<template>
	<view class="pop-container">
		<uni-popup ref="popup" type="dialog" >
			<uni-popup-dialog 
				:title="title" 
				message="" 
				:duration="2000" 
				:before-close="true" 
				@close="handleCancel" 
				@confirm="handleOk">
				<view class="dialog-content">
					<view style="height: 200px">
						 <zb-table
						 ref="zbTable"
						 :show-header="true"
						 :stripe="false"
						 :columns="column"
						 :data="data"
						 :highlight="true"
						 @currentChange="currentChange"
						 :border="true"
					    >
						</zb-table> 
					</view>
				</view>
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data"; // 字典
	import { listTaskMoves } from "@/api/wms/stockMove.js";
	
	export default {
		props: {
		  title: {
		    type: String,
		    required: true
		  },
		  formData:{
				type: Object,
				require: true
		  }
		},
		mounted() {
			
		},
		created: function(option) {
			
		},
		data() {
			return {
				currentFlag: '',
				keyWord: '', // 输入查询的值
				column: [],	 // 表头数据
				data: [], // 表体数据
				currentSelectData: {},  //当前选中数据行
			};
		},
		methods:{
			handleOk() {
				if(Object.keys(this.currentSelectData).length == 0){
					uni.showToast({
						title: "任务有多行匹配，请选择一行",
						icon: "none",
						duration: 3000
					})
					return true;
				}
				this.$emit("sendData", this.currentSelectData);
			  // 点击确定按钮的处理逻辑
				this.currentSelectData = {}
			  this.$refs.popup.close()
			},
			handleCancel() {
				uni.showToast({
					title: "任务有多行匹配，请选择一行",
					icon: "none",
					duration: 3000
				})
			},
			hidePopup() {
				this.$refs.popup.close();
			},
			// 单选当前行
			currentChange(row,index){
				this.currentSelectData = row;
		  },
			// searchBar
			input(value) {// uniSearchBar 的 value 改变时触发事件，返回参数为uniSearchBar的 value	e=value
				this.keyWord = value;
			},
			clear(res) {
				this.keyWord = "";
			},
			cancel(res) {
				this.keyWord = "";
			},
			// 查询按钮点击事件
			search(){
				let that = this;
				this.getRwbmList();
			},
			// 获取任务编码数据
			async getRwbmList(){
				let that = this;
				// 出库类型
				let inTypeObj = {}
				getDicts("out_type").then(response => { 
					  // that.inTypeOption = response.data;
					  let tmpArr = response.data;
					  if(tmpArr.length > 0){
						tmpArr.forEach((item,index)=>{
							inTypeObj[item.dictValue] = item.dictLabel;
						})
					  }
				});
				
				// 任务编码表头
				this.column = [
				  { name: 'subTaskCode', label:'任务编号', width:170,align:'center', emptyString:'--' },
				  { name: 'taskQty', label:'任务数', width:90,align:'center', emptyString:'--'},
				  { name: 'stockQty', label:'移位数', width:90,align:'center', emptyString:'--'},
				];
				
				let params = {
					billTypeCode: that.formData.taskBillTypeCode,
					id: that.formData.taskMoveId,
					params: {
						"materialCode":that.formData.materialCode
					},
				}
				let res = await listTaskMoves(params);
				let IsMultipleRow = false;
				if(res.code === 200){
					that.data = res.rows.map(item => {
						let a1 = item.wmsTaskMoves;
						let a2 = item;
							return Object.assign({}, a2, a1);
					});
					//大于1行才显示选项
					if(that.data.length > 1){
						uni.vibrateLong({});
						IsMultipleRow = true;
						this.$refs.popup.open();
					}
				}
				
				return IsMultipleRow;
			},
		},
	}
</script>

<style>
	@import "@/static/scss/commonpopup.css"
</style>
