<template >
	<view >

		<uni-forms style="background-color: white;">
		<uni-collapse>
			<uni-collapse-item title="领料拣货出库信息" :open="true">
				<uni-row>
					<uni-card>
						<uni-col :span="14">物料编码:{{singleInfo.materialCode}}</uni-col>
						<uni-col :span="10">数量:{{singleInfo.pickNumber}}</uni-col>
						<uni-col :span="14">单位:{{singleInfo.unit}}</uni-col>
						<uni-col :span="10">物料名称:{{singleInfo.materialName}}</uni-col>
						<uni-col :span="14">物料规格:{{singleInfo.specification}}</uni-col>
						<uni-col :span="10">库位:{{singleInfo.whCode}}</uni-col>
						<uni-col :span="14">批号:{{singleInfo.materialBatchNo}}</uni-col>
						<uni-col :span="10">拣货员:{{singleInfo.pickBy}}</uni-col>
						<uni-col :span="24">确认库位<uni-easyinput type="text" /></uni-col>
						<uni-col :span="24">确认出库数量<uni-easyinput type="text"
								v-model="singleInfo.pickNumber" /></uni-col>
		
	
					</uni-card>	
				</uni-row>		
			</uni-collapse-item>
	<selectLay v-show="isDone" style="position: fixed;top: 45%;left: 0;"  :options="empList" :placeholder="placeholder" @selectitem="equipmentbrandFuc"></selectLay>
			<uni-collapse-item :open="true" title="领料出库明细">
				<uni-col :span="12"><button type="primary" size="default" @click="empListBtn(1)">领料员</button></uni-col>
				<uni-col :span="12"><button type="primary" size="default" @click="empListBtn(2)">出库员</button></uni-col>
				<uni-card @click="open(index,item)" v-for="(item,index) in wmsLotNoList.wmsDrawOutDetailList">
					<uni-col :span="24">领料出库单明细编码:{{item.drawOutDetailCode}}</uni-col>
					<uni-col :span="24">物料编码:{{item.materialCode}}</uni-col>
					<uni-col :span="24">物料名称:{{item.materialName}}</uni-col>
					<uni-col :span="24">物料批号:{{item.materialBatchNo}}</uni-col>
					<uni-col :span="24">物料箱号:{{item.materialLotNo}}</uni-col>
					<uni-col :span="12">库位条码:{{item.whCode}}</uni-col>
					<uni-col :span="12">出库数量:{{item.number}}</uni-col>
				</uni-card>
			</uni-collapse-item>
		
		</uni-collapse>
		</uni-forms>

	</view>
</template>

<script>
	import {
		addInDetail,
		addLotInfo,
		uploadU9
	} from "@/api/wms/purchase.js";
	import {
		listEmployee
	} from "@/api/mes/jobIn.js";

	import {
		addSplitOutInfo
	} from "@/api/wms/invQuick"
	import {
		listOutSplitHistory
	} from "@/api/wms/stock.js"
	import {
		listOut,
	} from "@/api/wms/invQuick.js"
	import {
		updateInDetail
	} from "@/api/wms/pdcIn.js";
	import {
		getTask,
		getDetails,
		addOut,
	} from '@/api/wms/pdcMaterial.js'
	import selectLay from "@/components/select-lay/select-lay.vue"
	export default {
		onLoad: function(option) {
			console.log((JSON.parse(option.item)), 'iophd');
			if (JSON.parse(option.item)) {
				this.singleInfo = JSON.parse(option.item)
			}
	
			getDetails({drawTaskCode:this.singleInfo.drawTaskCode}).then(res=>{
				this.wmsLotNoList = res.wmsDrawOut
				console.log(res,"查看明细");
			})

		},
		components:{
			selectLay,
		},
		created() {
			listEmployee().then(res=>{//员工
							this.empList = res.rows.map(item=>{
						
					return {
						value:item.id,
						label:item.name
					}
				})
			})
		},
		data() {
			return {
				drawBy:"",
				warehouseOutBy:"",
				listData: {},
				empList:[],
				disBol: false,
			
				placeholder:"",
				//入库时间
				//是否已分批
				isSecondOpen: false,
				selectedRow: {},
				singleInfo: {},
				dataList:{},
				wmsLotNoList: [],
				isDone:false,
				eachNumber: null,
				splitNumber: null,
				drawOutCode: '',
				index: null,
				checkStorageLocationBarcode: true,
				// storageLocationBarcode: ''
				formData: {},
				rules: {
					storageLocationBarcode: [{

						required: true,
						errorMessage: '请输入库位条码!'

					}]
				},
			}
		},

		methods: {
			empListBtn(e){
				this.isDone = true;
				if(e === 1){
					this.placeholder = "请选择领料员"
				}else{
					this.placeholder = "请选择出库员"
				}
			},
			equipmentbrandFuc(e){
				console.log(e,"e");
				if(this.placeholder == "请选择领料员"){
					this.drawBy = e
				}else{
					this.drawBy = e
				}
				this.placeholder = "";
				this.isDone = false;
			},
			open(index, item) {
				console.log(item, index);
				listOut({
					pageNum: 1,
					pageSize: 50,
					orderByColumn: 'id',
					isAsc: "desc",
					'drawTaskCode': this.singleInfo.drawTaskCode
				}).then(async res => { //判断单子有没有在主表
					console.log(res, "主表单子");
					if (!res.total) { //有就直接进入拆分页面，没有新建
						getDetails({
							billType: "1",
							drawTaskCode:this.singleInfo.drawTaskCode,
							status: "0"
						}).then(res => {
							if (res) { //如果查的到数据，开始新建
								res.wmsDrawOut.billType = '1';
								res.wmsDrawOut.drawBy = this.drawBy;
								res.wmsDrawOut.drawTaskCode = this.singleInfo.drawTaskCode
								res.wmsDrawOut.drawType = "0";
								res.wmsDrawOut.status = "0";
								res.wmsDrawOut.warehouseOutBy = this.warehouseOutBy;
								addOut(res.wmsDrawOut).then(addOutList => {
									console.log(addOutList, "adda")
								})
							}
						})
					}
					this.$tab.navigateTo(
						'/pages/wms/pdcMaterial/splitItem?drawTaskCode=' +
						encodeURIComponent(JSON.stringify(this.singleInfo.drawTaskCode)) + '&item=' +
						encodeURIComponent(JSON
							.stringify(item)))



				})

			},

		},


	}
</script>

<style>
</style>