<template>
	<div>
		<a-space class="header">
			<div class="input-box">
				<div class="silt-title">
					<span style="width: 70px; margin-right: 12px; display: block">{{ '站点名称' }}</span>
					<a-input @input="handleInput" style="width: 220px" v-model:value="pagination.username" placeholder="请输入" />
				</div>
				<div class="input-box-sle">
					<span class="title-box">{{ '审核状态' }}</span>
					<a-select
						class="select-box"
						v-model:value="status"
						:size="size"
						style="width: 200px"
						@change="handleMenuClick"
						placeholder="请选择"
					>
						<a-select-option v-for="(item, i) in statusArray" :key="item.key"> {{ item.name }} </a-select-option>
					</a-select>
				</div>
			</div>
			<div class="btnBox">
				<a-button style="margin-right: 16px" @click="searchData">查询</a-button>
				<a-button @click="reset">重置</a-button>
			</div>
		</a-space>
		<a-table :dataSource="dataSource" :row-key="(record) => record.key" :pagination="false" :columns="columns">
			<template #bodyCell="{ column, record }">
				<template v-if="column.key === 'action'">
					<span>
						<template v-for="item in CZBtnOptions">
							<a-button
								:key="item.label"
								:class="item.className"
								@click="item.fn(record)"
								v-if="item.state == null || item.state.includes(record.status)"
								>{{ item.label }}</a-button
							></template
						>
					</span>
				</template>
			</template>
		</a-table>
		<a-modal
			v-model:visible="SHDialogOption.open"
			:title="SHDialogOption.title"
			:closable="false"
			:maskClosable="false"
			@cancel="cancelSHDialog"
			@ok="okSHDialog"
		>
			<a-input type="textarea" v-model:value="SHDialogOption.form.msg"></a-input>
		</a-modal>
		<a-pagination
			@change="onChange"
			size="small"
			:total="pagination.total"
			:show-total="(total) => `共 ${pagination.total} 条`"
		/>
		<!-- 抽屉开关 -->
		<a-drawer
			:visible="visible"
			:closable="false"
			width="1000px"
			placement="right"
			@close="handleClose"
			class="custom-class"
			root-class-name="root-class-name"
			:root-style="{ color: 'blue' }"
			:title="titleData"
		>
			<!-- 查看抽屉 -->
			<Form v-if="showData" :detailsData="detailData" />
			<!--编辑抽屉  -->
			<draft v-if="showEdit" @getClose="getClose" :detailsData="detailData" />
		</a-drawer>
	</div>
