<template>
	<el-dialog v-model="state.dialogVisible" draggable title="查看标签记录" ref="dialogRef" width="60%" append-to-body>
		<el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
			<el-form-item label="市民标签" prop="Label">
				<el-input v-model="state.queryParams.Label" placeholder="市民标签" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="记录人" prop="CreatorName">
				<el-input v-model="state.queryParams.CreatorName" placeholder="记录人名称" clearable @keyup.enter="handleQuery" />
			</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>
		<vxe-table
			border
			:loading="state.loading"
			:data="state.tableData"
			:column-config="{ resizable: true }"
			:row-config="{ isCurrent: true, isHover: true, height: 30, useKey:true }"
			ref="tableRef"
			:scrollY="{ enabled: true, gt: 100 }"
			show-overflow
			max-height="500px"
		>
			<vxe-column field="label" title="市民标签"></vxe-column>
			<vxe-column field="phone" title="电话"></vxe-column>
			<vxe-column field="creatorName" title="记录人"></vxe-column>
			<vxe-column field="creationTime" title="创建时间" width="160">
				<template #default="{ row }">
					{{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
				</template>
			</vxe-column>
		</vxe-table>
		<pagination
			@pagination="queryList"
			:total="state.total"
			v-model:current-page="state.queryParams.PageIndex"
			v-model:page-size="state.queryParams.PageSize"
			:disabled="state.loading"
		/>
	</el-dialog>
</template>

<script setup lang="tsx" name="businessCitizenTagsRecord">
import { defineAsyncComponent, reactive, ref } from 'vue';
import type { FormInstance } from 'element-plus';
import { citizenLabelList } from '@/api/auxiliary/citizen';
import { formatDate } from '@/utils/formatTime';


const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页

// 定义变量内容
const state = reactive({
	dialogVisible: false, // 弹窗显示隐藏
	queryParams: {
		PageIndex: 1, // 当前页
		PageSize: 10, // 每页条数
		Keyword: null, // 关键字
	},
	tableData: [], // 表格数据
	total: 0, // 总条数
	loading: false, // 加载状态
	citizen: {}, //市民信息
});
const ruleFormRef = ref<RefType>(); // 表单ref
// 打开弹窗
const openDialog = (row: any) => {
	state.citizen = row;
	queryList();
	state.dialogVisible = true;
};
const dialogRef = ref<RefType>();
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
/** 搜索按钮操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	handleQuery();
};
/** 获取历史工单 */
const queryList = () => {
	state.loading = true;
	let request = {
		...state.queryParams,
		CitizenId: state.citizen.id,
	};
	citizenLabelList(request)
		.then((response: any) => {
			state.tableData = response?.result.items ?? [];
			state.total = response?.result.total;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
// 暴露变量
defineExpose({
	openDialog,
	closeDialog,
});
</script>
