<template>
  <div class="app-container">
    <div style="width: 50%">
      <research-form
        ref="researchFormRef"
        v-model="form"
        :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>
    </div>
  </div>
</template>

<script name="EnterpriseAdd" setup>
import ResearchForm from "@/views/components/ResearchForm";
import tab from "@/plugins/tab";
import { reactive, ref, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { researchDetail, researchEdit } from "@/api/dataList/research";
import { ElMessage } from "element-plus";

const router = useRouter();
const route = useRoute();
const formType = ref(1);
const researchFormRef = ref(null);
const labelWidth = ref(140);
const data = reactive({
  form: {
    industrys: [],
  },
});
const { form } = toRefs(data);

/**
 * 返回列表页
 */
const cancel = () => {
  tab.closeOpenPage({
    path: "/approval/research",
  });
};

/**
 * 提交审核结果
 * @param state
 * @return {Promise<void>}
 */
const submitForm = async (state) => {
  form.value.examineStatus = state;
  await researchEdit({
    id: form.value.id,
    examineStatus: state,
  });
  ElMessage.success("审核成功");
  cancel();
};

const getDetailById = async () => {
  if (route.query.id) {
    const { data } = await researchDetail(route.query.id);
    form.value = data;
    form.value.industrys =
      data.industry?.split(",")?.map((el) => parseInt(el)) ?? [];
    form.value.researchs = data.research?.split(",") ?? [];
  }
};
getDetailById();
</script>
