<template>
	<a-modal v-model:visible="showCompanyModel" title="查看参加招聘会的企业" @cancel="cancelModal" width="80%" :footer="null">
		<a-c-table :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
			@page="getPage" :loading="loading">
			<template #status="{ record }">
				<a-tag color="green" v-if="record.status == 2">通过</a-tag>
				<a-tag color="red" v-if="record.status == 3">不通过</a-tag>
			</template>
			<template #default="{ record }">
				<a-row :gutter="10">
					<template v-if="record.status == 1">
						<a-popconfirm title="通过?" @confirm="pass(record)">
							<a-col><a-button type="primary" size="small" primary>通过</a-button></a-col>
						</a-popconfirm>
						<a-popconfirm title="不通过?" @confirm="unPass(record)">
							<a-col><a-button type="primary" size="small" primary>不通过</a-button></a-col>
						</a-popconfirm>
					</template>
					<a-popconfirm title="是否移除该企业?" @confirm="delRecruitmentbookCompany(record.id)">
						<a-col><a-button type="primary" size="small" danger>移除</a-button></a-col>
					</a-popconfirm>
				</a-row>
			</template>
		</a-c-table>
	</a-modal>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineProps, watch, defineEmits } from 'vue';
	import { GetRecruitmentBookList, PostRecruitmentBookUpdate, PostRecruitmentBookDel } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/views/jobFair/list/company/columns.ts';
	import { message } from 'ant-design-vue';
	let { store, commomParams } = useCommon();
	const emit = defineEmits();
	let props = defineProps(['company_record']);
	let loading = ref<Boolean>(true);

	let showCompanyModel = computed(() => {
		return store.state.showCompanyModel;
	})

	let company_record = ref<Object>({});
	watch(() => props.company_record, (newVal1) => {
		company_record.value = newVal1;
		commomParams.value.search.recruitment_id = newVal1.id;
		getData()
	})

	const getData = async (val) => {
		try {
			loading.value = true;
			let res = await GetRecruitmentBookList(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.recruitmentbooks;
			commomParams.value.table.columns = cols;
			commomParams.value.page = {
				current: commomParams.value.search.page,
				pageSize: commomParams.value.search.pagesize,
				total: res.data.total,
				pageSizeOptions: ['10', '20', '30', '40'],
				hideOnSinglePage: false,
				showSizeChanger: true,
				recruitment_id: company_record.value.id
			};
		} catch {
			loading.value = false;
		}
	}

	const getPage = (data : object) => {
		commomParams.value.search.page = data.current;
		commomParams.value.search.pagesize = data.pageSize;
		getData();
	}

	const cancelModal = () => {
		store.commit('getShowCompanyModel', {
			showCompanyModel: false
		})
	}

	// 通过
	const pass = (record : object) => {
		PostRecruitmentBookUpdate({
			id: record.id,
			recruitment_id: record.recruitment_id,
			company_id: record.company_id,
			status: 2,
		}).then(res => {
			message.success('审核通过');
			getData();
		})
	}

	// 通过
	const unPass = (record : object) => {
		PostRecruitmentBookUpdate({
			id: record.id,
			recruitment_id: record.recruitment_id,
			company_id: record.company_id,
			status: 3,
		}).then(res => {
			message.success('审核不通过');
			getData();
		})
	}

	// 移除
	const delRecruitmentbookCompany = (id) => {
		commomParams.value.delRecord = { id: id };
		PostRecruitmentBookDel(commomParams.value.delRecord).then(res => {
			message.success('删除成功');
			getData();
		})
	}
</script>

<style>
</style>