<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.RowRelocation') }}</view>
      <view class="right"></view>
    </view>
    <u-form class="form" ref="form" :error-type="['toast']" label-width="150rpx">
      <!-- 单号查询 -->
      <u-form-item :required="true" :label="$t('message.InventoryOrderNo')" prop="orderNo">
        <u-search :placeholder="$t('message.Commission_tips1')" v-model.trim="order3" @search="query" :show-action="false"></u-search>
      </u-form-item>
      <!-- 物料号选择 -->
      <u-form-item :required="true" :label="$t('message.CommissionedMaterielNo')">
        <u-input v-model="orderlist.productCode" type="select" @click="materialCodeSelect = true" :placeholder="$t('message.Warehouse_Tip6')" />
        <u-select :confirm-text="$t('message.product_Confirm')" :cancel-text="$t('message.product_Cancel')" v-model="materialCodeSelect" :list="model.materielList" @confirm="materialConfirm"></u-select>
      </u-form-item>
      <!-- 物料描述 -->
      <u-form-item :label="$t('message.po_MaterielDes')">
        <u-input :disabled="true" v-model="orderlist.productDescZh" placeholder="" style="overflow: hidden" />
      </u-form-item>
      <!-- 出库库位 -->
      <u-form-item :label="$t('message.Outbound')">
        <u-input :disabled="true" v-model="orderlist.originWl" placeholder="" />
      </u-form-item>
      <!-- 入库库位 -->
      <u-form-item :label="$t('message.Warehousing')">
        <u-input :disabled="true" v-model="orderlist.aimWl" placeholder="" />
      </u-form-item>
      <!-- 总数 -->
      <u-form-item :label="$t('message.Warehouse_TotalNumber')">
        <u-input :disabled="true" v-model="orderlist.qty" placeholder="" />
      </u-form-item>
      <!-- 本次数量 -->
      <u-form-item :label="$t('message.CommissionedThisNumber')">
        <u-input v-model="NEWqty" placeholder="" type="number" />
      </u-form-item>
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <!-- 确定 -->
        <u-col :span="6">
          <u-button type="primary" @click="submit">{{ $t('message.product_Confirm') }}</u-button>
        </u-col>
        <!-- 返回 -->
        <u-col :span="6">
          <u-button type="error" @click="uni.navigateBack()">{{ $t('message.po_Return') }}</u-button>
        </u-col>
      </u-row>
    </view>
  </view>
</template>
<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import model from './model';
import { session } from '@/store/modules/session';
@Component
export default class KanDanHandOver extends BasePage {
  order3 = '';
  NEWqty = '';
  model = model;
  materialCodeSelect = false;
  orderlist: any = [];
  //查询单号
  async query() {
    if (this.order3 === '') {
      this.customToast(this.$t('message.Warehouse_Tip') as string);
      return;
    } else {
      await this.model.takeYKOrder({
        order3: this.order3,
      });
      if (model.code == '1') {
        uni.showToast({ icon: 'success', title: this.$t('message.successful') as string });
        this.orderlist = model.materielList[0];
        this.NEWqty = model.materielList[0].qty;
      }
    }
  }
  //选择物料回调函数
  materialConfirm(v: any) {
    this.orderlist.productCode = v[0].label;
    model.materielList.forEach((item: any) => {
      if (this.orderlist.productCode == item.productCode) {
        this.orderlist = item;
        this.NEWqty = item.qty;
      }
    });
  }
  //提交数据
  async submit() {
    if (this.order3 == '') {
      this.customToast(this.$t('message.InventoryPleaseScan') as string);
      return;
    }
    if (this.orderlist.length == 0) {
      this.customToast(this.$t('message.Commission_tips6') as string);
      return;
    }
    if (this.NEWqty == '' || parseFloat(this.NEWqty) == 0) {
      this.customToast(this.$t('message.PleaseQuantity') as string);
      return;
    }
    if (parseFloat(this.NEWqty) > parseFloat(this.orderlist.qty)) {
      this.customToast(this.$t('message.greater') as string);
      return;
    }
    this.orderlist.type = '1';
    this.orderlist.keepBy = session.loginName;
    this.orderlist.orderType = '0';
    this.orderlist.qty = this.NEWqty;
    let arr = [];
    arr.push(this.orderlist);
    await model.onTakeoutConfirm(arr);
    if (model.code == '1') {
      this.customToast(this.$t('message.Warehouse_Tip9') as string);
      model.empty();
      setTimeout(() => {
        this.toPage(this.page.raw.warehouse.rowTransfer.index);
      }, 2000);
    }
  }
}
</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 {
      padding: 30rpx 0;
      line-height: 35rpx;
    }
  }
  .bottom-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>
