<template>
	<div class="snapshot-publish-audit-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-grid v-bind="gridOptions" ref="gridRef">
				<template #form>
					<el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent :disabled="gridOptions.loading">
						<el-form-item label="审批状态" prop="Status">
							<el-radio-group v-model="state.queryParams.Status" @change="handleQuery">
								<el-radio :value="0">审批中</el-radio>
								<el-radio :value="1">同意</el-radio>
								<el-radio :value="2">不同意</el-radio>
								<el-radio :value="-1">全部</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
							<el-button @click="resetQuery(ruleFormRef)" class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
						</el-form-item>
					</el-form>
				</template>
				<template #action="{ row }">
					<el-button type="primary" @click="onView(row)" v-auth="'snapshot:publish:audit:audit'" link> 查看 </el-button>
				</template>
				<template #order_detail="{ row }">
					<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
				</template>
				<template #pager>
					<pagination
						@pagination="queryList"
						:total="state.total"
						v-model:current-page="state.queryParams.PageIndex"
						v-model:page-size="state.queryParams.PageSize"
						:disabled="state.loading"
					/>
				</template>
			</vxe-grid>
		</div>
		<!-- 审批 -->
		<publish-audit ref="publishAuditRef" @updateList="queryList" />
	</div>
</template>

<script lang="tsx" setup name="snapshotPublishAudit">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import Other from '@/utils/other';
import { centerPublishUserList } from '@/api/snapshot/publish';

// 引入组件
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情
const PublishAudit = defineAsyncComponent(() => import('@/views/snapshot/publish/components/Publish-audit.vue')); // 审批

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		Status: 0, // 默认 审批中
		No: null, // 工单编码
		Title: null, // 工单标题
	},
	total: 0, // 总条数
});

const gridOptions = reactive<any>({
	loading: false,
	border: true,
	showOverflow: true,
	columnConfig: {
		resizable: true,
	},
	scrollY: {
		enabled: true,
		gt: 100,
	},
	toolbarConfig: {
		zoom: true,
		custom: true,
		refresh: {
			queryMethod: () => {
				handleQuery();
			},
		},
	},
	customConfig: {
		storage: true,
	},
	id: 'snapshotReSendList',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'statusTxt',
			title: '审批状态',
			width: 120,
		},
		{
			field: 'no',
			title: '工单编码',
			width: 140,
		},
		{
			field: 'title',
			title: '原标题',
			slots: { default: 'order_detail' },
			minWidth: 300,
		},
		{
			field: 'creatorName',
			title: '申请人',
			width: 120,
		},
		{
			field: 'creationTime',
			title: '申请时间',
			formatter: 'formatDate',
			width: 160,
		},
		{
			field: 'arrangeTitle',
			title: '公开标题',
			minWidth: 300,
		},
		{
			field: 'address',
			title: '公开地址',
			width: 150,
		},
		{
			field: 'arrangeContent',
			title: '公开内容',
			minWidth: 300,
		},
		{
			field: 'arrangeOpinion',
			title: '公开办理信息',
			minWidth: 300,
		},
		{ title: '操作', width: 90, fixed: 'right', showOverflow: false, align: 'center', slots: { default: 'action' } },
	],
	data: [],
});
/** 搜索按钮操作 节流操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取列表
const requestParams = ref<EmptyObjectType>({});
const queryList = () => {
	state.loading = true;
	gridOptions.loading = true;
	requestParams.value = Other.deepClone(state.queryParams);
	centerPublishUserList(requestParams.value)
		.then((res) => {
			state.loading = false;
			gridOptions.data = res.result.items ?? [];
			state.total = res.result.total ?? 0;
			gridOptions.loading = false;
		})
		.finally(() => {
			state.loading = false;
			gridOptions.loading = false;
		});
};
// 重置表单
const ruleFormRef = ref<any>(null); // 表单ref
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	ruleFormRef.value?.resetFields();
	queryList();
};

// 添加标注
const publishAuditRef = ref<RefType>();
const onView = (row: any) => {
	publishAuditRef.value.openDialog(row);
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>

layout/routerView/parer
