<template>
  <view class="sh-content">
    <view class="sh-search">
      <u-form labelPosition="left" :model="dataForm" class="sh-form global-font">
        <u-form-item  prop="barCode">
  <!--        <u-input v-model="dataForm.containerCode" border input-align="left" height="70" style="background-color: #ffffff;height: 38px;line-height: 38px;"   placeholder="请扫描台车编号"
            @confirm="inputQuery()" :focus="firstFocus">
			</u-input> -->
       <select-lay @transfer="reomveValue" :pointNoChild="dataForm.pointNo" :options="pointList" @itemclick="cpnclick" style="width: 92%;margin-left: 2vh; margin-top: 4vh;"
       smoldName="ptName" slabel="label"  smodel="ptName" name="name3"  svalue="value" @selectitem="queryList" 
       :value="dataForm.ptName" placeholder="扫描或选择要释放位置编码"> </select-lay>
		</u-form-item>
      </u-form>
 
    </view>

	<view class='recommend'>
	  <text class='recommend-title global-font'>点位物料信息</text>
	</view>
    <!-- {{dataList}} -->
	<view class="all-card">
		
		<view class="sh-card" v-for="(item, index) in dataList" :keys="item.id" :index="item.id" v-if="dataList.length > 0"
		       style="border-radius: 20rpx;">
			<view  class="sh-card-title"   style="border-radius: 20rpx;">
			
		      <view class="card-content">
			
		        <view class="card-content-item" width="60%" style="margin-top: 1vh;">
		          <text class="item-title" >托盘编号:</text>
		          <text class="item-value">{{item.ttPart}}</text>
		        </view>
		      </view>
		     <view class="card-content">
		       <view class="card-content-item">
		         <text class="item-title">物料信息:</text>
		         <text class="item-value">{{item.ptName}}--{{item.ptDesc}}</text>
		       </view>
		
		     </view>

		    </view>

		     </view>
	</view>

	<view class="bottom">
		<button @click="openModal()" class="global-font" >释放点位</button>
	</view>
	<u-modal v-model="show" title='点位释放' @confirm="pickUp()" :content='`确定要释放此点位吗`'  show-confirm-button  show-cancel-button></u-modal>

	<view class="global-font" style=" position: absolute;
             top: 92%;
             left: 40%;
             transform: translate(-30%,-50%); 
			 color: rgb(213, 21, 32);font-size: 30rpx;">
		释放点位后，需确认已将点位上的托盘取下
		且无任何障碍物！
	</view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
		  show:false,
        showDiv:false,
        queryFlag: '',
        dataForm: {
          pointNo: null,
          keywords: "",
          pageNum: 1,
          pageSize: 10
        },
		datalist1:[],
		pointList:[],
		pickUpObj:{
			pointNo:'',
			taskCode:'',
			taskId:'',
			containerId:'',
			dtlAddBos:[]
		},
        dataList: [
			// {
			// 	ttPart:'你好',
			// 	ptName:'N96'
			// }
		],
        query: {
          current: 1,
          size: 20
        },
		isActive:0,
        loadStatus: 'loadmore',
        dicOptions: [],
		timer:0,
		//模拟数据列表
		datalist3: [],
		//模拟初始数据
		tval3: "myvalue1",
		firstFocus:false
      }
    },
    onLoad() {
      this.loadList();
	 //  this.$u.api.waitOutPlan(this.dataForm).then(res=>console.log(
	 // this.dataList=res.rows
	 //  ))
		  // uni.setNavigationBarTitle({
		  // 		title:this.$i18nMsg().nav.outStore
		  // 	})
	// this.$u.api.mouldStorage.queryMouldStorage({pageNum: 1,pageSize:9999,type:'out'}).then(res=>{
	// 	console.log(res);
	// })
	this.$u.api.AvgCarry.getPointList({pageNum: 1,
					pageSize: 100}).then(res=>{
				this.pointList=[]
			 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);
				 }
			 }
			
	})
	
	
    },
    //上拉刷新(当数据距离底部100时触发，距离在pages.json配置)
    onReachBottom() {
      this.loadStatus = "loading";
      setTimeout(() => {
        this.dataForm.pageNum += 1;
        this.loadList();
      }, 100);
    },
	//蹦出弹窗提示

	 onPullDownRefresh () {
	    this.list = []
	    //调用获取数据方法
	    this.getData()
	    setTimeout(() => {
			// onLoad()
			// this.$u.api.waitOutPlan(this.dataForm).then(res=>this.dataList=res.rows)}
			// console.log(111);
	        //结束下拉刷新
	      uni.stopPullDownRefresh ();
	    }, 800);
	},
		onReady() {
			
			},
    methods: {
		pickUp(){
				this.$u.api.release.releasePoint({pointNo:this.dataForm.pointNo}).then(res=>{
				this.$u.toast(res.msg);
				this.dataForm.pointNo = ''
			})
		},
		 getData(){
			 this.$u.api.waitOutPlan(this.dataForm).then(res=>{
				 	this.dataList=res.rows
			 })
		 },
		 cpnclick(item){
		 
		 },
		 openModal(){
		  if(this.dataForm.pointNo === null
		  || this.dataForm.pointNo === '' 
		  || this.dataForm.pointNo === 0
		  || this.dataForm.pointNo === undefined
		  || this.dataForm.pointNo === 'undefined'){
		  	 this.$u.toast("点位释放为空");
		  	 return; 
		  } 
		 	this.show = true;
		 },
		 // 删除值
		 reomveValue(){
			this.dataForm.pointNo = ''
		 },
		//点击变色
		btn(index,item){
			this.pickUpObj.dtlAddBos=[]
			this.isActive = index
			this.pickUpObj.pointNo=item.endLocation
			this.pickUpObj.taskCode=item.taskCode
			this.pickUpObj.taskId=item.taskId
			this.pickUpObj.taskType=item.taskType
			this.pickUpObj.containerId=item.containerId
			this.pickUpObj.dtlAddBos.push({qrCode:item.qrCode} )
			
		},
		confirmChange(){
		},
		editBtn(){
			this.show=true
		},
		queryList(index,item){
		this.dataForm.pointNo=item.value
		},
			
		enterUp(item){
		this.$u.api.replaceCar.upateBusinItemInDataForQty(item).then(res=>{
		})
		},
      /**搜索框查询*/
      inputQuery() {
        if (this.dataForm.pointNo == '' || this.dataForm.pointNo == null || this.dataForm.pointNo ==
          undefined) {
          return
        }
          this.loadList()
      },
	  onNavigationBarButtonTap(e){
		  // console.log(e);
		  this.$u.route({
		  	url: 'pages/BusinPickup/index2',
		  	type: 'navigateTo',	
		  })
	  },
		  
	  close(){
	  },
	  noEnter(){
		  this.show=false
	  },
      loadList() {
		  //防抖
		  clearInterval(this.timer)
		  // console.log(this.dataForm);
		  this.timer =setTimeout(()=>{
		  	//节流
		  	let flag = true
		  	if(flag===false) return
			if (this.dataForm.pointNo == '' || this.dataForm.pointNo == null || this.dataForm.pointNo ==
			  undefined) {
			  return
			}
		  	flag=false
		  	setTimeout(()=>{
		  		flag = true
				this.firstFocus=false
				
				this.$u.api.replaceCar.getBusinItemInData(this.dataForm).then(res=>{
					if(!res.data || res.data.length == 0){
					// console.log(res);
					this.$u.toast("当前托盘模具不存在");		
					}else if(res.code == '200'){
							// console.log(res);
							res.data.forEach((item)=>{
								item.containerId=item.id
							})
							this.dataList=res.data
							setTimeout(()=>{
								this.dataForm.pointNo=this.dataForm.pointNo
								this.dataForm.containerTypeLabel=this.dataForm.pointNo
								this.dataForm.pointNo=''
							},0)
					
							this.$nextTick(()=>{
								this.firstFocus = true
							})
						}
				})	
			}
			,500)
			
		  },400)
      },
	// 下一个界面
	enterNext(item,index){
		this.$u.route({
			url: 'pages/BusinPickup/index1',
			type: 'navigateTo',
			params:{
				pointNo:item.pointNo
			} 			
		})
	},
	
	
      // 任务查看
      searchClick() {
        this.dataList = [];
        this.dataForm.pageNum = 1;
        this.loadList();
      },
    },
	filters: {
	  formatType(value) {
	    switch (Number(value)) {
	      case 0:
	        return "type1";
	      case 1:
	        return "type2";
	      case 2:
	        return "type3";
	      default:
	        return "";
	    }
	  }}
  }
</script>

<style lang="scss">
  @import "index.scss";
  .footer {
    display: flex;
    padding: 20rpx 0;
  }
</style>
