<!--
 * @Author: zhp
 * @Date: 2023-02-14 15:02:26
 * @LastEditTime: 2023-04-04 15:44:45
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="130px">
    <el-form-item prop="sampleRange" :label="$t('quality.sampleRange')">
      <el-input v-model="dataForm.sampleRange" :placeholder="$t('quality.sampleRange')">
      </el-input>
    </el-form-item>
    <el-form-item prop="fourPointZero" :label="$t('quality.fourPointZero')">
      <el-input v-model="dataForm.fourPointZero" :placeholder="$t('quality.fourPointZero')"></el-input>
    </el-form-item>
    <el-form-item prop="onePointFive" :label="$t('quality.onePointFive')">
      <el-input v-model="dataForm.onePointFive" :placeholder="$t('quality.onePointFive')"></el-input>
    </el-form-item>
    <el-form-item prop="onePointZero" :label="$t('quality.onePointZero')">
      <el-input v-model="dataForm.onePointZero" :placeholder="$t('quality.onePointZero')"></el-input>
    </el-form-item>
    <el-form-item prop="sixPointFive" :label="$t('quality.sixPointFive')">
      <el-input v-model="dataForm.sixPointFive" :placeholder="$t('quality.sixPointFive')"></el-input>
    </el-form-item>
    <el-form-item prop="ten" :label="$t('quality.ten')">
      <el-input v-model="dataForm.ten" :placeholder="$t('quality.ten')"></el-input>
    </el-form-item>
    <el-form-item prop="twoPointFive" :label="$t('quality.twoPointFive')">
      <el-input v-model="dataForm.twoPointFive" :placeholder="$t('quality.twoPointFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointFour" :label="$t('quality.zeroPointFour')">
      <el-input v-model="dataForm.zeroPointFour" :placeholder="$t('quality.zeroPointFour')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointOne" :label="$t('quality.zeroPointOne')">
      <el-input v-model="dataForm.zeroPointOne" :placeholder="$t('quality.zeroPointOne')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointOneFive" :label="$t('quality.zeroPointOneFive')">
      <el-input v-model="dataForm.zeroPointOneFive" :placeholder="$t('quality.zeroPointOneFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointSixFive" :label="$t('quality.zeroPointSixFive')">
      <el-input v-model="dataForm.zeroPointSixFive" :placeholder="$t('quality.zeroPointSixFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointTwoFive" :label="$t('quality.zeroPointTwoFive')">
      <el-input v-model="dataForm.zeroPointTwoFive" :placeholder="$t('quality.zeroPointTwoFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointZeroFour" :label="$t('quality.zeroPointZeroFour')">
      <el-input v-model="dataForm.zeroPointZeroFour" :placeholder="$t('quality.zeroPointZeroFour')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointZeroOne" :label="$t('quality.zeroPointZeroOne')">
      <el-input v-model="dataForm.zeroPointZeroOne" :placeholder="$t('quality.zeroPointZeroOne')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointZeroOneFive" :label="$t('quality.zeroPointZeroOneFive')">
      <el-input v-model="dataForm.zeroPointZeroOneFive" :placeholder="$t('quality.zeroPointZeroOneFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointZeroSixFive" :label="$t('quality.zeroPointZeroSixFive')">
      <el-input v-model="dataForm.zeroPointZeroSixFive" :placeholder="$t('quality.zeroPointZeroSixFive')"></el-input>
    </el-form-item>
    <el-form-item prop="zeroPointZeroTwoFive" :label="$t('quality.zeroPointZeroTwoFive')">
      <el-input v-model="dataForm.zeroPointZeroTwoFive" :placeholder="$t('quality.zeroPointZeroTwoFive')"></el-input>
    </el-form-item>
    <!-- <el-form-item prop="criticalSampleSize" :label="[$t('quality.fatalFlaw') + $t('quality.sampleSize')]">
      <el-input v-model="dataForm.criticalSampleSize"
        :placeholder="[$t('quality.fatalFlaw') + $t('quality.sampleSize')]">
      </el-input>
    </el-form-item>
    <el-form-item prop="criticalUnacceptable" :label="[$t('quality.fatalFlaw') + $t('quality.unacceptable')]">
      <el-input v-model="dataForm.criticalUnacceptable"
        :placeholder="[$t('quality.fatalFlaw') + $t('quality.unacceptable')]">
      </el-input>
    </el-form-item> -->
  </el-form>
</template>

<script>
import debounce from "lodash/debounce";
import basicAdd from "@/mixins/basic-add";
export default {
  mixins: [basicAdd],
  data() {
    return {
      urlOptions: {
        submitURL: "/quality/qmsSamplingPlan",
        infoURL: "/quality/qmsSamplingPlan/{id}"
      },
      options: [{
        value: 0,
        label: '不可用'
      },
      {
        value: 1,
        label: '可用'
      }],
      visible: false,
      dataForm: {
        id: null,
        fourPointZero: null,
        onePointFive:null,	
        onePointZero:null,
        sampleRange: null,	
        sixPointFive: null,
        ten: null,
        twoPointFive: null,
        zeroPointFour: null,
        zeroPointOne: null,
        zeroPointOneFive: null,
        zeroPointSixFive: null,	
        zeroPointTwoFive: null,
        zeroPointZeroFour: null,
        zeroPointZeroOne: null,
        zeroPointZeroOneFive: null,
        zeroPointZeroSixFive: null,
        zeroPointZeroTwoFive: null,
      },
    };
  },
  computed: {
    dataRule() {
      return {
        // dictLabel: [
        //   {
        //     required: true,
        //     message: this.$t("validate.required"),
        //     trigger: "blur",
        //   },
        // ],
        // dictValue: [
        //   {
        //     required: true,
        //     message: this.$t("validate.required"),
        //     trigger: "blur",
        //   },
        // ],
        // sort: [
        //   {
        //     required: true,
        //     message: this.$t("validate.required"),
        //     trigger: "blur",
        //   },
        // ],
      };
    },
  },
  methods: {
    init(id, ) {
      this.dataForm.id = id || ""
      // console.log(11111)
      // this.dataForm.dictTypeId = dictTypeId || "";
      this.visible = true
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.getInfo()
        } else {
          // this.getCode()
        }
      });
    },
    // getCode() {
    //   this.$http.post(this.urlOptions.getCodeURL)
    //     .then(({ data: res }) => {
    //       if (res.code === 0) {
    //         console.log(res);
    //         this.dataForm.customSamplingCode = res.data
    //       }
    //     })
    //     .catch(() => {
    //     });
    // },
    // 获取信息
    getInfo() {
      this.$http
        .get(`/quality/qmsCustomSampling/${this.dataForm.id}`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.dataForm = {
            ...this.dataForm,
            ...res.data,
          };
        })
        .catch(() => {});
    },
    // 表单提交
    dataFormSubmitHandle: debounce(
      function () {
        this.$refs["dataForm"].validate((valid) => {
          if (!valid) {
            return false;
          }
          this.$http[!this.dataForm.id ? "post" : "put"](this.urlOptions.submitURL, this.dataForm)
            .then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg);
              }
              this.$message({
                message: this.$t("prompt.success"),
                type: "success",
                duration: 500,
                onClose: () => {
                  console.log(1111);
                  this.visible = false;
                  this.$emit("successSubmit");
                },
              });
            })
            .catch(() => {});
        });
      },
      1000,
      { leading: true, trailing: false }
    ),
  },
};
</script>
