<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.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>
				</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.dataIndex === 'auditStatus'">
						<div v-if="record.auditStatus == 0">待审核</div>
						<div v-if="record.auditStatus == 1">已审核</div>
						<div v-if="record.auditStatus == 2">驳回</div>
					</template>

					<template v-if="column.key === '操作'">
						<a-button type="link" @click="onView('view', record)">查看</a-button>
						<a-button v-if="record.status == 1" type="link" @click="onView('edit', record)">审批</a-button>
					</template>
				</template>
			</a-table>
		</div>
	</div>
</template>
<script setup>
	import business from '@/api/business/personnelApi'
	import { listPagination } from '@/hook/listlistPagination.js'
	import { reactive, ref } from 'vue'
	import { useRouter, useRoute } from 'vue-router'
	import { defineComponent } from 'vue'
	const router = useRouter()
	const route = useRoute()

	watch(
		() => route,
		(newVal) => {
			if (newVal.fullPath == '/business/approval') {
				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: 'age' },
		{ title: '联系方式', dataIndex: 'contact' },
		{ title: '规划方向', dataIndex: 'plan_direction' },
		{ title: '状态', dataIndex: 'auditStatus' },
		{ title: '操作', key: '操作' }
	]
	const { tableData, onSearch, handlePageChange, pagination, Search, onReset, SearchFormDel } = listPagination(
		{ name: '' },
		business.RCGHlist,
		{},
		{ type: 2 },
		'1'
	)

	const DEl = async (v) => {
		const res = await business.RCGHdel([
			{
				personInfoId: v.personInfoId,
				planId: v.planId
			}
		])
		onSearch()
	}

	const application = async (v) => {
		const res = await business.RCGHstartFlow({
			personInfoId: v.personInfoId,
			planId: v.planId
		})
		onSearch()
	}

	// 查看表单数据
	const onView = (record, row) => {
		switch (record) {
			case 'add':
				router.push('/business/approvalDel')
				break
			case 'del':
				DEl(row)
				break
			case 'view':
				router.push(
					`/business/approvalDel?codeSSC=${true}&personInfoId=${row.personInfoId}&planId=${row.planId}&requestId=${row.requestId}`
				)
				break
			case 'edit':
				router.push(`/business/approvalDel?codeSSC=1&personInfoId=${row.personInfoId}&planId=${row.planId}`)
				break
			case 'application':
				application(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>
