<template>
  <div class="app-container">
    <div style="width: 50%">
      <laboratory-form
        ref="expertFormRef"
        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 LaboratoryForm from "@/views/components/LaboratoryForm";
import tab from "@/plugins/tab";
import { reactive, ref, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
  casLaboratoryDetail,
  casLaboratoryUpdate,
} from "@/api/dataList/laboratory";

const router = useRouter();
const route = useRoute();
const formType = ref(1);
const expertFormRef = ref(null);
const labelWidth = ref(140);
const data = reactive({
  form: {
    image: undefined,
    name: undefined,
    tenantId: undefined,
    province: undefined, // 省code
    city: undefined, // 市code
    district: undefined, // 区code
    address: undefined, // 详细地址
    product: undefined,
    kind: undefined,
    code: undefined,
    inviterCode: undefined,
    url: undefined,
    industrys: [],
    keywords: [],
    directions: [],
    introduce: undefined,
    license: undefined,
  },
});
const { form } = toRefs(data);
const cancel = () => {
  tab.closeOpenPage({
    path: "/approval/data-list/laboratory",
  });
};
const submitForm = async (state) => {
  form.value.examineStatus = state;
  await casLaboratoryUpdate({
    id: form.value.id,
    examineStatus: state,
  });
  cancel();
};

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