<template>
	<div class="statistics-center-detail-seat-satisfaction-list-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-grid v-bind="gridOptions">
				<template #form>
					<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline :disabled="gridOptions.loading">
						<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>
							<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-button type="primary" @click="onPie" :loading="state.loading"> <SvgIcon name="ele-PieChart" class="mr5" />图表 </el-button>
						</el-form-item>
					</el-form>
				</template>
				<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-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>
				</template>
				<template #footer_count="{ row }">
					<el-button type="primary" link @click="linkDetail(row)">{{ row.count }}</el-button>
				</template>
				<template #footer_verySatisfied="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.verySatisfiedKey)">{{ row.verySatisfied }}</el-button>
				</template>
				<template #footer_satisfied="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.satisfiedKey)">{{ row.satisfied }}</el-button>
				</template>
				<template #footer_defaultSatisfied="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.defaultSatisfiedKey)">{{ row.defaultSatisfied }}</el-button>
				</template>
				<template #footer_noSatisfied="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.noSatisfiedKey)">{{ row.noSatisfied }}</el-button>
				</template>
				<template #footer_noEvaluate="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.noEvaluateKey)">{{ row.noEvaluate }}</el-button>
				</template>
				<template #footer_noConnect="{ row }">
					<el-button type="primary" link @click="linkDetail(row,row.noConnectKey)">{{ row.noConnect }}</el-button>
				</template>
			</vxe-grid>
		</div>
	</div>
</template>
<script setup lang="tsx" name="statisticsCenterDetailSeatSatisfactionList">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import { centerSatisfactionDetail, centerSatisfactionDetailExport } from '@/api/statistics/center';
import Other from '@/utils/other';
import { FormInstance } from 'element-plus';
import { defaultDate } from '@/utils/constants';

// 引入组件
const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件
// 定义变量内容
const state = reactive<any>({
	queryParams: {
		// 查询条件
		crTime: defaultDate, //
		StartTime: null,
		EndTime: null,
	},
	loading: false, // 加载
});

const requestParams = ref<EmptyObjectType>({});
const gridOptions = reactive<any>({
	loading: false,
	border: true,
	showOverflow: true,
	columnConfig: {
		resizable: true,
	},
	scrollY: {
		enabled: true,
		gt: 100,
	},
	toolbarConfig: {
		zoom: true,
		custom: true,
		refresh: {
			queryMethod: () => {
				handleQuery();
			},
		},
		tools: [{ toolRender: { name: 'exportAll' } }],
		slots: {
			buttons: 'toolbar_buttons',
		},
	},
	customConfig: {
		storage: true,
	},
	id: 'statisticsCenterDetailSeatSatisfactionList',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{ field: 'userName', title: '话务员', minWidth: 150 },
		{
			field: 'count',
			title: '小计',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, '')} link>
							{row.count}
						</el-button>
					);
				},
				footer: 'footer_count',
			},
		},
		{
			field: 'countRate',
			title: '总满意率',
		},
		{
			field: 'verySatisfied',
			title: '非常满意',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.verySatisfiedKey)} link>
							{row.verySatisfied}
						</el-button>
					);
				},
				footer: 'footer_verySatisfied',
			},
		},
		{
			field: 'verySatisfiedRate',
			title: '非常满意率',
		},
		{
			field: 'satisfied',
			title: '满意',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.satisfiedKey)} link>
							{row.satisfied}
						</el-button>
					);
				},
				footer: 'footer_satisfied',
			},
		},
		{
			field: 'satisfiedRate',
			title: '满意率',
		},
		{
			field: 'defaultSatisfied',
			title: '默认满意',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.defaultSatisfiedKey)} link>
							{row.defaultSatisfied}
						</el-button>
					);
				},
				footer: 'footer_defaultSatisfied',
			},
		},
		{
			field: 'defaultSatisfiedRate',
			title: '默认满意率',
		},
		{
			field: 'noSatisfied',
			title: '不满意',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.noSatisfiedKey)} link>
							{row.noSatisfied}
						</el-button>
					);
				},
				footer: 'footer_noSatisfied',
			},
		},
		{
			field: 'noSatisfiedRate',
			title: '不满意率',
		},
		{
			field: 'noEvaluate',
			title: '未作评价',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.noEvaluateKey)} link>
							{row.noEvaluate}
						</el-button>
					);
				},
				footer: 'footer_noEvaluate',
			},
		},
		{
			field: 'noEvaluateRate',
			title: '未作评价率',
		},
		{
			field: 'noConnect',
			title: '未接通',
			slots: {
				default({ row }) {
					return (
						<el-button type="primary" onClick={() => linkDetail(row, row.noConnectKey)} link>
							{row.noConnect}
						</el-button>
					);
				},
				footer: 'footer_noConnect',
			},
		},
		{
			field: 'noConnectRate',
			title: '未接通率',
		},
	],
	data: [],
	params: {
		exportMethod: centerSatisfactionDetailExport,
		exportParams: requestParams,
	},
	sortConfig: {
		remote: true,
	},
	showFooter: true,
	footerData: [],
});
// 手动查询，将页码设置为1
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
/** 重置按钮操作 */
const statisticalTimeRef = ref<RefType>();
const ruleFormRef = ref<RefType>();
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	statisticalTimeRef.value.reset();
	queryList();
};
/** 获取列表 */
const queryList = async () => {
	try {
		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');
		const { result } = await centerSatisfactionDetail(requestParams.value);
		gridOptions.data = result.list ?? [];
		gridOptions.footerData[0] = result.total;
		state.loading = false;
		gridOptions.loading = false;
	} catch (e) {
		console.log(e);
		state.loading = false;
		gridOptions.loading = false;
	}
};
// 查看图表
const router = useRouter();
const onPie = () => {
	router.push({
		path: '/statistics/center/seatSatisfaction',
	});
};
// 点击数字进入详情
const linkDetail = (row: any, key?: string) => {
	if (key || key === '' || key !== '0') {
		router.push({
			path: '/statistics/center/detailSeatSatisfaction',
			query: {
				SeatEvaluate: key,
				StartTime: requestParams.value.StartTime,
				EndTime: requestParams.value.EndTime,
				UserId: row.userId,
			},
		});
	} else {
		router.push({
			path: '/statistics/center/detailSeatSatisfaction',
			query: {
				StartTime: requestParams.value.StartTime,
				EndTime: requestParams.value.EndTime,
			},
		});
	}
};
onMounted(() => {
	queryList();
});
</script>
