<template>
  <view class="page-raw-receipt">
    <view
      class="header"
      :style="{ backgroundColor: `rgba(23, 83, 234, ${scrollTop / 100})` }"
    >
      <view class="left">
        <u-icon class="icon" name="arrow-left" @click="index" />
      </view>
      <view class="title">{{ $t("message.dn_ReceivingGoods") }}</view>
      <view class="right"></view>
    </view>
    <u-form class="form" ref="form" :model="form" label-width="180rpx">
      <u-form-item
        :required="true"
        :label="this.$t('message.dn_OddNumbers')"
        prop="documentNo"
      >
        <u-search
          :placeholder="this.$t('message.dn_PleaseScan')"
          v-model="form.documentNo"
          @search="model.queryOrderInInfo"
          :show-action="false"
        ></u-search>
      </u-form-item>
      <u-form-item :label="this.$t('message.dn_CarNumber')">
        <u-input
          v-model="model.orderInInfo.carNo"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.dn_Time')">
        <u-input
          v-model="model.orderInInfo.bookingTime"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.po_Supplier')">
        <u-input
          v-model="model.orderInInfo.supplyCode"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <!--      <u-form-item label="需求工段">-->
      <!--        <u-input v-model="model.orderInInfo.line" />-->
      <!--      </u-form-item>-->
      <u-form-item :label="this.$t('message.po_OrderType')">
        <u-input
          v-model="model.orderInInfo.poType"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.po_Location')">
        <u-input
          :disabled="true"
          v-model="model.orderInInfo.location"
          placeholder=""
        />
      </u-form-item>
      <!--      <u-form-item :label="this.$t('message.po_Location')" prop="cboPlace">-->
      <!--        <u-input-->
      <!--          v-model="form.cboPlace.label"-->
      <!--          type="select"-->
      <!--          @click="cboPlaceSelect = true"-->
      <!--          :placeholder="this.$t('message.po_PleaseInput')"-->
      <!--        />-->
      <!--        <u-select-->
      <!--          v-model="cboPlaceSelect"-->
      <!--          :list="model.cboPlaceList"-->
      <!--          @confirm="(v) => (form.cboPlace = v[0])"-->
      <!--        ></u-select>-->
      <!--      </u-form-item>-->
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <u-col :span="6">
          <u-button type="primary" @click="onSubmit">{{
            $t("message.po_Continue")
          }}</u-button>
        </u-col>
        <u-col :span="6">
          <u-button type="error" @click="back">{{
            $t("message.po_Return")
          }}</u-button>
        </u-col>
      </u-row>
    </view>
  </view>
</template>

<script lang="ts">
import { Component, Ref } from "vue-property-decorator";
import { BasePage } from "@/components/base/page";
import { VForm, VFormRules } from "vue/types/form";
import model from "./model";

interface OptionType {
  label: string;
  value: string;
}

@Component
export default class dnReceiptDom extends BasePage {
  /**
   * 表单引用
   */
  @Ref("form") readonly $form!: VForm;

  /**
   * 页面Module
   */
  model = model;
  index() {
    this.toPage(this.page.raw.index);
  }
  /**
   * 表单数据
   */
  form = {
    documentNo: null,
    cboPlace: {} as OptionType,
  };
  cboPlaceSelect = false;

  rules: VFormRules<any> = {
    documentNo: [
      { required: true, message: this.$t("message.dn_PleaseScan") as string },
    ],
    // cboPlace: [{ required: true, message: this.$t('message.Warehouse_Tip10') as string }],
  };

  value = "";
  show = false;

  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  onReady() {
    this.$form.setRules(this.rules);
    this.model.queryLocation();
    //清空数据项
    this.$form.resetFields();
    this.model.orderInInfo.carNo = "";
    this.model.orderInInfo.bookingTime = "";
    this.model.orderInInfo.supplyCode = "";
    this.model.orderInInfo.poType = "";
    this.model.orderInInfo.location = "";
  }
  back() {
    uni.navigateBack({ delta: 1 });
  }
  onSubmit() {
    this.$form.validate((valid: boolean) => {
      if (!valid) return;
      // if (!this.model.hasDnInfo) {
      //   uni.showToast({
      //     icon: 'none',
      //     title: this.$t('message.dn_PleaseScan') as string,
      //   });
      //   return;
      // }
      sessionStorage.setItem(
        "dnNo",
        JSON.stringify(this.form.documentNo) as any
      );
      this.toPage(this.page.raw.ingoods.dnReceipt.detail);
      // this.toPage(this.page.raw.ingoods.dnReceipt.Receiving);
    });
  }
}
</script>

<style lang="scss" scoped>
.page-raw-receipt {
  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>
