<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="username" placeholder="请输入" /> -->
					<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>
					<!-- <a-button style="margin-right: 4px" type="primary" class="primarySele" @click="options">
						生成制定轮换计划
					</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>
					</template>
				</template>
			</a-table>

			<a-modal v-model:visible="AddEditDialog.open" :title="AddEditDialog.title" @ok="onDialogOk" width="800px">
				<div class="acc_del">
					<a-form-item class="form-item acc_del" label="选择年度生成制定换轮计划" :label-col="{ span: 10 }">
						<a-date-picker style="width: 250px" v-model:value="rotationYear" picker="year" valueFormat="YYYY" />
					</a-form-item>
				</div>
			</a-modal>
		</div>
	</div>
</template>
<script setup>
	import { listPaginationBAQDE } from '@/hook/listlistPagination.js'
	import { onMounted } from 'vue'
	import { reactive, ref } from 'vue'
	import { defineComponent } from 'vue'
	import business from '@/api/basic.info/rotationprogramApi.js'
	import { useRouter, useRoute } from 'vue-router'
	const selectedYear = ref('')
	const AddEditDialog = ref({
		open: false,
		title: '生成制定轮换计划'
	})
	const onDialogOk = async () => {
		AddEditDialog.value.open = false
		console.log(223, selectedYear.value)
		await onSearch({ rotationYear: selectedYear.value })
		router.push(`/rotation/rotationSchedule?code=${2}&rotationYear=${selectedYear.value}`)
	}
	const options = () => {
		selectedYear.value = ''
		AddEditDialog.value.open = true
	}

	const tableColumns = ref([
		// { title: '小麦轮出合计', dataIndex: 'dataIndex1' },
		// { title: '大米轮出合计', dataIndex: 'dataIndex4' },
		// { title: '小麦粉轮出合计', dataIndex: 'dataIndex3' },
		// { title: '编制日期', dataIndex: 'dataIndex3' }
		// { title: '操作', key: '操作' }
	])
	const tableTitle = ref([
		{
			title: '序号',
			dataIndex: 'Index',
			align: 'center',
			customRender: ({ text, record, index }) => {
				return `${index + 1}`
			}
		},
		{ title: '标题', align: 'center', dataIndex: 'name' },
		{ title: '轮换年度', align: 'center', dataIndex: 'rotationYear' }
	])
	const tableData = ref([])
	const router = useRouter()
	const route = useRoute()
	onMounted(() => {
		onSearch({ rotationYear: '2022' })
	})
	const username = ref('')
	const onSearch = async (T) => {
		const { businessRpReportVO, list } = await business.zDlist({ current: 1, size: 5, ...T })
		tableColumns.value = []
		tableData.value = []
		await tableTitle.value.forEach((v) => {
			return tableColumns.value.push(v)
		})
		await list.forEach((v) => {
			return tableColumns.value.push(v)
		})
		tableColumns.value.push({ title: '操作', align: 'center', key: '操作' })
		tableData.value = businessRpReportVO
		// console.log(tableData.value)
	}
	const { onReset, handlePageChange, pagination, Search, SearchFormDel } = listPaginationBAQDE(onSearch, {
		rotationYear: '2022'
	})

	// 查看表单数据
	const onView = (record, row) => {
		switch (record) {
			case 'add':
				router.push('/business/personnelDel?add')
				break
			case 'del':
				DEl(row)
				break
			case 'chenk':
				router.push(`/rotation/rotationSchedule?code=${2}&rotationYear=${row.rotationYear.slice(0, 4)}`)
				break
			case 'edit':
				router.push(`/business/personnelDel?code=1&id=${row.id}`)
				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: 350px;
			display: flex;
			justify-content: space-around;
			align-items: center;
		}
	}
	.silt-title {
		display: flex;
		span {
			text-align: right;
		}
	}
	.acc_del {
		margin-bottom: 0px;
	}
</style>
