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

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

    	<span>搬运起始点位:</span>
    	<u-input v-model="begin" border type="select" 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>	
	

    </view>
    <view class="img1" style="text-align: center;">
      <!-- <img src="@/static/icon/down.png" alt=""  style="width: 300rpx;"> -->
	  
    </view>
    <view class="task" >
    	<span>搬运目标点位:</span>
    	<u-input v-model="end" border type="select" 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>
    </view>
    <view class="footer" style="position: absolute;bottom:8%;left: 50%;transform: translateX(-50%);">
    	<u-button type="success" @click="checkOutPick()" style="width: 400rpx;">开始搬运</u-button>
    </view>
  </view>
</template>

<script>
  export default{
    data(){
      return {
          show: false,
          showTwo:false,
		  focusFlag:true,
          begin:'',
		  endValue:'',
          end:'',
          list:[],
          showList:[],
		  dataForm:{
			containerCode:'',
			endPoint:'',
		  },
		  pointList:[],
		  pointList1:[],
      }
    },
    onLoad(){
   // this.getDic()

	 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);
			 }
		 }
	 })

      // this.getList()


    },
    methods:{

		changeCode() {
			this.focusFlag=false
			// this.query = {
			// 	pageNum: 1,
			// 	pageSize: 10
			// }
			// this.getDataList()
			  this.$u.api.AvgCarry.queryBillingDByContainerCode({containerCode:this.dataForm.containerCode}).then(res=>{
				  // console.log(res);
					this.endValue = res.data
					this.pointList.forEach(item=>{
						if(res.data == item.value){
							this.end = 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)
			  }
			  )
		},
      //呼叫搬运
      checkOutPick(){
        // this.$u.api.AvgCarry.moveByAGV({fromLocation:this.begin,toLocation:this.end,containerCode:this.dataForm.containerCode}).then(res=>{
        //   this.$u.toast(res.msg)
        //   if(res.code==200){
        //     this.begin=''
        //     this.end=''
        //     this.judge()
        //   }
        // }).catch(err=>console.log(err)) 
		// if(this.dataForm.containerCode == null
		// || this.dataForm.containerCode === '' 
		// || this.dataForm.containerCode === 0
		// || this.dataForm.containerCode === undefined
		// || this.dataForm.containerCode ==='undefined'){
		// 	this.$u.toast("请扫描托盘编号");
		// 	return; 
		// }  
		
		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; 
		}
        // }).catch(err=>console.log(err))
		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=>{})
      },
    //获取点位
    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]
       // console.log(this.list)
      },
      //过滤数组
      judge(e){
		  // console.log(e);
		  // console.log(this.pointList);
        this.pointList1 = this.pointList.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: 220px;
	  background-image: url(@/static/down.png);
	  background-size: 50% 100%;
	  background-repeat: no-repeat;
	  background-position:center;
  }
</style>
