<template>
  <view class="page-raw-feeding">
    <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.FillingMaterials") }}</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="MRP" prop="inMrpCodeList">
        <u-input
          v-model="form.inMrpCodeList"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.Feeding_VoucherNo')">
        <u-input
          v-model="form.credNo"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <!-- <u-form-item :label="this.$t('message.Feeding_VoucherDate')">
        <u-input v-model="form.credDateStr" :placeholder="this.$t('message.po_PleaseInput')" />
      </u-form-item> -->
      <u-form-item :label="this.$t('message.Pi_materielNo')">
        <u-input
          v-model="form.materialCodeList"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item
        :required="true"
        :label="this.$t('message.Pi_factory')"
        prop="sapFactoryCode"
      >
        <u-input
          v-model="form.sapFactoryCode"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.Pi_Station')">
        <u-input
          v-model="form.sendSpotList"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
      <u-form-item :label="this.$t('message.Pi_OrderNo')">
        <u-input
          v-model="form.inPrdOrderList"
          :placeholder="this.$t('message.po_PleaseInput')"
        />
      </u-form-item>
    </u-form>
    <view class="bottom-bar">
      <u-row class="button-bar">
        <u-col :span="6">
          <u-button type="primary" @click="onQuery">{{
            $t("message.Pi_order")
          }}</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, Ref } from "vue-property-decorator";
import { BasePage } from "@/components/base/page";
import { VForm, VFormRules } from "vue/types/form";
import model from "./model";
import { session } from "@/store/modules/session";

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

  /**
   * 页面Module
   */
  model = model;

  /**
   * 表单数据
   */
  form: any = {
    sapFactoryCode: "",
  };

  /**
   * 表单校验规则
   */
  rules: VFormRules<any> = {
    inMrpCodeList: [
      { required: true, message: this.$t("message.Pi_InputMrp") as string },
    ],
    sapFactoryCode: [
      { required: true, message: this.$t("message.Pi_InputFactory") as string },
    ],
  };

  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  onReady() {
    this.$form.setRules(this.rules);
    //guoshuang 注掉 解决打开页面默认显示工厂号
    //this.form.sapFactoryCode = session.factoryCode;
  }

  /**
   * 查询
   */
  onQuery() {
    this.$form.validate(async (valid: boolean) => {
      if (!valid) return;
      const params = { ...this.form };
      if (this.form.inMrpCodeList) {
        params.inMrpCodeList = this.form.inMrpCodeList.split(",");
      } else {
        delete params.inMrpCodeList;
      }
      if (this.form.materialCodeList) {
        params.materialCodeList = this.form.materialCodeList.split(",");
      } else {
        delete params.materialCodeList;
      }
      if (this.form.sendSpotList) {
        params.sendSpotList = this.form.sendSpotList.split(",");
      } else {
        delete params.sendSpotList;
      }
      if (this.form.inPrdOrderList) {
        params.inPrdOrderList = this.form.inPrdOrderList.split(",");
      } else {
        delete params.inPrdOrderList;
      }
      await this.model.queryBlDetailList(params);
      if (this.model.blDetailList.length === 0) {
        // uni.showToast({
        //   icon: "none",
        //   title: this.$t("message.Pi_NoDataFound") as string,
        // });
        this.customToast(this.$t('message.Pi_NoDataFound') as string);
        return;
      }
      this.toPage(this.page.raw.handover.feeding.Location);
    });
    // this.toPage(this.page.raw.handover.feeding.Location);
  }
}
</script>

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

  .button-bar {
  }
}
</style>
