<template>
  <view class="page-raw-returning">
    <view class="header" :style="{ backgroundColor: `rgba(23, 83, 234, ${scrollTop / 100})` }">
      <view class="left">
        <u-icon class="icon" name="arrow-left" @click="back" />
      </view>
      <view class="title">{{ $t('message.spareGoods') }}</view>
      <view class="right"></view>
    </view>
    <u-form class="form" ref="form" :model="form" :error-type="['toast']" label-width="150rpx">
      <!-- 单号查询 -->
      <u-form-item :required="true" :label="$t('message.dn_OddNumbers')" prop="orderNo">
        <u-search :placeholder="$t('message.Commission_tips1')" v-model.trim="nxOutCode" @search="query" :show-action="false"></u-search>
        <view class="single-right">
          <u-button type="primary" @click="query">{{ $t('message.Query') }}</u-button>
        </view>
      </u-form-item>
      <!-- 物料编码 -->
      <u-form-item :required="true" :label="$t('message.matcode')">
        <jPicker sureColor="#ff0000" style="width: 230rpx" @bindpicker="materialConfirm" showKey="value" valKey="value" :val="form.materialCode" class="search" :options="model.materielList" />
      </u-form-item>
      <!-- 物料描述 -->
      <u-form-item :label="$t('message.product_MaterialDes')">
        <u-input :disabled="true" v-model="form.materialDesc" placeholder="" style="overflow: hidden" />
      </u-form-item>
      <!-- 行项目 -->
      <u-form-item :label="$t('message.Line')">
        <u-input :disabled="true" v-model="form.rowItem" placeholder="" />
      </u-form-item>
      <!-- 需求数量 -->
      <u-form-item :label="$t('message.Quantity')">
        <u-input v-model="form.orderAmount" :disabled="true" type="number" placeholder="" />
      </u-form-item>
      <!-- 累计出库数量 -->
      <u-form-item :label="$t('message.totalNum')">
        <u-input v-model="form.outAmount" :disabled="true" type="number" placeholder="" />
      </u-form-item>
      <!-- 库位 -->
      <u-form-item :required="true" :label="$t('message.CommissionedLocation')">
        <jPicker sureColor="#ff0000" @bindpicker="wlcodeChange" showKey="value" valKey="value" :val="wlcode.value" :options="model.wlcodeList" :focus="true" />
      </u-form-item>
      <!-- 数量 -->
      <u-form-item :label="$t('message.dn_Number')">
        <u-input v-model="qty" :placeholder="$t('message.Summary_PleaseInputNumber')" :border="border" />
      </u-form-item>
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <u-col :span="6">
          <u-button type="warning" @click="detailed">{{ $t('message.detailed') }}</u-button>
        </u-col>
        <u-col :span="6">
          <u-button type="primary" @click="Posting">{{ $t('message.po_Submit') }}</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 jPicker from '@/components/J-Picker/jPicker.vue';
@Component({
  components: {
    jPicker,
  },
})
export default class stoOutboundDom extends BasePage {
  border: true;
  model = model;
  form: any = {};
  nxOutCode = '';
  wlcode: any = '';
  async onReady() {
    await this.model.querywocodeList();
    this.wlcode = this.model.wlcodeList[0];
  }
  async query() {
    if (this.nxOutCode == '') {
      this.customToast(this.$t('message.Commission_tips1') as any);
      return;
    }
    await this.model.queryReturningTypeList(this.nxOutCode);
    if (this.model.findSpareInfoByDNCode == '1') {
      uni.showToast({
        title: this.$t('message.successful') as any,
        duration: 2000,
        image: '/static/icons/icon-51.png',
      });
      this.form = this.model.beijianList[0];
    }
  }
  materialConfirm(e: any) {
    this.form = this.model.beijianList[e.pickerVal];
  }
  wlcodeChange(e: any) {
    this.wlcode = e.pickerName;
  }
  async detailed() {
    if (this.nxOutCode.length == 0) {
      this.customToast(this.$t('message.Warehouse_Tip1') as any);
      return;
    }
    await this.model.queryDetailed(this.nxOutCode);
    // this.toPage(this.page.product.SpareDeliverGoods.detail);
    this.redirectTo(this.page.product.SpareDeliverGoods.detail);
  }
  qty: any = '';
  async Posting() {
    if (this.form == {}) {
      this.customToast(this.$t('message.Commission_tips6') as any);
      return;
    }
    if (this.wlcode == '' || this.qty == '' || parseFloat(this.qty) <= 0) {
      this.customToast(this.$t('message.Commission_tips2') as any);
      return;
    }
    if (parseFloat(this.qty) > parseFloat(this.form.orderAmount) || parseFloat(this.qty) + parseFloat(this.form.outAmount) > parseFloat(this.form.orderAmount)) {
      this.customToast(this.$t('message.Commission_tips4') as any);
      return;
    }
    let params = {
      nxOutCode: this.nxOutCode,
      rowItem: this.form.rowItem,
      materialCode: this.form.materialCode,
      materialDesc: this.form.materialDesc,
      locCode: this.wlcode.label,
      qty: this.qty,
    };
    await this.model.submitbj(params);
    if (this.model.submitCode == '1') {
      uni.showToast({
        title: this.$t('message.Warehouse_Tip9') as any,
        duration: 2000,
        image: '/static/icons/icon-51.png',
      });
      this.qty = '';
      this.form = {};
      await this.query();
    }
  }
  back() {
    uni.navigateBack({ delta: 1 });
  }
}
</script>

<style lang="scss" scoped>
.uni-input-input:disabled {
  -webkit-text-fill-color: currentcolor;
  background-color: #1753ea;
}
.page-raw-returning {
  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;
    }
  }
  .single-right {
    button {
      //margin-top: 15rpx;
      width: 110rpx;
      height: 70rpx;
    }
  }

  .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;
  }

  // .button-bar {
  // }
}
.input[disabled] {
  background-color: rgb(228, 143, 143); //修改默认灰色样式
  color: #666;
  opacity: 1; //默认的不透明级别为0.3
  -webkit-text-fill-color: #666; //字体颜色安卓与IOS适配
  -webkit-opacity: 1; //不透明级别安卓与IOS适配
}
.disabled {
  background-color: rgb(228, 143, 143); //修改默认灰色样式
  color: #666;
  opacity: 1; //默认的不透明级别为0.3
  -webkit-text-fill-color: #666; //字体颜色安卓与IOS适配
  -webkit-opacity: 1; //不透明级别安卓与IOS适配
}
</style>
