<template>
	<div class="statistics-center-aggregation-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
				<el-form-item prop="crTime">
					<statistical-time v-model="state.queryParams.crTime" @change="handleQuery" ref="statisticalTimeRef" :disabled="state.loading"/>
				</el-form-item>
				<el-form-item label="">
					<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" :loading="state.loading">
						<SvgIcon name="ele-Refresh" class="mr5" />重置
					</el-button>
					<el-popover :width="600" trigger="click">
						<template #reference>
							<el-button type="primary" title="口径说明"><SvgIcon name="ele-QuestionFilled" class="mr5"/>口径说明</el-button>
						</template>
						<el-descriptions title="" :column="1" border style="max-height: 400px; overflow: auto">
							<el-descriptions-item label="话务接通率">呼入话务接通数量 / 呼入话务总量 </el-descriptions-item>
							<el-descriptions-item label="话务数据匹配率">间范围内与电话工单匹配的话务数据量 / 时间范围内电话工单量。  </el-descriptions-item>
							<el-descriptions-item label="话务数据及时上传率"> 呼入及时上传话务数据量 / 呼入上传话务数据总量 </el-descriptions-item>
							<el-descriptions-item label="工单数据及时上传率"> 及时上传工单数据总量 / 上传工单数据总量 </el-descriptions-item>
							<el-descriptions-item label="受理量">  结转件 + 转办件（指各市（州）汇聚数据中，属于本月新增工单以及上一月及以前结转工单的数量。） </el-descriptions-item>
							<el-descriptions-item label="办结件数"> 指市（州）汇聚数据中，本月办结工单的数量。 </el-descriptions-item>
							<el-descriptions-item label="按时办结率">  按时办结工单数量 /（按时办结工单数量+超期办结工单数量+超期未办结工单数量） </el-descriptions-item>
							<el-descriptions-item label="回访量"> 市（州）回访工单总量：指市（州）汇聚数据中，本月回访工单的数量 </el-descriptions-item>
							<el-descriptions-item label="不满意件"> 时间范围内成功上传工单的满意度评价记录为“不满意”、“非常不满意”的工单件数 </el-descriptions-item>
							<el-descriptions-item label="知识库总量">  指各市（州）汇聚的知识库总量 </el-descriptions-item>
							<el-descriptions-item label="知识库更新数量"> 更新知识量 </el-descriptions-item>
						</el-descriptions>
					</el-popover>
				</el-form-item>
			</el-form>
			<vxe-toolbar
				ref="toolbarRef"
				:loading="state.loading"
				custom
				:refresh="{
					queryMethod: handleQuery,
				}"
			>
			</vxe-toolbar>
			<div style="overflow: hidden; width: 100%; height: 100%; flex: 1">
				<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"
					height="auto"
					auto-resize
					show-overflow
					:scrollY="{ enabled: true, gt: 100 }"
					id="statisticsCenterAggregation"
					:custom-config="{
						storage: true,
					}"
				>
					<vxe-column field="calConnectionRate" title="话务接通率">
						<template #default="scope">
							{{ scope.row.calConnectionRate }}%
						</template>
					</vxe-column>
					<vxe-column field="matchingRateOfCallData" title="话务数据匹配率">
						<template #default="scope">
							{{ scope.row.matchingRateOfCallData }}%
						</template>
					</vxe-column>
					<vxe-column field="timelyUploadRateOfCallData" title="话务数据及时上传率">
						<template #default="scope">
							{{ scope.row.timelyUploadRateOfCallData }}%
						</template>
					</vxe-column>
					<vxe-column field="timelyUploadRateOfOrderData" title="工单数据及时上传率">
						<template #default="scope">
							{{ scope.row.timelyUploadRateOfOrderData }}%
						</template>
					</vxe-column>
					<vxe-column field="acceptanceQuantity" title="受理量"></vxe-column>
					<vxe-column field="numbeOfCompletedCases" title="办结件数"></vxe-column>
					<vxe-column field="onTimeCompletionRate" title="按时办结率">
						<template #default="scope">
							{{ scope.row.onTimeCompletionRate }}%
						</template>
					</vxe-column>
					<vxe-column field="followUpVolume" title="回访量"></vxe-column>
					<vxe-column field="dissatisfiedItems" title="不满意件"></vxe-column>
					<vxe-column field="dissatisfactionRate" title="不满意率">
						<template #default="scope">
							{{ scope.row.dissatisfactionRate }}%
						</template>
					</vxe-column>
					<vxe-column field="knowledgeTotalNum" title="知识库总量"></vxe-column>
					<vxe-column field="knowledgeUpdateTotalNum" title="知识库更新数量"></vxe-column>
				</vxe-table>
			</div>
		</div>
	</div>
</template>
<script setup lang="tsx" name="statisticsCenterAggregation">
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
import {FormInstance } from 'element-plus';
import { defaultDate } from '@/utils/constants';
import Other from '@/utils/other';
import { getDataConvergence } from '@/api/dataShare';
import { centerUnreceivedExport } from '@/api/statistics/center';

// 引入组件
const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const state = reactive<any>({
	queryParams: {
		// 查询条件
		PageIndex: 1,
		PageSize: 20,
		crTime: defaultDate, // 生成时间
		StartTime: null,
		EndTime: null,
	},
	tableData: [], //表单
	loading: false, // 加载
});
/** 搜索按钮操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
/** 获取列表 */
const requestParams = ref<EmptyObjectType>({});
const queryList = () => {
	state.loading = true;
	requestParams.value = Other.deepClone(state.queryParams);
	requestParams.value.StartTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[0];
	requestParams.value.EndTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[1];
	Reflect.deleteProperty(requestParams.value, 'crTime');
	getDataConvergence(requestParams.value)
		.then((res: any) => {
			state.tableData = res.result;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
/** 重置按钮操作 */
const statisticalTimeRef = ref<RefType>();
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	statisticalTimeRef.value.reset();
	queryList();
};
const toolbarRef = ref<RefType>();
const tableRef = ref<RefType>();
onMounted(() => {
	queryList();
	if (tableRef.value && toolbarRef.value) {
		tableRef.value.connect(toolbarRef.value);
	}
});
</script>
