<template>
  <div class="app-container">
    <div style="width: 50%">
      <ExpertForm
        ref="expertFormRef"
        v-model="form"
        :formType="formType"
        :isAdd="false"
        :labelWidth="140"
        :showTitle="true"
      />
    </div>
    <div :style="{ marginLeft: labelWidth + 'px' }">
      <el-button @click="submitForm('2')">审核拒绝</el-button>
      <el-button type="primary" @click="submitForm('1')">通过审核</el-button>
      <!-- <el-button type="primary" @click="submitForm('0')">test审核</el-button> -->
    </div>
  </div>
</template>

<script name="EnterpriseAdd" setup>
import ExpertForm from "@/views/components/ExpertForm/index.vue";
import tab from "@/plugins/tab";
import { companyDetail, companyEdit } from "@/api/expert/expert";
import { reactive, ref, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import useUserStore from "@/store/modules/user";

const router = useRouter();
const route = useRoute();
const formType = ref(1);
const expertFormRef = ref(null);
const labelWidth = ref(140);
const data = reactive({
  form: {},
});
const { form } = toRefs(data);
const cancel = () => {
  tab.closeOpenPage({
    path: "/approval/dataList/approval",
  });
};
const submitForm = async (state) => {
  await companyEdit({ id: form.value.id, examineStatus: state });
  useUserStore().getUnApprovedExpert();
  cancel();
  ElMessage.success("已审核");
};

const getDetailById = async () => {
  if (route.query.id) {
    const { data } = await companyDetail(route.query.id);
    form.value = data;
    form.value.keywords = data.keyword?.split(",") ?? [];
    form.value.researchs = data.research?.split(",") ?? [];
    form.value.district = data.area;
  }
};
getDetailById();
</script>
