<!--
 * @Author: zhp
 * @Date: 2023-02-14 15:02:26
 * @LastEditTime: 2023-04-13 16:01:55
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="150px">
    <el-form-item prop="inspectionTypeId" :label="$t('disqualification.inspectionTypeId')">
      <el-select v-model="dataForm.inspectionTypeId" :placeholder="$t('disqualification.inspectionTypeId')">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="title" :label="$t('disqualification.title')">
      <el-input v-model="dataForm.title" :placeholder="$t('disqualification.title')">
      </el-input>
    </el-form-item>
    <el-form-item prop="productCode" :label="$t('disqualification.productCode')">
      <el-input v-model="dataForm.productCode" :placeholder="$t('disqualification.productCode')">
      </el-input>
    </el-form-item>
    <el-form-item prop="orderNumber" :label="$t('disqualification.orderNumber')">
      <el-input v-model="dataForm.orderNumber" :placeholder="$t('disqualification.orderNumber')">
      </el-input>
    </el-form-item>
    <el-form-item prop="batchNo" :label="$t('disqualification.batchNo')">
      <el-input v-model="dataForm.batchNo" :placeholder="$t('disqualification.batchNo')">
      </el-input>
    </el-form-item>
    <el-form-item prop="remark" :label="$t('disqualification.remark')">
      <el-input v-model="dataForm.remark" :placeholder="$t('disqualification.remark')">
      </el-input>
    </el-form-item>
    <el-form-item prop="supplierId" :label="$t('disqualification.supplierName')">
      <el-select v-model="dataForm.supplierId" :placeholder="$t('disqualification.supplierName')">
        <el-option v-for="item in supplierList" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="productId" :label="$t('disqualification.productName')">
      <el-select v-model="dataForm.productId" :placeholder="$t('disqualification.productName')">
        <el-option v-for="item in productList" :key="item.id" :label="item.productName" :value="item.id">
        </el-option>
      </el-select>
    </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: "/nonconform/qmsApprovalDispositionTeamConfiguration",
        infoURL: "/nonconform/qmsApprovalDispositionTeamConfiguration/{ id }",
        // getTypeListURL: '/basic/qmsProductType/page',
        // getTeamListURL: '/basic/qmsTeam/page',
        getProductURL: '/basic/qmsProduct/page',
        getSupplierListURL: '/supplier/qmsSupplier/page'
      },
      supplierList:[],
      productList:[],
      typeList: [],
      teamList:[],
      listQuery: {
        limit: 999,
        page: 1
      },
      options: [{
        value: 0,
        label: '监控'
      },
      {
        value: 1,
        label: '电芯来料检验'
      },
      {
        value: 2,
        label: 'IQC抽检'
      },
      {
        value: 3,
        label: 'IQC抽检2'
      },
      {
        value: 4,
        label: '原料抽检'
      },
      {
        value: 5,
        label: '进货外观检验'
      },
      {
        value: 6,
        label: '库内原料检验'
      },
      {
        value: 7,
        label: '来料检验'
      },
      {
        value: 8,
        label: '胶片'
      },
      {
        value: 9,
        label: '抽检'
      },
      {
        value: 10,
        label: '巡检'
      }, {
        value: 11,
        label: '首检'
      },
      {
        value: 12,
        label: '末检'
      },
      {
        value: 13,
        label: '实时监测'
      },
      {
        value: 14,
        label: 'FQC抽检'
      },
      {
        value: 15,
        label: 'OQC抽检'
      },
      ],
      visible: false,
      dataForm: {
        id: null,
        productId: null,
        productCode: null,
        orderNumber: null,
        batchNo: null,
        supplierId: null,
        title:null,
        reportTime: null,
        userName:null,
        disposalStatus: null,
        disposalMethod: null,
        disposalTime: null,
        remark: null,
        inspectionTypeId: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",
        //   },
        // ],
      };
    },
  },
  mounted () {
    this.getData();
  },
  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()
        }
      });
    },
    getData() {
      // this.$http
      //   .get(this.urlOptions.getTypeListURL, this.listQuery)
      //   .then(({ data: res }) => {
      //     if (res.code === 0) {
      //       console.log(res.data);
      //       this.typeList = res.data.list
      //     }
      //   })
      //   .catch(() => {
      //   });
      this.$http
        .get(this.urlOptions.getSupplierListURL, this.listQuery)
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res.data);
            this.supplierList = res.data.list
          }
        })
        .catch(() => {
        })
      this.$http
        .get(this.urlOptions.getProductURL, {
          params: this.listQuery,
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res.data)
            this.productList = res.data.list
          }
        })
        .catch(() => {
        })
    },
    // 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(`/nonconform/qmsApprovalDispositionTeamConfiguration/${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>
