<template>
	<!-- 人员信息管理 -->
	<div class="pricemoitorrecord">
		<a-card :bordered="false">
			<a-space class="search">
				<div class="silt-title">
					<span style="width: 70px; margin-right: 12px; display: block; line-height: 30px">{{ '人员姓名' }}</span>
					<a-input @input="handleInput" style="width: 220px" v-model:value="SearchFormDel.name" placeholder="请输入" />
				</div>
				<div class="btnBox">
					<a-button type="primary" class="primarySele" @click="Search"> 查询 </a-button>
					<a-button class="snowy-buttom-left" @click="onReset"> 重置 </a-button>
					<a-button type="primary" class="primarySele" @click="onView('add')"> 新增 </a-button>
				</div>
			</a-space>
		</a-card>

		<div class="list" style="margin-top: 10px">
			<a-table :dataSource="tableData" :pagination="pagination" :columns="tableColumns">
				<template #bodyCell="{ column, record }">
					<template v-if="column.key === '操作'">
						<a-button type="link" @click="onView('chenk', record)">查看</a-button>
						<a-button type="link" @click="onView('edit', record)">编辑</a-button>

						<a-popconfirm title="确定要删除吗？" @confirm="onView('del', record)">
							<a-button type="link">删除</a-button>
						</a-popconfirm>
					</template>
				</template>
			</a-table>
		</div>
	</div>
</template>
<script setup>
	import business from '@/api/business/personnelApi'
	import { listPagination } from '@/hook/listlistPagination.js'
	import { reactive, ref, watch } from 'vue'
	import { useRouter, useRoute } from 'vue-router'
	import { defineComponent } from 'vue'
	import useRouterdel from '@/router/index'
	const formRef = ref(null)
	const router = useRouter()
	const route = useRoute()
	onMounted(() => {
		// onSearch()
	})
	// useRouterdel.beforeResolve((to, from, next) => {
	// 	console.log(to.fullPath == '/business/personnel')
	// 	if (to.fullPath == '/business/personnel') {
	// 		next()
	// 		onSearch()
	// 	} else {
	// 		next()
	// 	}
	// })
	watch(
		() => route,
		(newVal) => {
			if (newVal.fullPath == '/business/personnel') {
				setTimeout(() => {
					onSearch()
				}, 0)
			}
		},
		{ immediate: true, deep: true }
	)
	const tableColumns = [
		{
			title: '序号',
			dataIndex: 'Index',
			align: 'center',
			customRender: ({ text, record, index }) => {
				return `${index + 1}`
			}
		},
		{ title: '人员姓名', dataIndex: 'name' },
		{ title: '性别', dataIndex: 'gendeName' },
		{ title: '年龄', dataIndex: 'age' },
		{ title: '联系方式', dataIndex: 'contact' },
		{ title: '操作', key: '操作' }
	]
	const SiteOptions = []

	const { tableData, onSearch, handlePageChange, pagination, Search, onReset, SearchFormDel } = listPagination(
		{ name: '' },
		business.EmPersonInfo
	)

	const handleInput = async (row) => {}

	//
	const DEl = async (row) => {
		const res = await business.EmPersonInfoDelete([{ id: row.id }])
		onSearch()
		console.log(res)
	}
	// 查看表单数据
	const onView = (record, row) => {
		switch (record) {
			case 'add':
				router.push('/business/personnelDel?add')
				break
			case 'del':
				DEl(row)
				break
			case 'chenk':
				router.push(`/business/personnelDel?code=${true}&id=${row.id}`)
				break
			case 'edit':
				router.push(`/business/personnelDel?code=1&id=${row.id}`)
				break
			default:
				// router.push('/business/personnelDel')
				break
		}
	}

	function onViewRow() {
		// router.push('/basic.info/pricemoitorrecordDetail')
	}

	const handleExpand = (expanded, record) => {
		// 处理展开分页的逻辑
		// 可以根据 record 的信息进行展开分页的操作
		// 例如根据 record 的 ID 获取分页数据等
		// 更新分页数据
		record.paginationData = [] // 假设 record.paginationData 是用于存储分页数据的属性
	}
</script>
<style lang="less" scoped>
	.search {
		padding-top: 20px;
		padding-left: 50px;
		margin-bottom: 32px;
		.btnBox {
			display: inline-block;
			width: 400px;
			display: flex;
			justify-content: space-around;
			align-items: center;
		}
	}
	.silt-title {
		display: flex;
	}
</style>
