<template>
	<div class="pricemoitorrecord">
		<a-card :bordered="false">
			<a-space class="search">
				<div class="silt-title" style="margin-right: 12px">
					<span style="text-align: right; width: 70px; margin-right: 0px; display: block; line-height: 30px">{{
						'企业名称 &nbsp; '
					}}</span>
					<a-input style="width: 220px" v-model:value="SearchFormDel.unitName" placeholder="请输入" />
				</div>
				<div class="silt-title" style="margin-right: 12px">
					<span style="width: 70px; margin-right: 0px; display: block; line-height: 30px">{{ '轮换年度&nbsp; ' }}</span>
					<a-date-picker
						style="width: 250px"
						v-model:value="SearchFormDel.rotationYear"
						picker="year"
						valueFormat="YYYY"
					/>
				</div>

				<div class="btnBox">
					<a-button style="margin-right: 4px" type="primary" class="primarySele" @click="Search"> 查询 </a-button>
					<a-button style="margin-right: 4px" 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 == 'rotationYear'">
						<div>{{ getDateDEl(rotationYear) }}</div>
					</template>
					<template v-if="column.key === '操作'">
						<a-button type="link" @click="onView('view', record)">查看</a-button>
					</template>
				</template>
			</a-table>
		</div>
	</div>
</template>
<script setup>
	import { getDate } from '@/utils/device'
	import business from '@/api/basic.info/rotationprogramApi.js'
	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()
	const tableColumns = [
		{
			title: '序号',
			dataIndex: 'Index',
			align: 'center',
			customRender: ({ text, record, index }) => {
				return `${index + 1}`
			}
		},
		{ title: '企业名称', dataIndex: 'dwmc' },
		{ title: '轮出数量合计', dataIndex: 'plan_quantity' },
		{ title: '轮入数量合计', dataIndex: 'quantity' },
		{ title: '轮换年度', dataIndex: 'rotationYear' },
		{ title: '上报时间', dataIndex: 'reportTime' },
		{ title: '操作', key: '操作' }
	]

	const { tableData, onSearch, handlePageChange, pagination, Search, onReset, SearchFormDel } = listPagination(
		{ unitName: '', rotationYear: '' },
		business.LHJHlist,
		{},
		{},
		'shut'
	)

	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/planningDel')
				break
			case 'del':
				DEl(row)
				break
			case 'view':
				router.push(`/rotation/planDetails?code=${true}&orgId=${row.orgId}&rpReportId=${row.id}`)
				break
			case 'edit':
				router.push(`/business/planningDel?code=1&personInfoId=${row.personInfoId}&planId=${row.planId}`)
				break
			case 'application':
				application(row)
				break
			default:
				// router.push('/business/personnelDel')
				break
		}
	}
	const getDateDEl = (v) => {
		const formattedDate = getDate('YYYY', v)
		return formattedDate
	}

	// 查看表单数据
	// const onView = (record) => {
	// 	// formRef.value.onOpen(record, true)
	// 	router.push('/rotation/planDetails?code=1')
	// }
</script>
<style lang="less" scoped>
	.search {
		padding-top: 20px;
		padding-left: 50px;
		margin-bottom: 32px;
		.btnBox {
			display: inline-block;
			width: 250px;
			display: flex;
			justify-content: space-around;
			align-items: center;
		}
	}
	.silt-title {
		display: flex;
		span {
			text-align: right;
		}
	}
</style>
