<template>
	<job-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></job-search>
	<template v-if="!jobList || jobList.length == 0">
		<a-empty style="height: 100vh;">
			<template #description>
				无投递信息
			</template>
		</a-empty>
	</template>
	<template v-else>
		<a-row :gutter="[10,20]">
			<a-col span="8" v-for="(item, index) in jobList">
				<a-card hoverable :title="item.job_name">
					<template #extra>
						<div>企业查看状态：{{item.status_text}}</div>
					</template>
					<a-row>
						<a-col span="20">
							<div>投递时间：{{item.created_at}}</div>
							<div>企业名称：{{item.company_name}}</div>
						</a-col>
						<a-col span="4">
							<a-popover trigger="click" placement="right">
								<template #content>
									<job-detail v-if="detail_record" :detail_record="detail_record"></job-detail>
								</template>
								<a-button @click="detail(item.job_id)" type="primary">详情</a-button>
							</a-popover>
						</a-col>
					</a-row>
				</a-card>
			</a-col>
			<a-col span="24">
				<a-flex justify="center">
					<a-space>
						<a-pagination hideOnSinglePage :total="commomParams.page.total" @change="getPage" />
					</a-space>
				</a-flex>
			</a-col>
		</a-row>
	</template>
</template>

<script setup lang="ts">
	import { ref, computed, onMounted, defineEmits, createVNode } from 'vue';
	import JobDetail from '@/components/jobseeker/invite/detail/index.vue'
	import { GetJobseekListapplication } from '@/apis/models';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { useCommon } from '@/hooks/useCommon';
	let { store, commomParams, dayjs, richOption, ExclamationCircleOutlined, Modal, showOtherModal1 } = useCommon();
	const emit = defineEmits();
	let loading = ref<Boolean>(true);
	let jobList = ref([]);
	let total = ref<Number>(0)


	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: 12,
				sort: 'id',
				sortby: 'asc',
				keyword: ''
			}
		}
		getData();
	}


	const getPage = (page, pageSize) => {
		commomParams.value.search.page = page;
		commomParams.value.search.pagesize = pageSize;
		getData();
	}
	const getData = async () => {
		try {
			loading.value = true;
			let res = await GetJobseekListapplication(commomParams.value.search);
			loading.value = false;
			jobList.value = res.data.jobapplicationrecords;
			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 toDetail = (job_id : Number, company_id : Number) => {
	// 	sessionStorage.setItem('job_id', job_id)
	// 	sessionStorage.setItem('tab_key', 2)
	// 	sessionStorage.setItem('pubilc_id', company_id)
	// 	sessionStorage.setItem('mode', 'detail')
	// 	emit('detail')
	// }
	
	let detail_record = ref<Object>(null)
	const detail = (record) => {
		detail_record.value = record;
	}


	onMounted(() => {
		getData();
	})
</script>

<style lang="less" scoped>
	.job-box {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		// align-items: center;
		width: 100%;

		.job-title {
			padding: 20px;
			background-color: #ffffff;

			.aaaa {
				display: flex;
				justify-content: space-between;
			}
		}

		.job-company {
			padding: 20px;
			background-color: #cccccc;

			.aaaa {
				display: flex;
				justify-content: space-between;
			}
		}

	}

	.mt10 {
		margin-bottom: 10px;
	}
</style>