<template>
	<a-card title="求职者专业统计">
		<major-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></major-search>
		<a-c-table :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
			@page="getPage" :loading="loading">
		</a-c-table>
	</a-card>
</template>

<script setup lang="ts">
	import { ref, onMounted } from 'vue';
	import MajorSearch from '@/components/statistics/resume/major/search/index.vue';
	import { GetStatsMajor } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	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: 'major',
				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 GetStatsMajor(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.list;
			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;
		}
	}
</script>

<style>
</style>