<template>
	<resume-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></resume-search>
	<a-c-operation @refresh="clearData" :need_add="false"></a-c-operation>
	<a-c-table :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
		@page="getPage" :loading="loading">
		<template #default="{ record }">
			<a-row :gutter="10">
				<!-- <a-col><a-button type="primary" size="small" primary @click="edit(record)">编辑</a-button></a-col> -->
				<a-col><a-button type="primary" size="small" primary @click="detail(record)">预览</a-button></a-col>
				<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>
				<a-popconfirm title="是否要推送该简历到ES?" @confirm="pushEs(record.customer_id)">
					<a-col><a-button type="primary" size="small" primary>推送该简历到ES</a-button></a-col>
				</a-popconfirm>
			</a-row>
		</template>
	</a-c-table>
	<!-- <role-add :edit_record="edit_record" @successAdd="successAdd" @closeAdd="closeAdd"></role-add> -->
	<resume-detail :detail_record="detail_record" @closeAdd="closePermission"></resume-detail>
</template>

<script lang="ts" setup>
	import { ref, onMounted, watch, computed, createVNode } from 'vue';
	import ResumeSearch from '@/views/jobSeeker/resume/search/index.vue';
	// import ResumeAdd from '@/views/jobSeeker/resume/add/add.vue';
	import ResumeDetail from '@/views/jobSeeker/resume/detail/detail.vue';
	import { PostJobseekerList, PostJobapplicantUpdate, PostEsJobseeker } from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/views/jobSeeker/resume/columns';
	let { store, commomParams, showModal, showOtherModal1, message, ExclamationCircleOutlined, Modal } = useCommon();
	let loading = ref<Boolean>(true);
	onMounted(() => {
		getData();
	})

	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: 'desc',
				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 PostJobseekerList(commomParams.value.search);
			loading.value = false;
			commomParams.value.table.data = res.data.seekers;
			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;
		}
	}


	// 编辑
	let edit_record = ref<Object>(null)
	const edit = (record : object) => {
		edit_record.value = record;
		showModal()
	}
	const successAdd = () => {
		getData();
	}
	const closeAdd = () => {
		edit_record.value = null;
	}

	// 删除
	// const delOneRole = (id : number) => {
	// 	commomParams.value.delRecord = { id: id };
	// 	PostRoleDel(commomParams.value.delRecord).then(res => {
	// 		message.success('删除成功');
	// 		getData();
	// 	})
	// }

	// 审核
	const pass = (record) => {
		PostJobapplicantUpdate({ customer_id: record.customer_id, id: record.id, status: 2 }).then(res => {
			message.success('审核通过');
		})
	}

	const unpass = (record) => {
		PostJobapplicantUpdate({ customer_id: record.customer_id, id: record.id, status: 3 }).then(res => {
			message.success('审核不通过');
		})
	}

	const pushEs = (customer_id) => {
		PostEsJobseeker({ customer_ids: [customer_id] }).then(res => {
			message.success('推送成功');
		})
	}



	let detail_record = ref<Object>(null)
	const detail = (record) => {
		detail_record.value = record;
		showOtherModal1()
	}
	const successPermission = () => {
		detail_record.value = null;
	}

	const closePermission = () => {
		detail_record.value = null;
	}
</script>

<style lang="less" scoped>

</style>