<script setup name="qualityDataInput">
	import Details from './qualityDataInputEdit.vue'
	import { getList, remove } from '@/api/grainQualityManagement/qualityDataInput'
	import { globalStore } from '@/store'
	import { message } from 'ant-design-vue'

	const columns = [
		{
			title: '序号',
			customRender: ({ text, record, index }) => `${index + 1}`
		},
		{
			title: '库区名称',
			dataIndex: 'orgName'
		},
		{
			title: '仓房名称',
			dataIndex: 'storeHouseName'
		},
		{
			title: '货位名称',
			dataIndex: 'warehouseName'
		},
		{
			title: '品种',
			dataIndex: 'grainVarietyName'
		},
		{
			title: '性质',
			dataIndex: 'grainNatureName'
		},
		{
			title: '检验时间',
			dataIndex: 'jysj'
		},
		...(hasPerm(['fumigationFilingApprovalView', 'doFumigationFilingApproval'])
			? [
					{
						title: '操作',
						dataIndex: 'action',
						align: 'center',
						width: 250
					}
			  ]
			: [])
	]
	const loadData = (parameter) => {
		return getList({ ...parameter, ...searchForm.value })
	}
	const addShow = ref(false)

	const openForm = () => {
		addShow.value = true
	}
	const editData = ref(null)
	const action = ref(null)
	const view = (data) => {
		action.value = 'view'
		editData.value = data
		addShow.value = true
	}

	const tableRef = ref()
	const refresh = () => {
		tableRef.value.refresh()
	}
	const searchForm = ref({
		storehouseName: null
	})
	const formRef = ref()
	const search = () => {
		refresh()
	}
	const reset = () => {
		formRef.value.resetFields()
	}
	const add = () => {
		action.value = 'add'
		addShow.value = true
	}
	const edit = (data) => {
		action.value = 'edit'
		editData.value = data
		addShow.value = true
	}
	const del = (data) => {
		console.log('rrrr', data)
		remove(data.id).then((resp) => {
			message.success('删除成功')
			refresh()
		})
	}
</script>

<template>
	<a-card :bordered="false">
		<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :row-key="(record) => record.id">
			<template #operator class="table-operator">
				<a-space>
					<a-form ref="formRef" :model="searchForm" layout="inline">
						<a-form-item label="仓房名称" name="storehouseName">
							<a-input v-model:value="searchForm.storehouseName" />
						</a-form-item>
					</a-form>

					<a-button type="primary" @click="search">
						<template #icon><plus-outlined /></template>
						查询
					</a-button>
					<a-button @click="reset">
						<template #icon><plus-outlined /></template>
						重置
					</a-button>
					<a-button @click="add">
						<template #icon><plus-outlined /></template>
						新增
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="view(record)" v-if="hasPerm('fumigationFilingApprovalView')">查看</a>
						<a-divider
							type="vertical"
							v-if="hasPerm(['fumigationFilingApprovalView', 'doFumigationFilingApproval'], 'and')"
						/>
						<a @click="edit(record)" v-if="hasPerm('doFumigationFilingApproval')">编辑</a>
						<a-divider
							type="vertical"
							v-if="hasPerm(['fumigationFilingApprovalView', 'doFumigationFilingApproval'], 'and')"
						/>
						<a-popconfirm title="确认删除?" ok-text="Yes" cancel-text="No" @confirm="del(record)">
							<a href="#" v-if="hasPerm('doFumigationFilingApproval')">删除</a>
						</a-popconfirm>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Details v-model:visible="addShow" :edit-data="editData" :action="action" @on-save="refresh()" />
	<!--	<Form v-model:visible="addShow" :edit-data="editData" :action="action" @on-approve="refresh"/>-->
</template>

<style scoped></style>
