<template>
  <div class="app-container">
    <div style="width: 50%">
      <ExpertForm v-model="form" :isAdd="false" ref="expertForm" />
    </div>
    <el-button @click="submitForm(3)">审核拒绝</el-button>
    <el-button type="primary" @click="submitForm(2)">审核通过</el-button>
  </div>
</template>
<script>
import ExpertForm from "@/views/components/ExpertForm";
import { expertDetail, expertEdit, expertExamine } from "@/api/dataList/expert";
export default {
  components: {
    ExpertForm,
  },
  data() {
    return {
      form: {
        image: undefined,
        name: undefined,
        mobile: undefined,
        research_id: undefined, // 所属单位
        laboratory_id: undefined, // 所属实验室
        tenant_id: undefined,
        province: undefined, // 省code
        city: undefined, // 市code
        district: undefined, // 区code
        address: undefined, // 详细地址
        school: undefined,
        education: undefined,
        major: undefined,
        job: undefined,
        title: undefined,
        work_at: undefined,
        gender: 1,
        industrys: [],
        keywords: [],
        researchs: [],
        introduce: undefined,
      },
    };
  },
  methods: {
    submitForm(status) {
      console.log(this.form);
      if (this.$refs.expertForm.submitForm()) {
        const str =
          status == 2
            ? "<span style='color:green'>通过</span>"
            : "<span class='el-message-box__errormsg'>拒绝</span>";
        this.$prompt(`您将 ${str} 该数据审核，请输入处理备注`, "审核", {
          dangerouslyUseHTMLString: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          closeOnClickModal: false,
          inputType: "textarea",
          inputPattern: status == 2 ? "" : /^.{1,30}$/,
          inputErrorMessage: "请输入拒绝原因",
        })
          .then(({ value }) => {
            expertEdit(this.form).then((res) => {
              if (res.code == 200) {
                const query = {
                  id: this.form.id,
                  status,
                  remark: value,
                };
                expertExamine(query).then((res) => {
                  this.$store.dispatch("tagsView/delView", this.$route);
                  this.$router.go(-1);
                  this.$modal.msgSuccess("处理成功");
                });
              }
            });
          })
          .catch(() => {});
      } else {
        console.log("校验未通过");
      }
      // this.$refs["form"].validate((valid) => {
      //   if (valid) {
      //     if (this.form.id != undefined) {
      //       serviceEdit(this.form).then((response) => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } else {
      //       serviceAdd(this.form).then((response) => {
      //         this.$modal.msgSuccess("新增成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     }
      //   }
      // });
    },
  },
  created() {
    let { id } = this.$route.query;
    if (!id) {
      this.$message.error("无ID");
      this.$router.go(-1);
      return;
    }
    expertDetail({ id }).then((res) => {
      this.form = res.data;
    });
  },
};
</script>