<template>
  <view>
	    
	  
    <view v-if="result.businInReceivingDForPdaVo" class="receiveBody">
		
      <view class="titleValue1">
        <span class="title">商品编号：</span>
        <span class="value" v-if="result.businInReceivingDForPdaVo">{{result.businInReceivingDForPdaVo.bgGoodNo}}</span>
      </view>
      <view class="titleValue1">
        <span class="title">商品名称：</span>
        <span class="value"
          v-if="result.businInReceivingDForPdaVo">{{result.businInReceivingDForPdaVo.bgGoodName}}</span>
      </view>
      <view class="titleValue1">
        <span class="title">规 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格：</span>
        <span class="value"
          v-if="result.businInReceivingDForPdaVo">{{result.businInReceivingDForPdaVo.bgSpecifications}}</span>
      </view>
	  <view class="titleValue1">
	    <span class="title">库 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</span>
	    <u-input v-model="kubevalue" type="select" placeholder="请选择库别" class="u-input" placeholder-style="color:#000000"
	      @click="kube = true" />
	    <u-select v-model="kube" :list="storageList" @confirm="confirmKube"></u-select>
	  </view>
	  <view class="titleValue1">
	    <span class="title">容 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;器：</span>
	    <u-input v-model="dataForm.containerCode" border placeholder="请输入或扫描容器条码"></u-input>
	  </view>
 <!--     <view class="titleValue">
        <span class="title">件装量：</span>
        <span v-if="result.businInReceivingDForPdaVo"> {{result.businInReceivingDForPdaVo.bpPackageQty}}</span>
      </view> -->
	 <view class='recommend'>
			<text class='recommend-title'>验货数量确认</text>
	 </view>
	 <view class="orderList" v-for="item in orderNoList">
	 	<view class="titleValue">
	 		<span class="title">单据编号：</span>
	 		<span class="value">{{item.orderNo|| '-'}}</span>
	 	</view>
	 	<view class="titleValue">
	 		<span class="title">验收数量：</span>
	 			<view style="width: 80px;">
	 				<u-input v-model="item.actualQty" border placeholder="请输入件装量" width="110" >
	 				</u-input>	
	 			</view>
	 		<span class="title" style="margin-left: 15px;">可验收数量:</span>
			<span class="title" style="margin-left: 10px;text-align: center;">{{item.ableQty}}</span>
	 </view>
	 
   <!--   <view class="titleValue">
        <span class="title">件 数：</span>
        <u-input v-model="dataForm.actualCaseQty" border placeholder="请输入件数" @input="changeCase"></u-input>
      </view> -->
  

    </view>
 <!--   <view class="footer">
      <u-button type="primary" @click='confirmFinish()'>确认验货</u-button>
    </view> -->
	<view class="enter-button">
		<button class="smell-button" @click="confirmFinish">确认验收</button>
	</view>
  </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        barCode: '',
        result: {},
        dataForm: {
          billingStatus: '',
          checkCaseQty: 0,
          checkPieceQty: 0,
          result: '',
          actualQty: '',
          // 件数
          actualCaseQty: 0,
          // 零散数
          actualPieceQty: 0,
          batchNo: '',
          productionDate: '',
          expiredDate: '',
          storageId: '',
          billingStatus: '',
          reason: '',
          containerCode: ''
        },
        resust: false,
        billingStatusValue: '',
        resustValue: '',
        kubevalue: '',
        receonclusion: false,
        kube: false,
        starttime: false,
        endtime: false,
        storageList: [],
        recelist: [],
        resustlist: [],
        sid: '',
        detailId: '',
        detailIds: [],
        recet: '',
		bos:[]
        
      };
    },
    onLoad: function(options) {
    
      this.did = options.did
      this.sid = options.sid
      // this.detailIds = JSON.parse(options.detailIds)
      this.orderNoList = JSON.parse(options?.orderNoList)
	  // this.allableQty = JSON.parseoptions.allableQty
	  this.loadStorageList() 
	  this.getList({
		  did:this.did,
		  sid:this.sid,
	  })
    },
    methods: {
      // 件数更改
      changeCase(e) {
        this.dataForm.actualQty = e 
      },


      loadStorageList() {
        this.storageList = [];
        this.$u.api.storageList().then(res => {
          let dataArry = res.data;
          for (var i = 0; i < dataArry.length; i++) {
            var obj = {
              value: dataArry[i].id,
              label: dataArry[i].storageName,
            };
            this.storageList.push(obj);
          }
        });
      },
	  
	  getList(params) {
	    this.$u.api.acceptance.getReceiving(params).then(res => {
	
	      if (res.code === 200) {
	        this.result = res.data
	        if (!this.result.businInReceivingDForPdaVo) {
	          this.$u.toast('当前商品待验收信息')
	        }
	        //库别
	        this.dataForm.storageId = res.data.businInReceivingDForPdaVo.storageId
	        this.dataForm.containerCode = res.data.businInReceivingDForPdaVo.containerCode
	        this.dataForm.batchNo = res.data.businInReceivingDForPdaVo.batchNo
	        const storageInfo = this.storageList.find((item) => Number(item.value) === Number(res.data
	          .businInReceivingDForPdaVo.storageId))
	        if (storageInfo) {
	          this.kubevalue = storageInfo.label
	        }
	      }
	    });
	  },
      // 提报异常
      confirmError() {
        this.$u.api.acceptance.confirmError({
          id: this.sid
        }).then((res) => {
          if (res.code === 200) {
            this.$u.toast('提报异常成功');
            this.dataForm = {
              billingStatus: '',
              checkCaseQty: '',
              checkPieceQty: '',
              result: '',
              actualQty: '',
              actualCaseQty: '',
              actualPieceQty: '',
              batchNo: '',
              productionDate: '',
              expiredDate: '',
              storageId: '',
              billingStatus: '',
              reason: '',
              containerCode: '',
              checkCaseQty: ''
            }
          } else {
            this.$u.toast(res.msg)
          }
        })
      },
      // 验收：
      confirmFinish() {
		if (!this.dataForm.containerCode) {
		   this.$u.toast('请扫码或输入容器号');
		   return
		 }
        if (!this.result.businInReceivingDForPdaVo) {
          this.$u.toast('请输入或扫描要验收的商品');
          return
        }
		for(var i=0;i<this.orderNoList.length;i++){
			if(this.orderNoList[i].actualQty === null
			|| this.orderNoList[i].actualQty === '' 
			|| this.orderNoList[i].actualQty === 0
			|| this.orderNoList[i].actualQty === undefined
			|| this.orderNoList[i].actualQty ==='undefined'){
				this.$u.toast('输入数量不能为0/空');
				return; 
			}
		}	
		for(var i=0;i<this.orderNoList.length;i++){
			if(this.orderNoList[i].actualQty > this.orderNoList[i].ableQty ){
				this.$u.toast('验收数量大于未收数量');
				return; 
			}
		}
		this.bos=[]
		this.orderNoList.forEach((item,index)=>{
			// containerCode:item.containerCode,
			// storageId: item.storageId,
			item.containerCode= this.dataForm.containerCode
			item.storageId= this.dataForm.storageId
			item.actualQty=Number(item.actualQty)
		})

        this.$u.api.acceptance.multipleConfirmBillingList({
			containerCode : this.dataForm.containerCode,
			storageId : this.dataForm.storageId,
			bos: this.orderNoList,
			}).then(res => {

          if (res.code === 200) {
            this.$u.toast('验收成功');
            this.result = {}
			this.orderNoList=[]
			setTimeout(()=>{
				this.$u.route({
					url: 'pages/checkAccept/index',
					type: 'navigateTo'
				})
			},1000)
          } else {
            this.$u.toast(res.msg);
          }
        });
      },
      queryFun() {

      },

      change(e) {
        this.endTimeValue = e.result
        this.endtime = false
        this.dataForm.expiredDate = e.result
      },
      // 确定库别
      confirmKube(e) {
        this.kube = false
        this.kubevalue = e[0].label
        this.dataForm.storageId = e[0].value
      },
    },
    onUnload() {
      var pages = getCurrentPages(); //当前页面栈
      if (pages.length > 1) {
        var beforePage = pages[pages.length - 1]; //获取上一个页面实例对象
        beforePage._data.refreshIfNeeded = true;
      }
    }

  }
