<template>
	<el-dialog v-model="state.dialogVisible" draggable title="短信明细" @close="close" destroy-on-close append-to-body>
		<el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
			<el-form-item label="市民姓名" prop="PhoneNumber">
				<el-input v-model="state.queryParams.PhoneNumber" placeholder="请填写市民姓名" clearable @keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="联系电话" prop="Name">
				<el-input v-model="state.queryParams.Name" 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"
			show-overflow
			:scrollY="{ enabled: true, gt: 100 }"
			max-height="500px"
		>
			<vxe-column field="name" title="市民姓名"></vxe-column>
			<vxe-column field="phoneNum" title="联系电话"></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">
import { defineAsyncComponent, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { smartCallOutSmsDetailQuery } from '@/api/auxiliary/smartCallOut';

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

// 定义变量内容
const state = reactive<any>({
	dialogVisible: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 10,
		PhoneNumber: null,
		Name: null,
	},
	total:0,
	tableData: [],
});

const ruleFormRef = ref<RefType>(null); // 表单ref
/** 搜索按钮操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取列表
const queryList = () => {
	state.loading = true;
	smartCallOutSmsDetailQuery(state.queryParams)
		.then((res) => {
			state.loading = false;
			state.tableData = res.result.items ?? [];
			state.total = res.result.total ?? 0;
		})
		.finally(() => {
			state.loading = false;
		});
};
// 重置表单
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
};
// 打开弹窗
const openDialog = async (row: any) => {
	try {
		state.dialogVisible = true;
		state.queryParams.id = row.id;
		queryList();
	} catch (error) {
		console.log(error);
	}
};
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
const close = () => {
	ruleFormRef.value?.resetFields();
	ruleFormRef.value?.resetFields();
};
// 暴露变量
defineExpose({
	openDialog,
	closeDialog,
});
</script>
