<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="2">
									<a-button @click="detail(record)" block>预览简历</a-button>
								</a-menu-item>
								<a-menu-item key="3">
									<a-button @click="interview(record)" block>邀请面试</a-button>
								</a-menu-item>
								<a-menu-item key="1">
									<a-button @click="popInRecycle(record.id)">移出人才库</a-button>
								</a-menu-item>
						
							</a-menu>
						</template>
						<a-button>
							操作
							<DownOutlined />
						</a-button>
					</a-dropdown>
				</a-col>
			</a-row>
		</template>
	</a-biaoge>
	<a-modal v-model:open="openInterview" centered title="面试邀请" @ok="interviewOk">
		<a-space direction="vertical" style="width: 100%;">
			<a-select v-model:value="position_name" @change="positionChange" placeholder="请进行搜索选择职位" show-search
				:filter-option="false" label-in-value @search="positionSearch" size="large"
				style="width: 100%;">
				<a-select-option v-for="item in position_list" :key="item.id" :value="item.id"
					:label="item.name" label-in-value>{{item.name}}</a-select-option>
			</a-select>
			<a-date-picker v-model:value="time" @Change="timeChange" show-time style="width: 100%;"
				placeholder="请选择面试日期" size="large" :disabled-date="disabledDate" />
		</a-space>
	</a-modal>
	<resume-detail v-if="detail_record" :detail_record="detail_record"></resume-detail>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineEmits, createVNode } from 'vue';
	import { GetCompanyTalentPoolList, PostCompanyTalentPoolDel, PostCompanyResumeInterviewAdd, PostCompanyJobList } from '@/apis/models';
	import ASearch from '@/components/company/resume/talent/search.vue';
	import ResumeDetail from '@/components/jobseeker/resume/detail/index.vue'
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/components/company/resume/talent/columns';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { DownOutlined } from '@ant-design/icons-vue';
	const emit = defineEmits();
	let { commomParams, ExclamationCircleOutlined, Modal,showOtherModal1 ,disabledDate , dayjs} = useCommon();
	const dayjsRef = ref(dayjs);
	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 GetCompanyTalentPoolList(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 popInRecycle = (id) => {
		Modal.confirm({
			title: '是否要移出人才库',
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostCompanyTalentPoolDel({ selected: [id] }).then(res => {
					successToast('已移出人才库')
					getData();
				})
			},
			onCancel() {
	
			},
		});
	}
	
	let detail_record = ref<Object>(null)
	const detail = (record) => {
		detail_record.value = record;
		showOtherModal1()
	}
	
	// 邀请面试
	let openInterview = ref<Boolean>(false);
	let form = {
		job_id: '',
		customer_id: '',
		interview_date_time: ''
	}
	
	
	const interview = (record : Object) => {
		positionSearch('')
		console.log(record)
		openInterview.value = true
		form.job_id = '';
		form.customer_id = record.customer_id;
		form.interview_date_time = ''
		time.value = '';
		position_name.value = null;
	}
	// 选择职位
	let position_list = ref<Object[]>([])
	let position_name = ref<String>(null)
	const positionSearch = (val) => {
		PostCompanyJobList({ keyword: val }).then(res => {
			position_list.value = res.data.list;
		})
	}
	const positionChange = (val : Object) => {
		position_name.value = val.option.label;
		form.job_id = Number(val.key);
	}
	let time = ref<String>('');
	const timeChange = (val) => {
		form.interview_date_time = dayjsRef.value(val).format('YYYY-MM-DD HH:mm:ss');
	}
	
	const interviewOk = () => {
		console.log(form)
		if (!form.interview_date_time) {
			warnToast('请选择面试时间')
			return;
		} else {
			PostCompanyResumeInterviewAdd(form).then(res => {
				successToast('已发送邀请')
				openInterview.value = false
				getData();
			})
		}
	
	}
	


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

<style scoped lang="less">

</style>