<template>
	<div style="margin: 16px;">
		<a-search @searchData="searchData" @clearData="clearData" :search_params="commomParams.search"></a-search>
	</div>
	<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="edit(record)">修改</a-button>
								</a-menu-item>
								<a-menu-item key="2">
									发布
								</a-menu-item>
								<a-menu-item key="3">
									暂停
								</a-menu-item>
								<a-menu-item key="3">
									删除
								</a-menu-item>
								<a-menu-item key="3">
									<a-button @click="putInRecycle(record.id)">放入回收站</a-button>
								</a-menu-item>
								<a-menu-item key="3">
									查看
								</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 } from 'vue';
	import { PostCompanyJobList, PostCompanyJobRecycle } from '@/apis/models';
	import ASearch from '@/components/invite/manage/search.vue';
	import { useCommon } from '@/hooks/useCommon';
	import { cols } from '@/components/invite/manage/columns';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { DownOutlined } from '@ant-design/icons-vue';
	import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
	import { createVNode } from 'vue';
	import { Modal } from 'ant-design-vue';
	const emit = defineEmits();
	let { commomParams } = 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 PostCompanyJobList();
			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 edit = (record : Object) => {
		emit('toEdit', { record: record })
	}

	// 放入回收站
	const putInRecycle = (id) => {
		Modal.confirm({
			title: '是否要放入回收站',
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostCompanyJobRecycle({ id: id }).then(res => {
					successToast('已放入回收站')
				})
			},
			onCancel() {

			},
		});
	}


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

<style scoped lang="less">
	:deep(.ant-table-thead >tr>th) {
		background-color: #fff !important;
		border: none !important;
		color: #bbb !important;
	}

	:deep(.ant-table-thead >tr>th::before) {
		display: none !important;
	}

	:deep(.ant-table-tbody >tr >td) {
		border: none !important;
	}
</style>