<template>
  <view class="page-receipt-detail">
    <view class="header">
      <view class="left">
        <u-icon class="icon" name="arrow-left" @click="uni.navigateBack()" />
      </view>
      <view class="title">{{ $t("message.dn_Detailed") }}</view>
      <view class="right"></view>
    </view>
    <div class="content">
      <div class="content-item">
        <div class="item-left">MAT code</div>
        <div class="item-right">{{ this.material.materialCode }}</div>
      </div>
      <div class="content-item">
        <div class="item-left">MAT desc</div>
        <div class="item-right">{{ this.material.materialDesc }}</div>
      </div>
      <div class="content-item">
        <div class="item-left">Request Qty</div>
        <div class="item-right">{{ this.material.requestAmount }}</div>
      </div>
      <div class="content-item">
        <div class="item-left">Receive Qty</div>
        <div class="item-right">{{ this.material.requestAmount }}</div>
      </div>
      <div class="content-item">
        <div class="item-left">Loc</div>
        <div class="item-right">{{ this.material.location }}</div>
      </div>
    </div>
    <u-search
      :placeholder="this.$t('message.dn_PleaseScan')"
      v-model="documentNo"
      @search="model.queryOrderInInfo"
      :show-action="false"
    ></u-search>
    <div class="library">
      <input type="text" placeholder="请输入库位" v-model="wlCode" />
      <input type="text" placeholder="请输入数量" v-model="number" />
      <u-button type="primary" size="medium" class="confirm" @click="confirm"
        >确认</u-button
      >
    </div>
    <u-table class="library-table">
      <u-tr class="u-tr">
        <u-th class="u-th">库位</u-th>
        <u-th class="u-th">数量</u-th>
        <u-th class="u-th">操作</u-th>
      </u-tr>
      <u-tr class="u-tr" v-for="(item, index) in LocationList" :key="index">
        <u-td class="u-td">{{ item.value }}</u-td>
        <u-td class="u-td">{{ item.num }}</u-td>
        <u-td class="u-td">
          <div class="u-td" @click="deleteItem(index)">删除</div>
        </u-td>
      </u-tr>
    </u-table>
    <view class="bottom-bar">
      <div class="extra">
        <u-row class="bottom-info">
          <u-button type="primary" class="main" @click="Reservoir"
            >确认</u-button
          >
          <u-col :span="2" v-if="factoryCode == '6662'">
            { {$t('message.product_Location')}}
          </u-col>
          <u-col :span="4" v-if="factoryCode == '6662'">
            <jPicker
              style="margin: 6px 0px"
              sureColor="#ff0000"
              @bindpicker="bookTypeChange"
              showKey="value"
              valKey="value"
              :val="locationCode"
              :options="model.cboPlaceList"
            />
          </u-col>
        </u-row>
      </div>
    </view>
  </view>
</template>

<script lang="ts">
import { Component } from "vue-property-decorator";
import { BasePage } from "@/components/base/page";
import model from "./model";
import { headers } from "./config";
import jPicker from "@/components/J-Picker/jPicker.vue";
import { session } from "@/store/modules/session";
// @Component
@Component({
  components: {
    jPicker,
  },
})
export default class RawReceiptDetail extends BasePage {
  /**
   * 页面Module
   */
  model = model;
  factoryCode = session.factoryCode;
  locationCode = "";
  /**
   * 实际数量
   */
  number = "";
  wlCode = "";
  material = <any>{};
  LocationList = [];
  documentNo = "";
  /**
   * 表头
   */
  headers = headers;
  onReady() {
    this.model.queryLocation();
    let ant: any = sessionStorage.getItem("mater");
    this.material = JSON.parse(ant);
    sessionStorage.removeItem("mater");
  }
  confirm() {
    if (this.wlCode == "" || this.number == "") {
      uni.showToast({
        icon: "none",
        title: "请输入正确的库位和数量",
      });
      return;
    }
    let arr: object = {
      value: this.wlCode,
      num: this.number,
    };
    this.LocationList.push(arr as never);
  }
  deleteItem(index: any) {
    this.LocationList.splice(index, 1);
  }
  bookTypeChange(e: any) {
    this.locationCode = e.pickerName.value;
  }
  Reservoir() {
    let wlQTyList: Array<string> = [];
    let requestAmountNum = 0;
    this.LocationList.forEach((item: any) => {
      let objString = JSON.stringify(this.material);
      let TEM = JSON.parse(objString);
      TEM.wlCode = item.value;
      TEM.requestAmount = item.num;
      wlQTyList.push(TEM);
      let pras = parseInt(item.num);
      requestAmountNum += pras;
    });
    this.material.wlQTyList = wlQTyList;
    this.material.receiptAmount = requestAmountNum;
    console.log(this.material);
    sessionStorage.setItem("material", JSON.stringify(this.material));
    this.toPage(this.page.raw.ingoods.dnReturnGoods.detail);
  }
}
</script>

<style lang="scss" scoped>
.page-receipt-detail {
  background: #f2f2f2
    linear-gradient(0deg, #f2f2f2 0%, #4a78ea 51%, #1753ea 100%) no-repeat;
  background-size: 100% 600rpx;
  padding: 30rpx;
  min-height: 100%;
  padding-top: 118rpx;

  .header {
    position: fixed;
    top: 36rpx;
    left: 0;
    right: 0;
    display: flex;
    height: 88rpx;
    line-height: 88rpx;
    color: #fff;
    font-size: 34rpx;
    font-weight: 500;
    text-align: center;
    .title {
      flex: 3;
    }
    .left,
    .right {
      flex: 1;
    }
    .icon {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 88rpx;
      height: 88rpx;
    }
  }

  .content {
    width: 100%;
    height: 500rpx;

    .content-item {
      width: 100%;
      height: 100rpx;
      display: flex;
      text-align: center;
      line-height: 100rpx;
      background-color: white;
      .item-left {
        width: 30%;
      }
      .item-right {
        width: 70%;
      }
    }
  }

  .library {
    width: 100%;
    background-color: white;
    display: flex;

    input {
      display: block;
      width: 30%;
      padding: 10rpx;
    }
  }

  .library-table {
    margin-top: 30rpx;
  }

  .table-wrapper {
    background-color: #fff;
  }

  .form {
    background-color: #fff;
    padding: 40rpx;
    border-radius: 10rpx;
  }

  .bottom-bar {
    z-index: 21;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    .container {
      background: #ffffff;
      box-shadow: 0 1rpx 20rpx 0 rgba(128, 128, 128, 0.2);
      padding: 20rpx;
    }

    .extra {
      margin: 5px;
      border-radius: 5px;
      padding: 0 10px;

      .main {
        margin-right: 0;
      }
    }
  }
}
</style>
