<template>
  <div class="app-container">
    <div style="width: 50%">
      <expert-form
        ref="expertFormRef"
        v-model="form"
        :formType="formType"
        :isAdd="false"
        :labelWidth="140"
        :showTitle="true"
      />
    </div>

    <div :style="{ marginLeft: 140 + 'px' }">
      <el-button @click="submitForm('2')">审核拒绝</el-button>
      <el-button type="primary" @click="submitForm('1')">通过审核</el-button>
      <!-- <el-button type="primary" @click="submitForm('0')">cancel审核</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/dataList/enterprise";
import { reactive, ref, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import useUserStore from "@/store/modules/user";

// const testCount = () => {
//   useUserStore().unApprovedBusinessPlus();
// };

const router = useRouter();
const route = useRoute();
const formType = ref(2);
const expertFormRef = ref(null);
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,
    examineStatus: "",*/
  },
});

const { form } = toRefs(data);
const cancel = () => {
  router.back();
  tab.closeOpenPage();
};

const submitForm = async (state) => {
  await companyEdit({ id: form.value.id, examineStatus: state });
  useUserStore().getUnApprovedBusiness();
  cancel();
  ElMessage.success("已审核");
};

const getDetailById = async () => {
  if (route.query.id) {
    const { data } = await companyDetail(route.query.id);
    form.value = data;
  }
};
getDetailById();
</script>
