<script setup>
import AgentForm from "@/views/components/AgentForm";
import { reactive, ref, toRefs } from "vue";
import { agentDetail, agentEdit } from "@/api/dataList/agent";
import { useRoute } from "vue-router";
import tab from "@/plugins/tab";

const route = useRoute();
const data = reactive({
  form: {
    idImage: [],
  },
});
const { form } = toRefs(data);
const agentFormRef = ref();
const getAgentDetail = (id) => {
  agentDetail(id).then((resp) => {
    form.value = resp.data;
    form.value.idImage = form.value.idCardPics?.split(",") ?? [];
    form.value.keywords = form.value.keyword?.split(",") ?? [];
  });
};

const cancel = () => {
  tab.closeOpenPage({
    path: "/approval/agent-approval",
  });
};
const submitForm = async (status) => {
  await agentEdit({
    brokerId: form.value.brokerId,
    examineStatus: status,
  });
  cancel();
};
if (route.query.id) {
  getAgentDetail(route.query.id);
} else {
  cancel();
}
</script>

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

<style lang="scss" scoped></style>
