<template>
  <view class="page-kan-dan-index">
    <view class="header" :style="{ backgroundColor: `rgba(23, 83, 234, ${scrollTop / 100})` }">
      <view class="left">
        <u-icon class="icon" name="arrow-left" @click="uni.navigateBack()" />
      </view>
      <view class="title">{{ $t('message.RowCollectionAndBorrowing') }}</view>
      <view class="right"></view>
    </view>
    <u-form class="form" label-width="130rpx">
      <!-- 单号 -->
      <view class="single">
        <view class="single-left">
          <view>{{ $t('message.CommissionedSingleNumber') }}</view>
          <u-search :placeholder="$t('message.Commission_tips1')" v-model.trim="order3" @search="query" :show-action="false"></u-search>
        </view>
        <view class="single-right">
          <u-button type="primary" @click="query">{{ $t('message.Query') }}</u-button>
        </view>
      </view>
      <!-- 物料号 -->
      <u-form-item :label="$t('message.po_MaterielNo')">
        <jPicker sureColor="#ff0000" style="width: 260rpx" @bindpicker="materialChoice" showKey="value" valKey="value" :val="wl.value" class="search" :options="MaterialList" />
      </u-form-item>
      <!-- 物料描述 -->
      <u-form-item :label="$t('message.po_MaterielDes')">
        <u-input :disabled="true" v-model="Some.productDescZh" placeholder="" style="overflow: hidden" />
      </u-form-item>
      <!-- 数量 -->
      <u-form-item :label="$t('message.Summary_Number')">
        <u-input v-model="Some.qty" placeholder="" type="number" />
      </u-form-item>
      <!-- 原库位 -->
      <u-form-item :label="$t('message.Warehouse_OriginalLocation')">
        <u-input :disabled="true" v-model="Some.originWl" placeholder="" />
      </u-form-item>
      <!-- 成本中心 -->
      <u-form-item :label="$t('message.product_costCenter')">
        <u-input :disabled="true" v-model="Some.costCenter" placeholder="" />
      </u-form-item>
      <!-- 文件号 -->
      <u-form-item :label="$t('message.DocumentNumber')">
        <u-input v-model="Some.fileNo" placeholder="" />
      </u-form-item>
      <u-row class="button-bar">
        <u-col :span="6">
          <u-button type="error" @click="uni.navigateBack()">{{ $t('message.po_Return') }}</u-button>
        </u-col>
        <u-col :span="6">
          <u-button type="primary" @click="submit">{{ $t('message.InventoryFinish') }} </u-button></u-col
        >
      </u-row>
    </u-form>
  </view>
</template>

<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import model from './model';
import jPicker from '@/components/J-Picker/jPicker.vue';
import { session } from '@/store/modules/session';
@Component({
  components: {
    jPicker,
  },
})
export default class KanDanHandOver extends BasePage {
  //单号
  order3 = '';
  model = model;
  wl: any = {};
  Some: any = {};
  MaterialList: any = [];
  //查询单号
  async query() {
    if (this.order3 === '') {
      this.customToast(this.$t('message.Commission_tips1') as string);
      return;
    } else {
      await this.model.takeLYOrder({
        order3: this.order3,
      });
      if (this.model.code == '1') {
        uni.showToast({ icon: 'success', title: this.$t('message.successful') as string });
        this.model.orderInInfoList.forEach((item: any) => {
          item.fileNo = '';
          let arr: any = {
            label: item.productCode,
            value: item.productCode,
          };
          this.MaterialList.push(arr);
        });
        this.Some = this.model.orderInInfoList[0];
        this.wl = this.MaterialList[0];
      }
    }
  }
  //选择物料回调函数
  materialChoice(e: any) {
    this.wl = e.pickerName;
    this.model.orderInInfoList.forEach((item: any) => {
      if (item.productCode == e.pickerName.value) {
        this.Some = item;
      }
    });
  }
  //提交
  async submit() {
    if (this.order3 === '') {
      this.customToast(this.$t('message.Commission_tips1') as string);
      return;
    }
    if (!this.Some) {
      this.customToast(this.$t('message.Warehouse_Tip5') as string);
      return;
    }
    if (this.Some.fileNo == '' || this.Some.fileNo == null || this.Some.fileNo == undefined) {
      this.customToast(this.$t('message.fileNumber') as string);
      return;
    }
    let orderlist = [];
    this.Some.type = '1';
    this.Some.keepBy = session.loginName;
    this.Some.orderType = '2';
    orderlist.push(this.Some);
    await model.onTakeoutConfirm(orderlist);
    if (this.model.code == '1') {
      uni.showToast({ icon: 'success', title: this.$t('message.success') as string });
      this.Some = {};
      this.Some.fileNo = ' ';
      this.wl = {};
      this.order3 = '';
      this.MaterialList = [];
    }
  }
}
</script>

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

  .header {
    position: fixed;
    top: 36rpx;
    left: 0;
    right: 0;
    z-index: 99;
    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;
    }
  }

  .form {
    background-color: #fff;
    padding: 40rpx;
    border-radius: 10rpx;
    box-shadow: 0 0 20rpx 0 rgba(128, 128, 128, 0.2);

    // .u-form-item {
    //   line-height: 35rpx;
    //   background-color: #f7f6fb;
    //   padding: 10rpx 30rpx;
    //   border-radius: 8rpx;
    //   &:after {
    //     border-bottom-width: 0;
    //   }
    // }
    .u-form-item {
      padding: 30rpx 0;
      line-height: 35rpx;
    }
    .single {
      width: 100%;
      height: 100rpx;
      display: flex;
      .single-left {
        width: 80%;
        height: 100%;
        display: flex;
        view {
          width: 110rpx;
          height: 100%;
          line-height: 100rpx;
        }
      }
      .single-right {
        button {
          margin-top: 15rpx;
          width: 150rpx;
          height: 70rpx;
        }
      }
    }
    .title {
      margin-bottom: 40rpx;
      color: #1a1a1a;
      font-size: 30rpx;
      font-weight: 500;
    }
    .button-bar {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 99;
      background: #ffffff;
      box-shadow: 0 1rpx 20rpx 0 rgba(128, 128, 128, 0.2);
      padding: 20rpx;
    }
  }
}
</style>
