<template>
  <view class="order-list content">
    <view class="swiper-box">
      <template v-if="content.materialShelves.length">
        <view class="order-card shelf-card" v-for="item in content.materialShelves" :key="item.id">
          <view class="order-info">
            <p class="info-line">
                <text class="label">货架:</text>
              <text class="info">{{item.shelf}}</text>
              </p>
              <p class="info-line">
                <text class="label">货层:</text>
              <text class="info">{{item.floor}}</text>
              </p>
              <p class="info-line">
                <text class="label">货位:</text>
              <text class="info">{{item.seat}}</text>
              </p>
              <p class="info-line">
                <text class="label">附加码:</text>
              <text class="info">{{item.sign}}</text>
              </p>
              <p class="info-line">
                <text class="label">当前库存:</text>
                <text class="info">{{item.shelfNum}}</text>
              </p>
              <p class="info-line">
                <text class="label">盘点数量:</text>
                <u-input  class="info" type="number" 
                    suffixIcon="edit-pen"
                    border="none" 
                    :clearable="false" 
                    v-model="item.inventoryNum">
                    </u-input>
              </p>
              <p class="info-line">
                <text class="label">盘盈盘亏:</text>
                <text class="info">{{item.inventoryNum?(item.inventoryNum - item.shelfNum):''}}</text>
              </p>
          </view>
        </view>
      </template>
      <template v-else>
        <u-empty mode="list" icon="https://cdn.uviewui.com/uview/empty/list.png">
        </u-empty>
      </template>
    </view>
    <view class="btn-wrap" >
      <u-button type="primary" color='#4680F9' @click="submit">{{$t('base.common.submit')}}</u-button>
    </view>
  </view>
</template>

<script>
import {saveInventory} from '../../api/stock'
export default {
  components:{
  },
  data() {
    return {
      content:{},
    };
  },
  onLoad(options) {
    this.content = JSON.parse(options.content)
    this.content.materialShelves.forEach(item=>{
      item.inventoryNum = item.shelfNum
    })
  },
  methods: {
    submit(){
      let num = 0
      this.content.materialShelves.forEach(item=>{
        item.inventoryNum = Number(item.inventoryNum)
        num+=item.inventoryNum
      })
      this.content.totalNum = num
      saveInventory(this.content).then(res=>{
        if(res.data.code == 0){
          uni.showModal({
            title: '提示',
            content: '保存成功',
            showCancel: false,
            success: ({ confirm, cancel }) => {
              if(confirm){
                uni.navigateBack({ delta: 1 })
              }
            }
          })
        }
      })
    }
  },
};
</script>

<style>
/* #ifndef APP-NVUE */
view {
  display: flex;
  box-sizing: border-box;
  flex-direction: column;
}

page {
	box-sizing: border-box;
	/* padding: 40rpx 40rpx 80rpx; */
	height: 100%;
}
/* #endif*/
</style>

<style lang="scss" scoped>
@import '../../common/css/public.scss';
.order-list {
  padding-bottom: 160rpx;
  background-color: #f8f8f8;
  .qrcode-wrap{
    padding: 24rpx;
    text-align: center;
    .info-line{
      text-align: center;
      font-size: 32rpx;
      margin-top: 24rpx;
    }
  }
}
.swiper-box{
  padding:24rpx;
}
.popupShow {
	overflow: hidden;
	position: fixed;
}
.picker-card{
    padding: 32rpx 32rpx 144rpx;
    position: relative;
    height: 100%;
    overflow-y: scroll;
    display: block;
    .card-oper{
      position: absolute;
      width: 100%;
      bottom: 0;
      left:0;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      padding: 24rpx;
      .btn{
        width: 100%;
      }
    }
  }
  .shelf-card{
  margin: 0 0 24rpx; 
  display: block;
  .order-info{
    flex-direction: row;
    flex-wrap: wrap;
    .info-line{
      width: 50%;
      .label{
        width: 120rpx;
      }
    }
  }
}
.btn-wrap{
    position: fixed;
    bottom: 0;
    padding: 32rpx;
    width: 100%;
    z-index: 200;
    background-color: #fff;
  }
</style>