<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="contact(record.customer_id)" block>查看联系方式</a-button>
								</a-menu-item>
								<a-menu-item key="1">
									<a-button @click="detail(record)" block>预览简历</a-button>
								</a-menu-item>
								<a-menu-item key="2">
									<a-button @click="interview(record)" block>邀请面试</a-button>
								</a-menu-item>
								<a-menu-item key="3">
									<a-button @click="putInTatent(record.customer_id)" block>放入人才库</a-button>
								</a-menu-item>
								<a-menu-item key="4">
									<a-button @click="putInRecycle(record.id)" block>放入回收站</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-date-picker v-model:value="time" @Change="timeChange" show-time style="width: 100%;" placeholder="请选择面试日期"
			size="large" :disabled-date="disabledDate" />
	</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 { GetCompanyResumeList, PostCompanyResumeInterviewAdd, PostCompanyTalentPoolAdd, PostCompanyResumeRecycle, GetJobapplicantContactdetail } from '@/apis/models';
	import ASearch from '@/components/company/resume/interview/search.vue';
	import ResumeDetail from '@/components/jobseeker/resume/detail/index.vue'
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/components/company/resume/receive/columns';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { DownOutlined } from '@ant-design/icons-vue';
	const emit = defineEmits();
	let { commomParams, ExclamationCircleOutlined, Modal, dayjs, disabledDate, showOtherModal1 } = 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 GetCompanyResumeList(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 contact = (id) => {
		Modal.confirm({
			title: `本次将会扣除一个点数，是否继续`,
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				GetJobapplicantContactdetail({ customer_id: id }).then(res => {
					successToast('请求成功，请进入已查看联系方式表查看')
					getData();
				})
			},
			onCancel() {

			},
		});
	}


	// 邀请面试
	let openInterview = ref<Boolean>(false);
	let form = {
		job_id: '',
		customer_id: '',
		interview_date_time: ''
	}
	const interview = (record : Object) => {
		openInterview.value = true
		form.job_id = record.job_id;
		form.customer_id = record.customer_id;
		form.interview_date_time = ''
		time.value = ''
	}

	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();
			})
		}

	}

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



	// 放入人才库
	const putInTatent = (id, num) => {
		Modal.confirm({
			title: `是否要放入人才库`,
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostCompanyTalentPoolAdd({ customer_id: id }).then(res => {
					successToast('已放入人才库')
					getData();
				})
			},
			onCancel() {

			},
		});
	}


	// 放入回收站
	const putInRecycle = (id) => {
		Modal.confirm({
			title: '是否要放入回收站',
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostCompanyResumeRecycle({ selected: [id] }).then(res => {
					successToast('已放入回收站')
					getData();
				})
			},
			onCancel() {

			},
		});
	}
</script>

<style scoped lang="less">

</style>