<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 v-if="record.status == 1"><a-button type="primary" size="small" >通过</a-button></a-col>
				</a-popconfirm>
				<a-col v-if="record.status  == 1"><a-button type="primary" size="small" 
						@click="interview(record)" danger>不通过</a-button></a-col>
				<!-- 	<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>
	<resume-add v-if="openForm" :edit_record="edit_record" @successAdd="successAdd" @closeAdd="closeAdd"></resume-add>
	<resume-detail :detail_record="detail_record" @closeAdd="closePermission"></resume-detail>
	<a-modal v-model:open="openInterview" centered title="不通过原因" @ok="unpass">
		<a-textarea v-model:value="form.aduit_memo" placeholder="请输入不通过原因" />
	</a-modal>
</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 , GetCustomerUpdate} from '@/apis/models';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/views/jobSeeker/resume/columns';
	import { UserOutlined, DownOutlined } from '@ant-design/icons-vue';
	let { store, commomParams, showModal, showOtherModal1, message, ExclamationCircleOutlined, Modal } = useCommon();
	let loading = ref<Boolean>(true);
	let openForm = ref<Boolean>(false);
	onMounted(() => {
		commomParams.value.search.rand = false
		getData();
	})

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

	const clearData = (data : object) => {
		commomParams.value.search.rand = false
		if (data) {
			commomParams.value.search = data
		} else {
			commomParams.value.search = {
				page: 1,
				pagesize: 10,
				sort: 'id',
				sortby: 'desc',
				keyword: '',
				rand: false
			}
		}
		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) => {
		openForm.value = true
		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('审核通过');
		})
	}

	// 邀请面试
	let openInterview = ref<Boolean>(false);
	let form = {
		id: 0,
		customer_id: 0,
		status: 3,
		aduit_memo: ''
	}

	const interview = (record : Object) => {
		openInterview.value = true
		form.id = record.id;
		form.customer_id = record.customer_id;
		form.status = 3
		form.aduit_memo = '不通过'
	}


	const unpass = () => {
		PostJobapplicantUpdate(form).then(res => {
			message.success('审核不通过');
			openInterview.value = false
			getData();
		})
	}

	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>