<template>
	<a-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></a-search>
	<a-biaoge :data="commomParams.table.data" :columns="commomParams.table.columns" :pagination="commomParams.page"
		@page="getPage" :loading="loading">
		<template #default="{ record }">
			<a-row :gutter="20">
				<a-col>
					<a-dropdown placement="bottomRight">
						<template #overlay>
							<a-menu>
								<a-menu-item key="1">
									<a-button @click="cancel(record.id)" v-if="record.employ_status == 1" block>取消面试</a-button>
								</a-menu-item>
								<a-menu-item key="1">
									<a-button v-if="record.employ_status == 1" @click="hire(record.id)" block>录用</a-button>
									<a-button v-if="record.employ_status == 2" disabled block>已录用</a-button>
								</a-menu-item>
							</a-menu>
						</template>
						<a-button>
							操作
							<DownOutlined />
						</a-button>
					</a-dropdown>
				</a-col>
			</a-row>
		</template>
	</a-biaoge>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineEmits, createVNode } from 'vue';
	import { GetCompanyResumeInterviewList, PostCompanyResumeInterviewDel,PostCompanyResumeInterviewAdmission } from '@/apis/models';
	import ASearch from '@/components/company/resume/interview/search.vue';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/components/company/resume/interview/columns';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { DownOutlined } from '@ant-design/icons-vue';
	const emit = defineEmits();
	let { commomParams, 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: '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 GetCompanyResumeInterviewList(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;
		}
	}

	// 取消面试
	const cancel = (id : Number) => {
		Modal.confirm({
			title: '是否要取消本次面试',
			icon: createVNode(ExclamationCircleOutlined),
			centered: true,
			onOk() {
				PostCompanyResumeInterviewDel({ id: id }).then(res => {
					successToast('取消成功')
					getData();
				})
			},
			onCancel() {
		
			},
		});
	}

	// 录用
	const hire = (id : Number) => {
		Modal.confirm({
			title: '是否要录用该求职者',
			icon: createVNode(ExclamationCircleOutlined),
			centered: true,
			onOk() {
				PostCompanyResumeInterviewAdmission({ id: id, employ_status:2 }).then(res => {
					successToast('已保存')
					getData();
				})
			},
			onCancel() {

			},
		});
	}


	// const del = (id : number) => {
	// 	commomParams.value.delParam = { id: id };
	// 	PostCompanyDepartmentDel(commomParams.value.delParam).then(res => {
	// 		successToast('删除成功');
	// 		getData();
	// 	})
	// }
</script>

<style scoped lang="less">

</style>