<template>
	<a-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></a-search>
	<a-biaoge :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
		@page="getPage" :loading="loading">
		<template #meet_status="{ record }">
			<span v-if="record.status == 1">开启</span>
			<span v-if="record.status == 2">关闭</span>
		</template>
		<template #default="{ record }">
			<a-row :gutter="20">
				<a-popconfirm title="是否要申请参加该招聘会?" @confirm="applyFor(record.id)">
					<a-col><a-button type="primary" size="small">申请</a-button></a-col>
				</a-popconfirm>
				<a-popconfirm placement="left" ok-text="关闭" @confirm="confirm">
					<template #icon></template>
					<template #title>
						<a-card style="width: 600px;  overflow: auto;">
							<a-card-meta :title="detailData.title" >
								<template #description>
									<div>
										发布时间： {{detailData.created_at}}
									</div>
									<div>
										招聘会地点： {{detailData.address}}
									</div>
								</template>
							</a-card-meta>
							<a-divider />
							<div style="height: 600px; overflow: auto;">
								<div v-html="detailData.content"></div>
							</div>
						</a-card>
					</template>
					<a-button type="primary" size="small" @click="toDetail(record)">详情</a-button>
				</a-popconfirm>
			</a-row>
		</template>
	</a-biaoge>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed } from 'vue';
	import he from 'he';
	import { PostRecruitmentList, PostRecruitmentbookAdd, PostRecruitmentBookcompany } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/components/company/meet/subscribe/columns';
	import ASearch from '@/components/company/meet/subscribe/search.vue';
	import { warnToast, successToast } from '@/utils/toastHelper';
	let { commomParams } = useCommon();
	let loading = ref<Boolean>(true);

	onMounted(() => {
		getData(commomParams.value.search);
	})

	const searchData = (data : object) => {
		commomParams.value.search = data
		getData();
	}

	const clearData = (data : object) => {
		if (data) {
			commomParams.value.search = data
		} else {
			commomParams.value.search = {
				page: 1,
				pagesize: 10,
				sort: 'id',
				sortby: 'asc',
				keyword: ''
			}
		}
		getData();
	}


	const getPage = (data : object) => {
		commomParams.value.search.page = data.current;
		commomParams.value.search.pagesize = data.pageSize;
		getData();
	}
	const getData = async () => {
		try {
			loading.value = true;
			let res = await PostRecruitmentList(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.recruitments;
			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
			};
		} catch {
			loading.value = false;
		}
	}

	// 申请
	const applyFor = (val) => {
		PostRecruitmentbookAdd({ recruitment_id: val, company_id: 0 }).then(res => {
			successToast('预定成功')
		})
	}

	// 详情
	let detailData = ref<object>({})
	const toDetail = (data) => {
		detailData.value = data
		detailData.value.content = he.decode(detailData.value.content)
	}
</script>

<style scoped lang="less">

</style>