<template>
	<view>
		<uni-collapse>
			<uni-forms :modelValue="jobInForm" ref="jobInForm" :rules="rules">
				<uni-collapse-item title="领料出库单" :open="true">
					<uni-forms-item label="工单" :labelWidth='90' name="pwoCode">
						<uni-easyinput type="text" disabled v-model="jobInForm.pwoCode"></uni-easyinput>
					</uni-forms-item>
					<uni-forms-item label="生产领料任务单" :labelWidth='90' name="pwoJobCode">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar" type="text" @confirm="scanJobCode"
							v-model="jobInForm.pwoJobCode"></uni-easyinput>
					</uni-forms-item>
					<uni-forms-item label="领料员" :labelWidth='90' name="equipmentCode">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar1" type="text" v-model="equipmentCode">
						</uni-easyinput>
					</uni-forms-item>
					<uni-forms-item label="出库员" :labelWidth='90' name="equipmentCode">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar1" type="text" v-model="equipmentCode">
						</uni-easyinput>
					</uni-forms-item>
				</uni-collapse-item>
				<uni-collapse-item title="领料出库单单明细" :open="true">
					<!-- <u-button type="primary" @click="addDetail">新增</u-button>
			  <u-button type="primary" @click="submit">确认</u-button> -->
					<uni-swipe-action>
						<uni-swipe-action-item :rightOptions="rightOptions" :key="index"
							v-for="(item, index) in jobInForm.mesPwoJobCvDetailList"
							@click="(data) => clickDetail(index,data)" @change="swipChange">
							<uni-badge :text="index+1" type="primary"></uni-badge>
							<uni-forms-item label="物料编码" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.materialCode'">
								<uni-easyinput type="text" disabled v-model="item.materialCode"></uni-easyinput>
							</uni-forms-item>
							<uni-forms-item label="物料名称" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.materialName'">
								<uni-easyinput type="text" disabled v-model="item.materialName"></uni-easyinput>
							</uni-forms-item>
							<uni-forms-item label="物料批号" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.materialBatch'">
								<uni-easyinput type="text" disabled v-model="item.materialBatch"></uni-easyinput>
							</uni-forms-item>
							<uni-forms-item label="物料箱号" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.whCodeDest'">
								<uni-easyinput type="text" disabled v-model="item.whCodeDest"></uni-easyinput>
							</uni-forms-item>
							<uni-forms-item label="库区编码" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.locCodeDest'">
								<uni-easyinput type="text" disabled v-model="item.locCodeDest"></uni-easyinput>
							</uni-forms-item>
							<uni-forms-item label="出库数量" :labelWidth='90'
								:name="'mesPwoJobCvDetailList.'+ index +'.locCodeDest'">
								<uni-easyinput type="text" disabled v-model="item.locCodeDest"></uni-easyinput>
							</uni-forms-item>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</uni-collapse-item>
			</uni-forms>

		</uni-collapse>
		<u-button type="primary" @click="jobInSubmit">提交</u-button>
	</view>
</template>

<script>
	import {
		handleConvert,
		getEquipment,
		addConversion,
		listEmpEqpHistory,
		listEmployee,
		listConversion
	} from "@/api/mes/jobIn.js";
	import {
		updatePwoJob,
		listEquipment,
		getPwoJob,
		listPwoJob
	} from "@/api/mes/jobReport.js"

	export default {
		data() {
			return {
				jobInForm: {
					mesPwoJobCvDetailList: [],
				},
				equipmentCode: null,
				flag: true,
				show: false,
				operateBy: null,
				operateByCode: null,
				rightOptions: [{
					text: '删除',
					style: {
						backgroundColor: '#ff2a17'
					}
				}, ],
				rules: {
					materialCode: [{
						required: true,
						errorMessage: '请输入物料编码!'
					}],
					materialName: [{
						required: false,
						errorMessage: '请输入物料名称!'
					}],
					number: [{
						required: true,
						errorMessage: '请输入转移数量!'
					}],
					equipmentCode: [{
						required: true,
						errorMessage: '请输入设备编码!'
					}]
				}
			}
		},
		mounted() {},
		methods: {


			scanJobCode(code) {

			},

			jobInSubmit() {
				this.jobInForm.operateBy = this.operateBy
				console.log(this.jobInForm);
				this.$refs["jobInForm"].validate().then(valid => {
					//作业转入

					this.jobInForm.operateBy = this.operateBy
					console.log(this.jobInForm);
					addConversion(this.jobInForm).then(response => {
						this.$modal.msgSuccess("转入成功!");
						setTimeout(() => {
							this.$tab.switchTab("/pages/work/index");
						}, 500);
					});
				});
			},
			//作业编码
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.jobInForm.pwoJobCode = res.result;
						_this.scanJobCode(_this.jobInForm.pwoJobCode);
					}
				});
			},
			//设备编码
			scanBar1() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.equipmentCode = res.result;
					}
				});
			},
			//操作人编码
			scanBar2() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.operateByCode = res.result;
						_this.scanBarOperateBy();
					}
				});
			},
		}
	}
</script>

<style>
</style>