<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 style="width: 220px" v-model:value="SearchFormDel.systemName" 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('view', 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>
	<Form ref="formRef" @successful="tableRef.refresh()" @change="change" />
</template>
<script setup>
	import business from '@/api/business/personnelApi'
	import { listPagination } from '@/hook/listlistPagination.js'
	import Form from './form.vue'

	import { reactive, ref } from 'vue'
	import { useRouter } from 'vue-router'
	import { defineComponent } from 'vue'
	const formRef = ref(null)
	const router = useRouter()
	const tableColumns = [
		{
			title: '序号',
			dataIndex: 'Index',
			align: 'center',
			customRender: ({ text, record, index }) => {
				return `${index + 1}`
			}
		},
		{ title: '制度名称', dataIndex: 'systemName' },
		{ title: '发布内容', dataIndex: 'publishContent' },
		{ title: '发布时间', dataIndex: 'publishTime' },
		{ title: '操作', key: '操作' }
	]
	const change = () => {
		onSearch()
	}

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

	const DEl = async (v) => {
		const res = await business.enterpriseManagementDEl([{ id: v.id }])
		onSearch()
	}

	// 查看表单数据
	const onView = (record, row) => {
		switch (record) {
			case 'add':
				formRef.value.onOpen(record, true, false)
				break
			case 'del':
				DEl(row)
				break
			case 'view':
				formRef.value.onOpen(record, true, true, row)
				break
			case 'edit':
				formRef.value.onOpen(record, true, false, row)
				break
			default:
				// router.push('/business/personnelDel')
				break
		}
	}
</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>
