<template>
	<div class="statistics-department-handle-container layout-pd">
		<!-- 搜索  -->
		<el-card shadow="never">
			<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
				<el-form-item label="部门名称" prop="Keyword">
					<el-input v-model="state.queryParams.Keyword" placeholder="部门名称" clearable @keyup.enter="queryList" class="keyword-input" />
				</el-form-item>
				<el-form-item label="时间段" prop="crTime">
					<el-date-picker
						v-model="state.queryParams.crTime"
						type="datetimerange"
						unlink-panels
						range-separator="至"
						start-placeholder="开始时间"
						end-placeholder="结束时间"
						:shortcuts="shortcuts"
						@change="queryList"
						value-format="YYYY-MM-DD[T]HH:mm:ss"
					/>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="queryList" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
					<el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading">
						<SvgIcon name="ele-Refresh" class="mr5" />重置
					</el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card shadow="never">
			<ProTable
				ref="proTableRef"
				:pagination="false"
				:columns="columns"
				:data="state.tableData"
				@updateTable="queryList"
				@updateColSetting="updateColSetting"
        :loading="state.loading"
			>
			</ProTable>
		</el-card>
	</div>
</template>
<script setup lang="tsx" name="statisticsDepartmentHandle">
import { onMounted, reactive, ref } from 'vue';
import { ElButton, FormInstance } from 'element-plus';
import { throttle } from '@/utils/tools';
import { departmentAcceptType } from '@/api/statistics/department';
import { shortcuts } from '@/utils/constants';
import dayjs from 'dayjs';

// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
// ProTable 实例
const proTableRef = ref<RefType>();

// 表格配置项
const columns = reactive<any[]>([
	{ type: 'selection', fixed: 'left', width: 55 },
	{ prop: 'orgName', label: '部门名称', align: 'center' },
	{ prop: 'orgType', label: '部门类别', align: 'center' },
	{ prop: 'd', label: '信件总数' , align: 'center'},
	{
		prop: 'f',
		label: '办件信息',
   align: 'center',
		_children: [
			{ prop: 'a', label: '已办案件', align: 'center' },
			{ prop: 'b', label: '在办案件', align: 'center' },
			{ prop: 'c', label: '办结率', align: 'center' },
		],
	},
]);
// 列设置获取
const updateColSetting = (colSetting: any, colArr) => {
	console.log(colSetting, colArr);
};
const state = reactive({
	queryParams: {
		// 查询条件
		TypeCode: '0', // 关键词
		crTime: [dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'), dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')], // 时间默认今天开始到今天结束
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
/** 获取列表 */
const queryList = throttle(() => {
	state.loading = true;
	let StartDate = null;
	let EndDate = null;
	if (state.queryParams?.crTime) {
		StartDate = state.queryParams?.crTime[0];
		EndDate = state.queryParams?.crTime[1];
	}
	const request = {
		StartDate,
		EndDate,
		TypeCode: state.queryParams.TypeCode,
	};
	departmentAcceptType(request)
		.then((res: any) => {
			state.tableData = res.result ?? [];
			state.total = res.result?.total ?? 0;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
}, 300);
// 排序
/** 重置按钮操作 */
const resetQuery = throttle((formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
}, 300);
onMounted(() => {
	queryList();
});
</script>
