<template>
	<view class="sh-content" style="padding: 50rpx 50rpx;">

		<view class="task global-font" style="font-size: 32rpx;">
			<span>扫描托盘条码:</span>
			<u-input v-model="dataForm.containerCode" border
				style="background-color: #ffffff;margin-bottom: 20px;margin-top: 20rpx;" placeholder="请扫描或输入要搬运的托盘条码"
				:focus="focusFlag" @input="changeCode()"></u-input>

			<span>搬运起始点位:</span>
		<!-- 	<u-input v-model="begin" style="background-color: #ffffff;margin-bottom: 20px;margin-top: 20rpx;" border
				type="select" font-size='32' placeholder="请选择起始点位" prop="wareHouse" class="u-input"
				placeholder-style="color:#000000" @click="show = true" />
			<u-select v-model="show" :list="pointList1" @confirm="confirm" mode="single-column"></u-select> -->
			<select-lay @transfer="reomveValue" :pointNoChild="begin" :options="pointList"  style="width: 100%; margin-top: 1vh;"
			smoldName="ptName" slabel="label"  smodel="ptName" name="name3"  svalue="value" @selectitem="queryList" 
			:value="begin" placeholder="选择要释放位置编码"  > </select-lay>
		</view>
		<view class="img1" style="text-align: center;font-size: 32rpx;">
			<!-- <img src="@/static/icon/down.png" alt=""  style="width: 300rpx;"> -->

		</view>
		<view class="task global-font" style="font-size: 32rpx;">
			<span>搬运目标点位:</span>
	<!-- 		<u-input v-model="end" style="background-color: #ffffff;margin-bottom: 20px;margin-top: 20rpx;" border
				type="select" font-size='32' placeholder="请选择目标点位" prop="wareHouse" class="u-input"
				placeholder-style="color:#000000" @click="showTwo = true" />
			<u-select v-model="showTwo" :list="pointList1" @confirm="confirmTwo" mode="single-column"></u-select> -->
		<select-lay @transfer="reomveValue1" :pointNoChild="end" :options="pointList1"  style="margin-top: 1vh;"
		smoldName="ptName" slabel="label"  smodel="ptName" name="name3"  svalue="value" @selectitem="queryList1" 
		:value="end" placeholder="选择要释放位置编码"> </select-lay>
		
		</view>
		<view class="footer" style="position: absolute;bottom:8%;left: 50%;transform: translateX(-50%);">
			<u-button type="success" @click="checkOutPick()" style="width: 400rpx;background-color: #41ABE2;">开始搬运
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				showTwo: false,
				focusFlag: true,
				flag: true,
				begin: '',
				endValue: '',
				end: '',
				list: [],
				showList: [],
				dataForm: {
					containerCode: '',
					endPoint: '',
				},
				timer: 0,
				pointList: [],
				pointList1: [],
				pointList2:[],
				pointList3:[],
			}
		},
		onLoad() {
		this.$u.api.AvgCarry.getPointList({
				pageNum: 1,
				pageSize: 999,
				// pointGroup:1
			}).then(res => {
				this.pointList = []
				this.pointList1 = []
				if (res.code == 200) {
					let dataArry = res.rows;
					for (var i = 0; i < dataArry.length; i++) {
						var obj = {
							value: dataArry[i].pointNo,
							label: dataArry[i].pointName,
						};
						this.pointList.push(obj);
						this.pointList1.push(obj);
					}
				}
			
			})
			
			// this.$u.api.AvgCarry.getPointList({
			// 	pageNum: 1,
			// 	pageSize: 999
			// }).then(res => {
			// 	this.pointList2 = []
			// 	this.pointList3 = []
			// 	if (res.code == 200) {
			// 		let dataArry = res.rows;
			// 		for (var i = 0; i < dataArry.length; i++) {
			// 			var obj = {
			// 				value: dataArry[i].pointNo,
			// 				label: dataArry[i].pointName,
			// 			};
			// 			this.pointList2.push(obj);
			// 			this.pointList3.push(obj);
			// 		}
			// 	}

			// })		

		},
		methods: {
			changeCode() {
				clearTimeout(this.timer)
				//防抖节流
				this.flag = true
				if (this.flag === false) return;
				this.flag = false;
				this.timer = setTimeout(() => {		
					this.flag = true
					this.focusFlag = false
					this.$u.api.AvgCarry.queryBillingDByContainerCode({
						containerCode: this.dataForm.containerCode
					}).then(res => {
						this.endValue = res.data[0] ? res.data[0].targetPoint : ''
						this.beginValue = res.data[1] ? res.data[1].startPoint : ''
						this.pointList.forEach(item => {
							if (res.data[0]) {
								if (res.data[0].targetPoint == item.value) {
									this.end = item.label
									}
							}
							if (res.data[1]) {
								if (res.data[1].startPoint == item.value) {
									this.begin = item.label

								}
							}

						})
					// this.end = res.data
					// this.pointList1 = this.pointList.filter(item => item.value != this.beginValue && item.value !=
					// 	this.endValue)
					// this.dataForm.endPoint = res.data
					// this.endValue=res.data
					this.pointList = this.pointList.filter(item => item.value != this.beginValue && item.value !=
						this.endValue)
				})
				
				this.$forceUpdate()
			},800)
			},
			//呼叫搬运
			checkOutPick() {

				if (this.beginValue == null ||
					this.beginValue === '' ||
					this.beginValue === 0 ||
					this.beginValue === undefined ||
					this.beginValue === 'undefined') {
					this.$u.toast("请选择起始位置");
					return;
				}
				if (this.endValue == null ||
					this.endValue === '' ||
					this.endValue === 0 ||
					this.endValue === undefined ||
					this.endValue === 'undefined') {
					this.$u.toast("请选择目标位置");
					return;
				}
				this.$u.api.AvgCarry.agvCarry({
					startPoint: this.beginValue,
					toLocation: this.endValue,
					containerCode: this.dataForm.containerCode
				}).then(res => {
					this.$u.toast(res.msg)
					if (res.code == 200) {
						this.begin = ''
						this.end = ''
						this.beginValue = ''
						this.endValue = ''
						this.dataForm.startPoint = ''
						this.dataForm.containerCode = ''
						this.dataForm.endPoint = ''
						this.focusFlag = true
						this.judge()
						this.$u.api.AvgCarry.getPointList({
							pageNum: 1,
							pageSize: 100
						}).then(res => {
							this.pointList = []
							this.pointList1 = []
							if (res.code == 200) {
								let dataArry = res.rows;
								for (var i = 0; i < dataArry.length; i++) {
									var obj = {
										value: dataArry[i].pointNo,
										label: dataArry[i].pointName,
									};
									this.pointList.push(obj);
									this.pointList1.push(obj);
								}
							}
						})
					}
				}).catch(err => {})
			},
			// 选择点位
			queryList(index,item){
			this.begin=item.label
			this.beginValue=item.value
			this.judge()
			},		
			queryList1(index,item){
			this.end = item.label
			this.endValue = item.value
			this.judge()
			},
			//获取点位
			async getList() {
				this.list = [];
				await this.$u.api.getCarry().then(res => {
					if (res.code === 200) {
						let dataArry = res.data;
						for (var i = 0; i < dataArry.length; i++) {
							var obj = {
								value: dataArry[i].dictValue,
								label: dataArry[i].dictLabel,
							};
							this.list.push(obj);
						}
					} else {
						this.$u.toast(res.msg);
					}
				});
				this.showList = [...this.list]
			},
			
			reomveValue(){
				this.beginValue = ''
				this.begin = ''
			},	
			reomveValue1(){
				this.end = ''
				this.endValue = ''
			},
			//过滤数组
			judge(e) {
				this.pointList1 = this.pointList.filter(item => item.value != this.beginValue && item.value != this
					.endValue)		
				// this.pointList = this.pointList1.filter(item => item.value != this.beginValue && item.value != this
				// 	.endValue)
			},
			confirm(e) {
				this.begin = e[0].label
				this.beginValue = e[0].value
				this.judge(e)
			},
			confirmTwo(e) {
				// this.dataForm.endPoint= e[0].label
				this.end = e[0].label
				this.endValue = e[0].value
				this.judge(e)
			},
		}
	}
</script>

<style lang="scss">
	@import "index.scss";

	.img1 {
		height: 200px;
		background-image: url(@/static/down.png);
		background-size: 50% 100%;
		background-repeat: no-repeat;
		background-position: center;
	}
</style>
