<!--
 * @Author: zwq
 * @Date: 2023-01-04 10:29:40
 * @LastEditors: zhp
 * @LastEditTime: 2023-06-20 15:24:30
 * @Description: 
-->
<template>
  <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">
    <el-form-item prop="factoryId" :label="$t('code.factoryName')">
      <el-select v-model="dataForm.factoryId" :placeholder="$t('code.factoryName')">
        <el-option v-for="item in factoryList" :key="item.id" :label="item.factoryName" :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="batchNo" :label="$t('code.batchNo')">
      <el-input v-model="dataForm.batchNo" :placeholder="$t('code.batchNo')"></el-input>
    </el-form-item>
    <el-form-item prop="inspectionType" :label="$t('code.inspectionType')">
      <el-select v-model="dataForm.inspectionType" :placeholder="$t('code.inspectionType')">
        <el-option v-for="item in inspectionTypeList" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="recheck" :label="$t('code.recheck')">
      <el-switch v-model="dataForm.recheck" :active-value="1" :inactive-value="0">
      </el-switch>
    </el-form-item>
    <el-form-item prop="productId" :label="$t('code.productName')">
      <el-select v-model="dataForm.productId" :placeholder="$t('code.productName')">
        <el-option v-for="item in productList" :key="item.id" :label="item.name" :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="supplierId" :label="$t('code.supplierName')">
      <el-select v-model="dataForm.supplierId" :placeholder="$t('code.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="customSamplingId" :label="$t('code.customSampling')">
      <el-select v-model="dataForm.customSamplingId" :placeholder="$t('code.customSampling')">
        <el-option v-for="item in samplingPlanList" :key="item.id" :label="item.sampleRange" :value="item.id">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item prop="recheck" :label="$t('code.recheck')">
      <el-switch v-model="dataForm.recheck" :active-value="1" :inactive-value="0">
      </el-switch>
    </el-form-item>
    <el-form-item prop="task" :label="$t('code.task')">
      <el-switch v-model="dataForm.task" :active-value="1" :inactive-value="0">
      </el-switch>
    </el-form-item>
    <el-form-item prop="inspectionStatus" :label="$t('code.inspectionStatus')">
      <el-select v-model="dataForm.inspectionStatus" :placeholder="$t('code.inspectionStatus')">
        <el-option v-for="item in inspectionStatusList" :key="item.id" :label="item.name" :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: "/basic/qmsCustomerType",
        infoURL: "/basic/qmsCustomerType/{id}",
        getCodeURL: '/basic/qmsControlMode/getCode',
        getFactoryURL: '/code/factory/page',
        getProductURL: '/basic/product/page',
        getSupplierURL: '/supplier/qmsSupplier/page',
        getDictDataList: '/sys/dict/data/page',
        getUserURL: '/sys/user/page',
        getSamplingPlanURL: '/quality/qmsSamplingPlan/page'
      },
      // urlOptions: {
      //   submitURL: "/sys/params/",
      //   infoURL: "/sys/params",
      // },
      inspectionStatusList: [
        {
          id: 0,
          name: '未登记'
        },
        {
          id: 1,
          name: '已登记'
        }
      ],
      supplierList: [],
      userList: [],
      samplingPlanList: [],
      unitList: [],
      productList: [],
      factoryList: [],
      visible: false,
      inspectionTypeList: [{
        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抽检'
      },
      ],
      dataForm: {
        batchNo:null,
        customSamplingId: null,
        endTime: null,
        factoryId: null,
        inspectionStatus: null,
        inspectionType: null,
        productId: null,
        recheck: null,
        startTime: null,
        supplierId: null,
        task: null,
        userId: null,
      },
    };
  },
  computed: {
    // dataRule() {
    //   return {
    //     paramCode: [
    //       {
    //         required: true,
    //         message: this.$t("validate.required"),
    //         trigger: "blur",
    //       },
    //     ],
    //     paramValue: [
    //       {
    //         required: true,
    //         message: this.$t("validate.required"),
    //         trigger: "blur",
    //       },
    //     ],
    //   };
    // },
  },
  mounted () {
    this.getDict()
  },
  methods: {
    getDict() {
      this.$http
        .post(this.urlOptions.getSamplingPlanURL, {
          params: this.listQuery
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res);
            this.samplingPlanList = res.data.list
          }
        })
        .catch(() => {
        })
      this.$http
        .post(this.urlOptions.getProductURL, {
          params: this.listQuery
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res);
            this.productList = res.data.list
          }
        })
        .catch(() => {
        })
      this.$http
        .post(this.urlOptions.getSupplierURL, {
          params: this.listQuery
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res);
            this.supplierList = res.data.list
          }
        })
        .catch(() => {
        })
      this.$http
        .post(this.urlOptions.getFactoryURL, {
          params: this.listQuery
        })
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res);
            this.factoryList = res.data.list
          }
        })
        .catch(() => {
        })
      // console.log(111111);
    },
    // init(id) {
    //   this.dataForm.id = id || "";
    //   this.visible = true;
    //   this.$nextTick(() => {
    //     this.$refs["dataForm"].resetFields();
    //     if (this.dataForm.id) {
    //       this.getInfo();
    //     }
    //   });
    // },
    // 获取信息
    // getInfo() {
    //   this.$http
    //     .get(`/sys/params/${this.dataForm.id}`)
    //     .then(({ data: res }) => {
    //       if (res.code !== 0) {
    //         return this.$message.error(res.msg);
    //       }
    //       this.dataForm = {
    //         ...this.dataForm,
    //         ...res.data,
    //       };
    //     })
    //     .catch(() => {});
    // },
    // 表单提交
    handleConditionSearch() {
      this.$emit("successSubmit", this.dataForm)
    },
    // dataFormSubmitHandle: debounce(
    //   function () {
    //     // console.log(1111);
    //     // this.visible = false;
    //     this.$emit("successSubmit", this.dataForm.key);
    //     // this.$refs["dataForm"].validate((valid) => {
    //     //   if (!valid) {
    //     //     return false;
    //     //   }
    //     //   this.$http[!this.dataForm.id ? "post" : "put"](
    //     //     "/sys/params",
    //     //     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: () => {

    //     //         },
    //     //       });
    //     //     })
    //     //     .catch(() => {});
    //     // });
    //   },
    //   1000,
    //   { leading: true, trailing: false }
    // ),
  },
};
</script>
