<template>
	<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="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>
</template>

<script setup lang="ts">
	import { ref, onMounted, computed, defineEmits, createVNode } from 'vue';
	import { GetCompanyJobRecycleList, PostCompanyJobRecoverRecycle } from '@/apis/models';
	import ASearch from '@/components/company/invite/manage/search.vue';
	import { cols } from '@/components/company/invite/manage/columns';
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { DownOutlined } from '@ant-design/icons-vue';
	import { useCommon } from '@/hooks/useCommon';
	let { commomParams, ExclamationCircleOutlined, Modal } = useCommon();
	const emit = defineEmits();
	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 GetCompanyJobRecycleList(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 edit = (record : Object) => {
		emit('toEdit', { record: record })
	}

	// 移除回收站
	const popInRecycle = (id) => {
		Modal.confirm({
			title: '是否要移出回收站',
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostCompanyJobRecoverRecycle({ id: id }).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>