<template>
  <div class="app-container">
    <div style="width: 50%">
      <ExpertForm
        v-model="form"
        :showTitle="true"
        :formType="formType"
        ref="expertForm"
      />
    </div>
    <el-button @click="$router.go(-1)">取消</el-button>
    <el-button type="primary" @click="submitForm">提交</el-button>
  </div>
</template>
<script>
import ExpertForm from "@/views/components/ExpertForm";
import {
  expertAdd,
  expertDetail,
  expertEdit,
  expertExamine,
} from "@/api/dataList/expert";
export default {
  components: {
    ExpertForm,
  },
  data() {
    return {
      formType: 1,
      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() {
      if (this.$refs.expertForm.submitForm()) {
        if (this.form.id != undefined) {
          expertEdit(this.form).then((response) => {
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.go(-1);
            this.$modal.msgSuccess("修改成功");
          });
        } else {
          expertAdd(this.form).then((res) => {
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.go(-1);
            this.$modal.msgSuccess("新增成功");
          });
        }
      } else {
        console.log("校验未通过");
      }
    },
  },
  created() {
    const { id } = this.$route.query;
    if (id) {
      expertDetail({ id }).then((res) => {
        this.form = res.data;
      });
    }
  },
};
</script>