<template>
	<view class="bg-f9 productionPlan">
		<header-bar :title="submitType === 'add' ? '完工入库' : '完工入库'"></header-bar>
		<view class="commons-dtl-box">
			 <view class="">
			 	<span>工单编号</span> xxxxxxx
			 </view>
			 <view class="">
			 	<span>产品名称</span> 3ml 注射器
			 </view> 
			 <view class="">
			 	<span>待入库</span> 8000
			 </view> 
		</view>
		<view class="example" > 
			<!-- 基础用法，不包含校验规则 -->
			<uni-forms label-position="top" :modelValue="form" label-width="130" ref="form" :rules="rules">
				
				
				<uni-forms-item label="本次入库" required  name="num">
					<uni-easyinput v-model="form.num" placeholder="请输入本次入库" />
				</uni-forms-item>
			</uni-forms>
		</view> 
		
		<view style="height:200rpx">
			
		</view>
		<button class="submit" @click="submitForm">提交</button>
	</view>
</template>

<script>
	import headerBar from '../../../components/header-bar/index.vue'
	import Vue from 'vue'
	export default {
		components: {
			headerBar
		},
		data() {
			return {
				form: {
					name: '',
					type: null,
					classifyId: null,
					code: null,
					unit: null,
					introduce: null,
				},
				types: [{
					text: '半成品',
					value: '0'
				}, {
					text: '成品',
					value: '1'
				}],
				rules: {
					// 对name字段进行必填验证
					name: {
						rules: [{
							required: true,
							errorMessage: '请输入产品名称',
						}, ]
					},
					// 对email字段进行必填验证
					type: {
						rules: [{
							required: true,
							errorMessage: '请选择工作人员',
						}, ]
					},
					unit: {
						rules: [{
							required: true,
							errorMessage: '请输入完工数量',
						}, ]
					},
					num: {
						rules: [{
							required: true,
							errorMessage: '请输入本次入库',
						}, ]
					},
					
					
				},
				submitType: 'add',
				treeData: [],
			}
		},
		onLoad(e) {
			if (e.id) {
				this.form.id = e.id
				this.form.remarks = e.remarks
				this.form.type = e.type
				this.form.name = e.name
				this.submitType = 'edit'
			}
			this.getTree()
		},
		methods: {
			treeChange() {},
			getTree() {
				const v = this
				v.$post('/api/basics//classify/tree', {
					type: 1
				}).then(res => {
					if (res.code === 200) {
						v.treeData = res.data
					}

				})
			},
			submitForm() {
				const v = this
				this.$refs.form.validate().then(res => {
					uni.showLoading({
						title: '加载中'
					});
					v.$post('/api/syringe-management/product/' + this.submitType, v.form).then(res => {
						if (res.code === 200) {
							uni.showToast({
								title: this.submitType == 'add' ? '添加成功' : '修改成功',
								duration: 1000,
								icon: 'success'
							})
						}
						uni.hideLoading()
						let pages = getCurrentPages(); // 获取页面栈
						let prePage = pages[pages.length - 2]; //获取上一页
						prePage.$vm.needRefresh = true; // 需要刷新
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
		},
	}
</script>

<style lang="less">
	
</style>
