<template>
	<!--购销计划新增 -->
	<a-card :bordered="false">
		<div class="pricemoitorrecord">
			<a-form :model="formState" name="basic" autocomplete="off" @finish="onFinish" @finishFailed="onFinishFailed">
				<div class="form">
					<a-form-item
						class="form-item"
						label="计划名称"
						name="username"
						:label-col="{ span: 7 }"
						:rules="[{ required: true, message: 'Please input your username!' }]"
					>
						<a-input v-model:value="formState.username" />
					</a-form-item>
					<a-form-item
						class="form-item"
						label="接收库区"
						name="swls"
						:label-col="{ span: 7 }"
						:rules="[{ required: true, message: 'Please input your username!' }]"
					>
						<a-select v-model:value="formState.swls" @change="handleChange" :options="options"></a-select>
					</a-form-item>
					<a-form-item
						class="form-item"
						label="计划类型"
						name="swls"
						:label-col="{ span: 7 }"
						:rules="[{ required: true, message: 'Please input your username!' }]"
					>
						<a-select v-model:value="formState.swls" @change="handleChange" :options="options"></a-select>
					</a-form-item>

					<!--  -->
					<a-form-item
						class="form-item"
						label="计划开始时间"
						name="username"
						:label-col="{ span: 7 }"
						:rules="[{ required: true, message: 'Please input your username!' }]"
					>
						<a-input v-model:value="formState.username" />
					</a-form-item>
					<a-form-item
						class="form-item"
						label="计划结束时间"
						name="username"
						:label-col="{ span: 7 }"
						:rules="[{ required: true, message: 'Please input your username!' }]"
					>
						<a-input v-model:value="formState.username" />
					</a-form-item>
				</div>

				<div class="list">
					<div>轮换明细</div>
					<div>&nbsp;</div>
					<a-table :dataSource="tableData" :pagination="pagination" :columns="tableColumns">
						<!-- <template #bodyCell="{ column, record }">
						</template> -->
						<!-- 自定义分页器 -->
						<template #custom-row="{ current, pageSize }">
							<a-pagination
								:total="total"
								:current="current"
								:page-size="pageSize"
								show-size-changer
								:page-size-options="pageSizeOptions"
								show-total
								show-quick-jumper
								@change="handlePageChange"
							></a-pagination>
						</template>
					</a-table>
				</div>

				<a-form-item>
					<div class="item-submit">
						<a-button class="btn1" html-type="submit">保存</a-button>
						<a-button class="btn1" type="primary" html-type="submit">下发</a-button>
					</div>
				</a-form-item>
			</a-form>
		</div>
		<!-- <Form ref="formRef" @successful="tableRef.refresh()" /> -->
	</a-card>
</template>
<script lang="js">
	import { onMounted } from 'vue'
	// import Form from './form.vue'
	import { reactive, ref } from 'vue'
	import { useRouter } from 'vue-router'
	import { defineComponent } from 'vue'
	export default {
		name: 'ApplicationExtension',
		components: {},
		setup(props, { emit }) {
			const formRef = ref(null)
			onMounted(() => {
				onSearch()
			})
			const dataSource = ref([]) // 响应式表格数据
			const total = ref(0) // 总记录数
			const currentPage = ref(1) // 当前页码
			const pageSize = ref(10) // 每页显示的记录数
			const pageSizeOptions = ['1', '2', '30', '40'] // 每页显示记录数选项

			const handlePageChange = (current, size) => {
				// 更新当前页码和每页显示的记录数
				pagination.current = current
				pagination.pageSize = size
				// 根据新的页码和每页显示的记录数获取数据
			}
			const router = useRouter()
			const tableColumns = [
				{ title: '序号', key: 'INDEX' },
				{ title: '品种', dataIndex: 'dataIndex1' },
				{ title: '性质', dataIndex: 'dataIndex2' },
				{ title: '生产年限', dataIndex: 'dataIndex3' },
				{ title: '计划数量', dataIndex: 'dataIndex4' }
				// { title: '操作', key: '操作' }
			]
			const tableData = ref([
				{
					INDEX: 1,
					dataIndex1: '企业名称1',
					dataIndex2: '企业代码1',
					dataIndex3: '法定代表人1',
					dataIndex4: '企业性质1'
				},
				{
					INDEX: 2,
					dataIndex1: '企业名称2',
					dataIndex2: '企业代码2',
					dataIndex3: '法定代表人2',
					dataIndex4: '企业性质2'
				}
			])
			const SiteOptions = []
			const username = ref('')
			const SearchForm = reactive({
				siteName: ''
			})
			function onSearch() {
				// let fd = JSON.parse(JSON.stringify(SearchForm))
				// fd.current = tablePage.current
				// fd.size = tablePage.size
				// priceMoitorRecordApi.priceMoitorRecordPage(fd).then((reg) => {
				// 	console.log(reg.records, 123)
				// 	tableData.value = reg.records
				// 	tablePage.total = reg.total
				// })
			}
			function onReset() {
				SearchForm.siteName = ''
				tablePage.current = 1
				onSearch()
			}
			const handleInput = () => {}

			function onViewRow() {
				// router.push('/basic.info/pricemoitorrecordDetail')
			}
			function onChangePage(ev) {
				// Object.assign(tablePage, ev)
				onSearch()
			}

			const pagination = reactive({
				current: currentPage.value,
				pageSize: pageSize.value,
				total: total.value,
				showSizeChanger: true,
				pageSizeOptions: pageSizeOptions,
				showTotal: (total, range) => `共 ${total} 条`,
				onChange: handlePageChange
			})

			const handleExpand = (expanded, record) => {
				// 处理展开分页的逻辑
				// 可以根据 record 的信息进行展开分页的操作
				// 例如根据 record 的 ID 获取分页数据等
				// 更新分页数据
				record.paginationData = [] // 假设 record.paginationData 是用于存储分页数据的属性
			}

			// 查看表单数据
			const onView = (record) => {
				// formRef.value.onOpen(record, true)
				router.push('/basic.info/applicationQualificationNew')
			}
			const formState = reactive({
				username: '',
				swls: ''
			})
			const onFinish = (values) => {
				console.log('Success:', values)
			}
			const onFinishFailed = (errorInfo) => {
				console.log('Failed:', errorInfo)
			}

			const options = ref([
				{
					value: 1
				}
			])

			const handleChange = (val) => {
				console.log(val)
			}

			return {
				handleChange,
				formState,
				onFinish,
				onFinishFailed,
				pageSizeOptions,
				pageSize,
				currentPage,
				total,
				dataSource,
				handlePageChange,
				tableColumns,
				tableData,
				SiteOptions,
				username,
				SearchForm,
				onSearch,
				onViewRow,
				handleInput,
				onReset,
				formRef,
				onView,
				handleExpand,
				pagination,
				onChangePage,
				options
			}
		}
	}
</script>
<style lang="less" scoped>
	.search {
		padding-top: 20px;
		padding-left: 50px;
		margin-bottom: 32px;
		.btnBox {
			display: inline-block;
			width: 200px;
			display: flex;
			justify-content: space-around;
			align-items: center;
		}
	}
	.silt-title {
		display: flex;
	}
	.form {
		display: flex;
		flex-wrap: wrap;
		.form-item {
			width: 400px;
			margin-right: 20px;
		}
	}
	.item-submit {
		display: flex;
		justify-content: center;
		.btn1 {
			width: 100px;
			margin-right: 20px;
		}
	}
	.ant-select {
		width: 250px;
	}
	.ant-input {
		width: 250px;
	}
	.ant-form-item-label {
		width: 120px;
	}
</style>
