<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 {
  researchAdd,
  researchDetail,
  researchEdit,
} from "@/api/dataList/research";
export default {
  components: {
    ExpertForm,
  },
  data() {
    return {
      formType: 3,
      form: {
        id: undefined,
        image: undefined,
        name: undefined,
        code: undefined,
        tenant_id: undefined,
        province: undefined, // 省code
        city: undefined, // 市code
        district: undefined, // 区code
        address: undefined, // 详细地址
        industrys: [], // 领域
        researchs: [], // 研究方向
        license: undefined, // 营业执照地址
        introduce: undefined, // 介绍
      },
    };
  },
  methods: {
    submitForm() {
      if (this.$refs.expertForm.submitForm()) {
        if (this.form.id != undefined) {
          researchEdit(this.form).then((response) => {
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.go(-1);
            this.$modal.msgSuccess("修改成功");
          });
        } else {
          researchAdd(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) {
      researchDetail({ id }).then((res) => {
        this.form = res.data;
      });
    }
  },
};
</script>