</template>
<script setup name="bizGrainPriceCollect">
	import Form from './querySee.vue'
	import draft from './draft.vue'
	import { ref } from 'vue'
	import bizGrainPriceCollectApi from '@/api/basic.info/bizGrainPriceCollectApi'

	const status = ref(null)

	const pagination = ref({
		// 分页配置
		pageSize: 10, // 每页显示的条数
		showSizeChanger: true, // 是否可以改变每页显示的条数
		showQuickJumper: true, // 是否可以快速跳转到指定页
		current: 1, // 当前页数
		total: null, // 总条数
		username: ''
	})
	const SHDialogOption = reactive({
		open: false,
		row: undefined,
		title: '',
		status: '',
		form: {}
	})
	const CZBtnOptions = [
		{
			label: '查看',
			className: 'check',
			state: null,
			fn: (row) => check(row)
		},
		{ label: '编辑', className: 'edit', state: ['待审核', '驳回'], fn: (row) => edit(row) },
		{ label: '驳回', className: 'delete', state: ['驳回', '编辑'], fn: (row) => deleteData(row) },
		{ label: '审核', className: 'audit', state: ['待审核', '驳回', '编辑'], fn: (row) => audit(row) }
	]
	const detailData = ref({})
	const titleData = ref('')
	// 抽屉是否打开
	const visible = ref(false)
	const showData = ref(false) //查看抽屉
	const showEdit = ref(false) //编辑抽屉
	const constid = ref([''])

	// 列表数据
	const dataSource = ref([])
	const statusArray = ref([
		{
			key: 0,
			name: '待审核'
		},
		{
			key: 1,
			name: '已审核'
		},
		{
			key: 2,
			name: '驳回'
		}
	]) // 下拉框数据
	const columns = ref([
		{
			title: '序号',
			dataIndex: 'Index',
			align: 'center',
			customRender: ({ text, record, index }) => {
				return `${index + 1}`
			}
		},
		{
			title: '监测点名称',
			dataIndex: 'monitorName',
			align: 'center',
			key: 'monitorName'
		},
		{
			title: '价格采集人',
			dataIndex: 'userCollectName',
			align: 'center',
			key: 'userCollectName'
		},
		{
			title: '所属州市',
			dataIndex: 'orgName',
			align: 'center',
			key: 'orgName'
		},
		{
			title: '采集时间',
			dataIndex: 'userCollectTime',
			align: 'center',
			key: 'userCollectTime'
		},
		{
			title: '审核状态',
			dataIndex: 'status',
			align: 'center',
			key: 'status'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			key: 'action'
		}
	])

	// 审核状态修改
	const handleMenuClick = (value) => {
		status.value = value
		// console.log(status.value, 12345)
	}

	// 抽屉关闭事件
	const handleClose = () => {
		visible.value = false
	}
	// 子组件的自定义方法
	function getClose(item) {
		console.log(item, 'hhhhhh')
		visible.value = item
		handleClose()
	}

	//查询
	const searchData = () => {
		getListData()
	}

	// 重置输入框
	const reset = () => {
		pagination.value.username = ''
		status.value = null
		getListData()
	}
	// 列表数据
	const getListData = () => {
		dataSource.value = []
		console.log(pagination.value.username, ' pagination.value.username')
		const params = ref({
			current: pagination.value.current, //当前页码
			isApp: 0, //是否移动端
			monitorName: pagination.value.username, //监测点名称
			size: pagination.value.pageSize, //每页条数
			status: status.value //审核状态
		})
		bizGrainPriceCollectApi.bizGrainPriceCollectPage(params.value).then((res) => {
			console.log(res, 'res')
			pagination.value.total = res.total
			dataSource.value = res.records.map((i) => {
				return {
					...i,
					status: i.status === 0 ? '待审核' : i.status === 1 ? '已审核' : '驳回'
				}
			})
		})
		// bizGrainPriceCollectApi.findPage
	}
	// 分页
	const onChange = (page, pageSize) => {
		pagination.value.current = page
		getListData()
	}
	//列表操作栏方法实现

	// 查看
	const check = (val) => {
		console.log('detailData.value', val)
		detailData.value = val
		titleData.value = '粮食价格采集查看'
		showEdit.value = false
		showData.value = true
		visible.value = true
	}
	// 编辑
	const edit = (val) => {
		detailData.value = val
		titleData.value = '粮食价格采集编辑'
		showData.value = false
		showEdit.value = true
		visible.value = true
	}
	// 驳回
	const deleteData = (res) => {
		console.log(res, 11)
	}
	// 审核
	const audit = (val) => {
		console.log(val, '审核')
		SHDialogOption.open = true
		SHDialogOption.row = val
		SHDialogOption.title = '审核'
	}
	//弹出框
	const cancelSHDialog = () => {
		SHDialogOption.open = false
		const params = ref({
			type: '1',
			id: SHDialogOption.row.id,
			auditStatus: '2',
			auditRejectAdvice: SHDialogOption.form.msg
		})
		console.log(SHDialogOption.form, 'uuuuuuuu')
		SHDialogOption.open = false
		const fd = SHDialogOption.form.msg //意见
		const id = SHDialogOption.row.id //数据ID
		const Status = SHDialogOption.row.Status //状态
		SHDialogOption.form = { msg: '' }
		SHDialogOption.row = undefined

		bizGrainPriceCollectApi.bizGrainPriceCollectAudit(params.value).then((res) => {
			console.log(res, 'aaaa')
		})
		// ajax
	}
	//点击确认返回数据
	const okSHDialog = (val) => {
		const params = ref({
			type: '1',
			id: SHDialogOption.row.id,
			auditStatus: '1',
			auditRejectAdvice: SHDialogOption.form.msg
		})
		console.log(SHDialogOption.form, 'uuuuuuuu')
		SHDialogOption.open = false
		const fd = SHDialogOption.form.msg //意见
		const id = SHDialogOption.row.id //数据ID
		const Status = SHDialogOption.row.Status //状态
		SHDialogOption.form = { msg: '' }
		SHDialogOption.row = undefined
		console.log(params.value, 'yyyyyyy')
		bizGrainPriceCollectApi.bizGrainPriceCollectAudit(params.value).then((res) => {
			console.log(res, 'aaaa')
		})

		// ajax
	}

	onMounted(() => {
		getListData()
	})
</script>
<style scoped>
	.header {
		display: flex;
		padding: 20px;
		width: 100%;
	}
	.input-box {
		display: flex;
		width: 100%;
	}
	.input-box-sle {
		width: 56%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 24px;
	}
	.title-box {
		margin-right: 12px;
	}
	.inputBoxContent {
		width: 400px;
	}
	.silt-title {
		width: 280px;
		display: flex;
		align-items: center;
		margin-right: 32px;
	}
	.btnBox {
		display: flex;
	}
	.ant-input-group-addon {
		border: 0;
	}
	.ant-input,
	.ant-btn {
		border-radius: 5px;
	}
	.ant-pagination {
		margin-top: 12px;
		float: right;
		margin-right: 16px;
	}
	.check {
		background-color: rgba(112, 125, 233);
		color: #fff;
	}
	.edit {
		background-color: rgba(222, 186, 80);
		color: #fff;
	}
	.delete {
		background-color: rgba(255, 70, 70);
		color: #fff;
	}
	.audit {
		background-color: rgba(83, 184, 36);
		color: #fff;
	}
	.ant-table-thead > tr > th {
		text-align: center;
	}
	.ant-table-tbody > tr > td {
		text-align: center;
	}
</style>
