<template>
	<div class="statistics-order-hotspot-satisfied-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="热点名称" prop="HotspotName">
					<el-input v-model="state.queryParams.HotspotName" placeholder="热点名称" clearable @keyup.enter="handleQuery" class="keyword-input" />
				</el-form-item>
				<el-form-item label="归档类型" prop="TypeId">
					<el-select v-model="state.queryParams.TypeId" placeholder="归档类型" @change="handleQuery">
						<el-option label="办件结果" value="1" />
						<el-option label="办件态度" value="2" />
					</el-select>
				</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-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-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-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,
				}"
				:tools="[{ toolRender: { name: 'exportAll' } }]"
			>
			</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="statisticsOrderHotspotSatisfied"
					:custom-config="{
						storage: true,
					}"
					showHeaderOverflow
					:params="{ exportMethod: statisticsOrderHotSatisfyExport, exportParams: requestParams }"
					show-footer
					:footer-method="footerMethod"
				>
					<vxe-column field="hotspotName" title="热点名称" min-width="200" fixed="left">
					</vxe-column>
					<vxe-column field="totalSumCount" title="小计" min-width="90" fixed="left"> </vxe-column>
					<vxe-column field="totalSumRateText" title="总满意率" min-width="120"> </vxe-column>
					<vxe-column field="verySatisfiedCount" title="非常满意"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail(scope)">
								{{ scope.row.verySatisfiedCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="verySatisfiedRateText" title="非常满意率" min-width="120"> </vxe-column>
					<vxe-column field="satisfiedCount" title="满意"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail( scope)">
								{{ scope.row.satisfiedCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="satisfiedRateText" title="满意率" min-width="120"> </vxe-column>
					<vxe-column field="regardedAsSatisfiedCount" title="视为满意"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail( scope.row)">
								{{ scope.row.regardedAsSatisfiedCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="regardedAsSatisfiedRateText" title="视为满意率" min-width="120"> </vxe-column>
					<vxe-column field="defaultSatisfiedCount" title="默认满意"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail( scope)">
								{{ scope.row.defaultSatisfiedCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="defaultSatisfiedRateText" title="默认满意率" min-width="120"> </vxe-column>
					<vxe-column field="noSatisfiedCount" title="不满意"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail(scope)">
								{{ scope.row.noSatisfiedCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="noSatisfiedRateText" title="不满意率" min-width="120"> </vxe-column>
					<vxe-column field="noEvaluateCount" title="未作评价"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail(scope)">
								{{ scope.row.noEvaluateCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="noEvaluateRateText" title="未作评价率" min-width="120"> </vxe-column>
					<vxe-column field="noPutThroughCount" title="未接通"  min-width="100">
						<template #default="scope">
							<el-button type="primary" link @click="linkDetail(scope)">
								{{ scope.row.noPutThroughCount }}
							</el-button>
						</template>
					</vxe-column>
					<vxe-column field="noPutThroughRateText" title="未接通率" min-width="120"> </vxe-column>
				</vxe-table>
			</div>
		</div>
	</div>
</template>
<script setup lang="tsx" name="statisticsOrderHotspotSatisfied">
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
import { FormInstance } from 'element-plus';
import { defaultDate } from '@/utils/constants';
import Other from '@/utils/other';
import { statisticsOrderHotSatisfy, statisticsOrderHotSatisfyExport } from '@/api/statistics/order';
import { useRouter } from 'vue-router';
import XEUtils from 'xe-utils';

const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const state = reactive<any>({
	queryParams: {
		// 查询条件
		HotspotName: null,
		TypeId: '1',
		crTime: defaultDate, //
		StartTime: null,
		EndTime: null,
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
	totalCount: {},
});
/** 搜索按钮操作 */
const handleQuery = () => {
	// state.queryParams.PageIndex = 1;
	queryList();
};
/** 获取列表 */
const requestParams = ref<EmptyObjectType>({});
const queryList = async () => {
	state.loading = true;
	try {
		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');
		const { result } = await statisticsOrderHotSatisfy(requestParams.value);
		state.tableData = result.dataList;
		state.totalCount = result.sumModel;
		state.loading = false;
	} catch (e) {
		state.loading = false;
		console.log(e);
	}
};
/** 重置按钮操作 */
const statisticalTimeRef = ref<RefType>();
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	statisticalTimeRef.value.reset();
	queryList();
};
// 计算合计
const footerMethod = ({ columns, data }) => {
	return [
		columns.map((column: any, columnIndex: number) => {
			if (columnIndex === 0) {
				return '合计';
			}
			// 后端返回了数据集合 state.totalCount 所以不需要计算 直接进行赋值
			return XEUtils.get(state.totalCount, column.property);
		}),
	];
};
// 查看列表明细
const router = useRouter();
const linkDetail = (data:any) => {
	router.push({
		path: '/statistics/order/detailHotspotSatisfied',
		query: {
			HotspotName: data.row.hotspotName,
			HotspotId: data.row.hotspotId,
			StartTime: requestParams.value.StartTime,
			EndTime: requestParams.value.EndTime,
			TypeId: requestParams.value.TypeId,
			TitleCode: data.column.property,
			tagsViewName:`${data.row.hotspotName}-${data.column.title}`
		},
	});
};
const toolbarRef = ref<RefType>();
const tableRef = ref<RefType>();
onMounted(() => {
	queryList();
	if (tableRef.value && toolbarRef.value) {
		tableRef.value.connect(toolbarRef.value);
	}
});
</script>
