<!--
 * @Author: zhp
 * @Date: 2023-02-14 15:02:26
 * @LastEditTime: 2023-05-15 14:35:31
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="150px">
    <el-form-item prop="department" :label="$t('laboratory.department')">
      <el-input v-model="dataForm.department" :placeholder="$t('laboratory.department')">
      </el-input>
    </el-form-item>
    <el-form-item prop="position" :label="$t('laboratory.position')">
      <el-input v-model="dataForm.position" :placeholder="$t('laboratory.position')">
      </el-input>
    </el-form-item>
    <el-form-item prop="responsibilitie" :label="$t('laboratory.responsibilitie')">
      <el-input v-model="dataForm.responsibilitie" :placeholder="$t('laboratory.responsibilitie')">
      </el-input>
    </el-form-item>
    <el-form-item prop="expectedReturnDate" :label="$t('gage.expectedReturnDate')">
      <el-date-picker v-model="dataForm.expectedReturnDate" type="datetime" :placeholder="$t('gage.expectedReturnDate')"
        format='yyyy-MM-dd HH:mm:ss' valueFormat='yyyy-MM-ddTHH:mm:ss'>
      </el-date-picker>
    </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: "/gage/qmsLaboratoryEmployeeResume",
        infoURL: "/gage/qmsLaboratoryEmployeeResume/{ id }",
        dictionaryDetailList: '/mutual/qmsDataDictionaryDetail/page',
        getUserList: '/sys/user/page'
        // getTeamListURL: '/basic/qmsTeam/gape',
        // getProductURL: '/basic/qmsProduct/gape',
        // getSupplierListURL: '/supplier/qmsSupplier/gape'
      },
      gageList: [],
      userList:[],
      departmentList: [],
      processList: [
        {
          id: 0,
          name: '未审核'
        },
        {
          id: 1,
          name: '不同意'
        },
        {
          id: 2,
          name: '同意'
        }
      ],
      listQuery: {
        limit: 999,
        gape: 1
      },
      eventList: [
        {
        id: 0,
          name: '领用'
      },
      {
        id: 1,
        name: '归还'
        },
        {
          id: 2,
          name: '量具报废'
        },
        {
          id: 3,
          name: '量具维修'
        },
        {
          id: 4,
          name: '量具购买'
        },
      ],
      visible: false,
      dataForm: {
        department:null,
        endDate: null,
        id: null,
        laboratoryTesterId: null,
        position: null,
        remark: null,
        responsibilitie: null,
        startDate: null,
        id: null,
        laboratoryTesterId: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(data) {
      this.dataForm.id = data.id ? data.id : ''
      this.dataForm.laboratoryTesterId = data.laboratoryTesterId ? data.laboratoryTesterId : ''
      // 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.getUserList, this.listQuery)
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res.data);
            this.userList = res.data.list
          }
        })
        .catch(() => {
        });
      this.$http
        .get(this.urlOptions.dictionaryDetailList, this.listQuery)
        .then(({ data: res }) => {
          if (res.code === 0) {
            console.log(res.data);
            this.departmentList = 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(`/gage/qmsLaboratoryEmployeeResume/${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>
