<!-- 功能库房拣货 -->
<template>
	
	<div class="functionWarehousePicking">
		<scan-code v-model="scanVisible" :warehouseId="key == '1' ? taskforWarehouseId || warehouseId: taskConfirmWarehouseId || warehouseId" ref="scan" :stage="stage" :scanTable="scanTableList"></scan-code>
		<!-- 	{"type":"0-整件 1-零货 2-功能库房","warehouseId":"仓id"} -->
		<get-info :bldgInfo="bldgInfo" :type="2" text="整单"></get-info>
		<div class="mainTab">
			<span class="btnGroup">
				<!-- <a-button type="primary" icon="printer">打印</a-button> -->
				<!-- 扫描监管码 [integer] 扫描监管码节点：0=拣货 1=外复核 -->
				<p-button type="primary" icon="scan" :disabled="isScan" v-show="key==3" @click="scan">扫描监管码</p-button>
			</span>
			
			 <p-tabs default-active-key="3" @change="callback">
			      <p-tab-pane key="1" tab="待索取">
					<!-- tab0  -->
					<tab0 ref="tab0" @emitWarehouseId="emitWarehouseId" :bldgInfo.sync="bldgInfo" @emitData="emitData"   />
			      </p-tab-pane>
					<!-- tab1  -->
			      <!-- <p-tab-pane key="2" tab="任务索取" force-render>
					<tab1   />
			      </p-tab-pane> -->
			      <p-tab-pane key="3" tab="任务确认">
			        <!-- tab2  -->
			        <tab2 ref="tab2" @emitWarehouseId="emitWarehouseId" :bldgInfo.sync="bldgInfo" @emitData="emitData"   />
			      </p-tab-pane>
			    </p-tabs>
		</div>
	</div>
</template>

<script>
	import scanCode from '../../components/scanCode'; 	//扫描监管码
	import   tab0   from './components/tab0.vue';
	// import   tab1   from './components/tab1.vue';
	import   tab2   from './components/tab2.vue';
	import  getInfo  from	'../components/getInfo.vue';
	import { scan_warehouse }  from  '../config/api.js';
	import  { mapGetters } from  'vuex';
	