</script>

<style lang="scss">
  .goodsNumber {
    padding: 20rpx 50rpx;
    display: flex;
    align-items: center;

    .goodsNumberCode {
      color: #333333;
      font-size: 36rpx;
      margin-right: 20rpx;
    }
  }
  .orderList{
  	margin: 22px 5px;
  	.titleValue{
  		
  	.value{
  		font-weight: 600;
  	}
  	}
  }
	.receiveBody{
		height: 550px;
		.titleValue1 {
			display: flex;
			align-items: center;
			
			font-size: 28rpx;
			padding: 5px 50rpx;
			// margin: 15px 10px 15px 5px;
			
			.title {
				// color: red;
				width: 180rpx;
				text-align: left;
			}
		
			.value {
				color: #666666;
			}
		}
		.recommend {
		  text-align: center;
		  height: 50rpx;
		  margin-top: 40rpx;
		  margin-bottom: 25px;
		}
		
		.recommend-title {
		  display: table;
		  width: 100%;
		  line-height: 50rpx;
		  white-space: nowrap;
		  border-spacing: 2rem 0;
		  font-size: 32rpx;
		  color: gray
		}
		.recommend-title::before, .recommend-title::after {
		  display: table-cell;
		  content: "";
		  width: 50%;
		  background: linear-gradient(#eee, #eee) repeat-x center;
		  
		  background-size: 0.1rem 0.1rem;
		}
		
	}
  .goodsInfo {
    width: 95%;
    margin: 0 auto;
    background-color: #f2f2f2;
    padding: 20rpx 30rpx;
    line-height: 40rpx;
    margin-bottom: 20rpx;

    .goodsInfoItem {
      display: flex;
      align-items: center;
      color: #333333;

      .goodsItemLabel {
        width: 120rpx;
        font-size: 24rpx;
      }

      .goodsItemValue {
        font-size: 28rpx;
        font-weight: 600;
      }
    }

    .itemsContend {
      display: flex;
      justify-content: space-between;

      .items {
        width: 50%;
        display: flex;
        font-size: 24rpx;
        color: #555555;

        .itemsLabel {
          width: 120rpx;
        }

        .itemsValue {}
      }
    }
  }

  .titleValue {
    display: flex;
    align-items: center;
    font-size: 28rpx;
    padding: 0 50rpx;
    margin-bottom: 20rpx;

    .title {
      color: #555555;
      width: 170rpx;
      text-align: left;
    }

    .value {
      color: #666666;
    }
  }
.enter-button{
		display: flex;
		flex: 2;
		height: 70px;
		width: 100%;
		z-index: 100px;
		background-color: #fff;
		position: fixed;
		bottom: 0px;
		.smell-button{
			display: block;
			color: #fff;
			margin: 19px auto;
			height: 35px;
			line-height: 35px;
			width: 45%;
			background-color: #19be6b;
			
		}
	}
  .footer {
    padding: 20rpx 40rpx;
    display: flex;
    justify-content: space-between;
  }
</style>
