<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 :title="item.company_name" @click="toDetail(item.company_id)">
					<template #extra>
						<a-space>
							<div>{{item.read_time_txt}}</div>
						</a-space>
					</template>
				</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 { GetViewHistoryList } from '@/apis/models';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { router } from '@/router';
	import { useCommon } from '@/hooks/useCommon';
	let { store, commomParams, dayjs, richOption, ExclamationCircleOutlined, Modal } = 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 GetViewHistoryList(commomParams.value.search);
			loading.value = false;
			jobList.value = res.data.viewhistorys;
			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 = (company_id : Number) => {
		sessionStorage.setItem('tab_key', 1)
		sessionStorage.setItem('pubilc_id', company_id)
		sessionStorage.setItem('mode', 'detail')
		store.commit('getPageType', {
			pageType: ''
		})
		store.commit('setShowLoginBox', {
			showLoginBox: false
		})
		sessionStorage.setItem('pageType', '')
		store.commit('permissions/SET_PERMISSION', null)
		store.commit('permissions/SET_MENU', [])
		router.push({
			path: '/personal'
		})
	}


	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>