export default {
	computed:{
		...mapGetters(['warehouse']),
	},
	components:{ tab0,  tab2, getInfo,scanCode },
	data(){
		return {
			key: 3,
			selectedRows1:[],
			selectedRows2:[],
			selectedRows3:[],
			taskConfirmWarehouseId: '',
			taskforWarehouseId: '',
			bldgInfo: {},
			warehouseId: '',
			scanVisible: false,	//p-modal弹窗：扫描监管码
			isScan:true,		//扫描监管码是否禁用。
			scanTableList:[],	// 扫描监管码数据
			stage: 1, //扫码阶段：0=入库质检 1=PC拣货 2=PC内复核 3=PC外复核 4=补录 5=PDA拣货 6=PDA内复核 7=PDA外复核
		}
	},	//data
	methods: {
		emitWarehouseId(data, index) {
			if(index == 1) {
				this.taskforWarehouseId = data
			} else if(index == 3) {
				this.taskConfirmWarehouseId = data
				console.log(this.taskConfirmWarehouseId)

			}
		},
		// tab点击
		callback (key) {
			this.$nextTick(() => {
				  if(key ==1) {
				  this.warehouseId = this.taskforWarehouseId
				  const bldgName = this.$refs.tab0.$refs.search.form.getFieldsValue().bldgName
				  const bldgCode = this.$refs.tab0.$refs.search.form.getFieldsValue().bldgCode
				  const bldgId = this.$refs.tab0.$refs.search.form.getFieldsValue().bldgId
				  this.bldgInfo = { bldgName, bldgCode, bldgId }
				} else {
					this.warehouseId = this.taskConfirmWarehouseId
					const bldgName = this.$refs.tab2.$refs.search.form.getFieldsValue().bldgName
					const bldgCode = this.$refs.tab2.$refs.search.form.getFieldsValue().bldgCode
					const bldgId = this.$refs.tab2.$refs.search.form.getFieldsValue().bldgId
					this.bldgInfo = { bldgName, bldgCode, bldgId }
				}
			  })
			//   console.log(key);
			//   if(key ==1) {
			// 	  this.warehouseId = this.taskforWarehouseId
			//   } else {
			// 	  this.warehouseId = this.taskConfirmWarehouseId
			//   }
			  this.key = key;
			},
	 // 扫描监管码
	 	scan(){
	 			  if(this.scanTableList.length){
	 				  // this.scanTableList = [...selectedRows];
	 				  this.scanVisible = true;
	 			  } else {
	 				  this.$message.warning('该单所有商品，无需扫描药品追溯码');
	 			  }
	 			  
	 	},
	 	// 扫描监管码 scanSupervisionCodeStage[integer] 扫描监管码节点：0=拣货 1=外复核
	 	scanCode() {
	 		// this.scanVisible = true ;
	 		scan_warehouse({id:this.warehouseId}).then(res=>{
	 			if(res.success){
	 				// this.isScan = res.data.scanSupervisionCodeStage==0?false:true ;
					// 扫描监管码节点：0=整件拣货、零货拣货 1=整件外复核、零货拣货 2=整件拣货、零货内复核 3=整件外复核、零货内复核
					if(res.data.scanSupervisionCodeStage==0 || res.data.scanSupervisionCodeStage==1){
						this.isScan = false;
					}
					
	 				// console.log("扫描监管码节点：0=拣货 1=外复核:",this.isScan,res.data.scanSupervisionCodeStage);
	 			}
	 		})
	 		// console.log("扫描监管码！");
	 	  /* let list = this.queryRefFromName('list').data.filter(tt => tt.isSupervise == 1)
	 	  if (list.length===0){
	 	    this.$message.error('该单所有商品，无需扫描药品追溯码')
	 	    return;
	 	  }
	 	  this.scanTableList = [...list];
	 	  this.scanVisible = true; */
	 	},
	 	// 接收数据 过滤isSupervise==1
	 	emitData(selectedRows,db,ok){
			 console.log(this.warehouseId,'warehouseIdwarehouseIdwarehouseIdwarehouseIdwarehouseIdwarehouseId')
	 		// 判断是否双击
	 		 if((selectedRows.length==1  &&  selectedRows[0].isSupervise  && db) || ok ){ 
	 			 this.scanVisible = true;
	 			} else {
	 			 this.scanVisible = false;
				}
	 		let temp = selectedRows.filter(item=> item.isSupervise==1 );
	 		if(this.key==1){
	 				console.log("emitData接收：tab1");
	 				this.selectedRows1 = [...selectedRows];
	 				temp = this.selectedRows1.filter(item=> item.isSupervise==1 );
	 			}
	 		if(this.key==2){
	 				console.log("emitData接收：tab2");
	 				this.selectedRows2 = [...selectedRows];
	 				temp = this.selectedRows2.filter(item=> item.isSupervise==1 );
	 			}
	 		if(this.key==3){
	 				console.log("emitData接收：tab3");
	 				this.selectedRows3 = [...selectedRows];
	 				temp = this.selectedRows3.filter(item=> item.isSupervise==1 );
	 			}
	 		
	 		 this.scanTableList = temp.map(item=>{
	 			 return {
							refBillId : item.pickTaskId,	//拣选任务主表id
							refBillLineId : item.pickTaskDId,	//拣选任务明细id
	 						
	 						itemId : item.itemId,	//商品id
	 						containerCode : item.containerCode,	//容器编号
	 						batchNum : item.batchNum,	//批次号
	 						itemName:item.itemName,		//商品名称
	 						itemNum:item.itemCode,		//商品编码
	 						specification:item.itemSpecs,	//商品规格
	 						pieceQty: item.qty, 	//数量
	 						uom: item.uom, 	//包装单位
	 						caseQty: item.uomQty, 	//件数
	 						oddPieceQty: item.oddPieceQty, 	//零散数
	 						minSu : item.minSu,			 //小包装
	 						middleSu : item.middleSu, 	//中包装
	 						maxSu: item.maxSu, 			// 大包装
	 						manufacturerName: item.manufacturer, 	// 生产厂家
							manufacturerLotNum : item.manufacturerLotNum, //批号2021.7.7
							srcCode : item.srcCode,	// 源单编号
	 			 }
	 
	 		 });
	 		 console.log("转换字段后数据：",this.scanTableList);
	 		 
	 	},
	 	 
	 
		},	//methods
	watch:{
		warehouseId:function(nVal,oVal){
			this.scanCode();
		}
	},
	created() {
		this.warehouseId = this.warehouse.warehouseId;
		this.scanCode();
	},
	
}
</script>

<style scoped lang="less">
	
	.functionWarehousePicking {  background: white; 
		.mainTab{ position: relative;
			.btnGroup { position: absolute;top: 15px; right: 20px;z-index: 999;
					.ant-btn:not(:last-child) { margin-right: 15px;}
			  }
		}
	::v-deep {
		.ant-tabs { padding-bottom: 30px;
			// tab 导航部分
			.ant-tabs-bar { padding-left: 20px; }
			// tab标题文字
			.ant-tabs-tab { font-size: 16px; font-weight: bold; padding-top: 20px; letter-spacing: 1px;  }
			// tab 内容区
		}
	}
	}
</style>
