<template>
	<div class="statistics-center-inline-mass-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<div class="table-search-content">
				<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
					<el-form-item prop="crTime" label="查询时间段">
						<el-date-picker
							v-model="state.queryParams.crTime"
							type="datetimerange"
							unlink-panels
							range-separator="至"
							start-placeholder="开始时间"
							end-placeholder="结束时间"
							:shortcuts="shortcuts"
							@change="handleQuery"
							value-format="YYYY-MM-DD[T]HH:mm:ss"
							:default-time="defaultTimeStartEnd"
							:clearable="false"
							:editable="false"
						/>
					</el-form-item>
					<el-form-item prop="hbTime" label="环比时间段">
						<el-date-picker
							v-model="state.queryParams.hbTime"
							type="datetimerange"
							unlink-panels
							range-separator="至"
							start-placeholder="开始时间"
							end-placeholder="结束时间"
							:shortcuts="shortcuts"
							@change="handleQuery"
							value-format="YYYY-MM-DD[T]HH:mm:ss"
							:default-time="defaultTimeStartEnd"
							:clearable="false"
							:editable="false"
						/>
					</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" :loading="state.loading">
							<SvgIcon name="ele-Refresh" class="mr5" />重置
						</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div style="overflow: hidden; width: 100%; height: 100%; flex: 1">
				<vxe-grid v-bind="gridOptions">
					<template #toolbar_buttons>
						<el-popover :width="500" 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>
						</el-popover>
					</template>
				</vxe-grid>
			</div>
		</div>
	</div>
</template>
<script setup lang="tsx" name="statisticsCenterOnlineMass">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { defaultDate, defaultTimeStartEnd, shortcuts } from '@/utils/constants';
import Other from '@/utils/other';
import { centerIntelligentValidity } from '@/api/statistics/center';

const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const state = reactive<any>({
	queryParams: {
		// 查询条件
		crTime: defaultDate, // 时间默认今天开始到今天结束
		hbTime: defaultDate,
	},
	loading: false, // 加载
	tableData: [],
	total: 0, // 总数
});
const requestParams = ref<EmptyObjectType>({});
const gridOptions = reactive<any>({
	loading: false,
	border: true,
	showOverflow: true,
	printConfig: {},
	columnConfig: {
		resizable: true,
	},
	scrollY: {
		enabled: true,
		gt: 100
	},
	toolbarConfig: {
		zoom: true,
		custom: true,
		refresh: {
			queryMethod: () => {
				queryList();
			},
		},
		slots: {
			buttons: 'toolbar_buttons'
		}
	},
	customConfig: {
		storage: true
	},
	id: 'statisticsCenterOnlineMass',
	rowConfig: { isHover: true, height: 30,isCurrent:true,useKey:true },
	height: 'auto',
	columns: [
		{
			title:'受理渠道',
			field: 'aiVisitCount',
		},
		{
			title:'数量(件)',
			field: 'aiVisitSuccessCount',
		},
		{
			title:'上期数量',
			field: 'aiVisitCallTwoFailCount',
		},
		{
			title:'环比',
			field: 'aiVisitHaveOneAnswerCount',
		},
	],
	data: [],
});
/** 搜索按钮操作 */
const handleQuery = () => {
	// state.queryParams.PageIndex = 1;
	queryList();
};
/** 获取列表 */
const queryList = () => {
	state.loading = true;
	gridOptions.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');
	centerIntelligentValidity(requestParams.value)
		.then((res: any) => {
			gridOptions.data = [res.result]
			state.loading = false;
			gridOptions.loading = false;
		})
		.catch(() => {
			state.loading = false;
			gridOptions.loading = false;
		});
};
/** 重置按钮操作 */
const statisticalTimeRef = ref<RefType>();
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	statisticalTimeRef.value.reset();
	queryList();
};
onMounted(() => {
	queryList();
});
</script>
