<template>
	<a-card :bordered="false">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>
			<template #operator class="table-operator">
				<a-row :gutter="24">
					<a-col :span="6">
						<a-form-item label="名称关键词">
							<a-input placeholder="请输入岗位名称关键词" />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-form-item label="所属行政部门">
							<a-select
								class="select-box"
								v-model:value="objArr.orgName"
								:size="size"
								style="width: 200px"
								placeholder="请选择"
							>
								<a-select-option v-for="item in auditStatus" :key="item.id" :value="item.id"
									>{{ item.name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-button type="primary" @click="tableRef.refresh(true)">
							<template #icon><SearchOutlined /></template>
							查询
						</a-button>
						<a-button class="snowy-buttom-left" @click="reset">
							<template #icon><redo-outlined /></template>
							重置
						</a-button>
						<a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('priceMonitorAdd')">
							<template #icon><plus-outlined /></template>
							新增
						</a-button>
					</a-col>
				</a-row>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="onView(record)">查看</a>
						<a @click="formRef.onOpen(record)" v-if="hasPerm('priceMonitorEdit')">编辑</a>
						<a-divider type="vertical" v-if="hasPerm(['priceMonitorEdit', 'priceMonitorDelete'], 'and')" />
						<a-popconfirm title="确定要删除吗？" @confirm="deletePriceMonitor(record)">
							<a-button type="link" danger size="small" v-if="hasPerm('priceMonitorDelete')">删除</a-button>
						</a-popconfirm>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh()" />
</template>

<script setup name="pricemonitor">
	import { cloneDeep } from 'lodash-es'
	import Form from './form.vue'
	// import queryData from './queryData.vue'
	import priceMonitorApi from '@/api/basic.info/priceMonitorApi'
	import unReporCityApi from '@/api/basic.info/unReporCityApi.js'

	const tableRef = ref()
	const formRef = ref()
	const searchFormRef = ref()
	const auditStatus = ref([])
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '监测点名称',
			dataIndex: 'name'
		},
		{
			title: '所属行政管理部门',
			dataIndex: 'orgName'
		},
		{
			title: '详细位置',
			dataIndex: 'address'
		}
	]
	const objArr = ref({
		orgName: '',
		name: ''
	})
	onMounted(() => {
		getSearchData()
	})
	// 市州下拉框数据
	const getSearchData = () => {
		unReporCityApi.unReporCityquery().then((res) => {
			auditStatus.value = res
		})
	}
	// 操作栏通过权限判断是否显示
	if (hasPerm(['priceMonitorEdit', 'priceMonitorDelete'])) {
		columns.push({
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: 250
		})
	}
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	const loadData = (parameter) => {
		return priceMonitorApi.priceMonitorPage(parameter).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		objArr.value = {
			orgName: '',
			name: ''
		}
		input.value = ''
	}
	// 删除
	const deletePriceMonitor = (record) => {
		let params = [
			{
				id: record.id
			}
		]
		priceMonitorApi.priceMonitorDelete(params).then(() => {
			tableRef.value.refresh(true)
		})
	}
	console.log(deletePriceMonitor, 5215)
	// 查看表单数据
	const onView = (record) => {
		console.log(formRef.value)
		formRef.value.onOpen(record, true)
	}
</script>
