<template>
	<div class="snapshot-statistics-detail-community-order-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-grid v-bind="gridOptions" v-on="gridEvents" ref="gridRef">
				<template #statusTxt="{ row }">
					<el-text type="danger" tag="b" v-if="[1, 2, 3, 9, 101, 102, 103, 104, 105, 200].includes(row.status)">{{ row.statusTxt }}</el-text>
					<span v-else>{{ row.statusTxt }}</span>
				</template>
				<template #order_detail="{ row }">
					<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
				</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>
					</el-popover>
				</template>
				<template #pager>
					<pagination
						@pagination="queryList"
						:total="state.total"
						v-model:current-page="state.queryParams.PageIndex"
						v-model:page-size="state.queryParams.PageSize"
						:disabled="state.loading"
					/>
				</template>
			</vxe-grid>
		</div>
	</div>
</template>
<script setup lang="tsx" name="snapshotStatisticsDetailCommunity">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import Other from '@/utils/other';
import { getSSPStatisticsCommunityDetail, getSSPStatisticsCommunityDetailExport } from '@/api/snapshot/statistics';
import { useRoute } from 'vue-router';

// 引入组件
const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页

// 定义变量内容
const state = reactive<any>({
	queryParams: {
		PageIndex: 1, // 当前页
		PageSize: 20, // 每页条数
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
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: 'exportCurrent' } }, { toolRender: { name: 'exportAll' } }],
		slots: {
			buttons: 'toolbar_buttons',
		},
	},
	customConfig: {
		storage: true,
	},
	id: 'snapshotStatisticsDetailCommunity',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'expiredStatusText',
			title: '状态',
			width: 60,
			align: 'center',
			slots: {
				default: ({ row }) => {
					return <span class={'overdue-status-' + row.expiredStatus} title={row.expiredStatusText}></span>;
				},
			},
		},
		{
			field: 'statusTxt',
			title: '工单状态',
			width: 110,
			slots: {
				default: 'statusTxt',
			},
		},
		{ field: 'sourceChannel', title: '来源渠道', width: 110 },
		{ field: 'currentStepName', title: '当前节点', width: 120 },
		{ field: 'reTransactNum', title: '重办次数', width: 90 },
		{ field: 'orderScreenStatusText', title: '甄别状态', width: 100 },
		{ field: 'no', title: '工单编码', width: 140 },
		{
			field: 'creationTime',
			title: '受理时间',
			width: 160,
			sortable: true,
			formatter: 'formatDate',
		},
		{
			field: 'title',
			title: '工单标题',
			minWidth: 200,
			slots: { default: 'order_detail' },
		},
		{
			field: 'expiredTime',
			title: '期满时间',
			width: 160,
			sortable: true,
			formatter: 'formatDate',
		},
		{ field: 'actualHandleOrgName', title: '接办部门', width: 140 },
		{
			field: 'actualHandleTime',
			title: '接办时间',
			width: 160,
			sortable: true,
			formatter: 'formatDate',
		},
		{
			field: 'filedTime',
			title: '办结时间',
			width: 160,
			sortable: true,
			formatter: 'formatDate',
		},
		{ field: 'communityName', title: '社区名称', width: 140 },
		{ field: 'acceptType', title: '受理类型', width: 120 },
		{ field: 'hotspotName', title: '热点分类', width: 150 },
	],
	data: [],
	params: {
		exportMethod: getSSPStatisticsCommunityDetailExport,
		exportParams: requestParams,
	},
	sortConfig: {
		remote: true,
	},
});
const gridEvents = {
	sortChange(val: any) {
		state.queryParams.SortField = val.order ? val.field : null;
		// 0 升序 1 降序
		state.queryParams.SortRule = val.order ? (val.order == 'desc' ? 1 : 0) : null;
		handleQuery();
	},
};
// 手动查询，将页码设置为1
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 改变页码
const route = useRoute();
const routeQueryParams = route.query;
const queryList = () => {
	return new Promise((resolve, reject) => {
		requestParams.value = Other.deepClone(state.queryParams);
		requestParams.value.StartTime = routeQueryParams.StartTime;
		requestParams.value.EndTime = routeQueryParams.EndTime;
		requestParams.value.CommunityFullName = routeQueryParams.CommunityFullName;
		requestParams.value.IndustryId = routeQueryParams.IndustryId;
		state.loading = true;
		gridOptions.loading = true;
		getSSPStatisticsCommunityDetail(requestParams.value)
			.then((response: any) => {
				gridOptions.data = response?.result.items ?? [];
				state.total = response?.result.total;
				state.loading = false;
				gridOptions.loading = false;
				resolve(response);
			})
			.catch(() => {
				state.loading = false;
				gridOptions.loading = false;
				reject();
			});
	});
};
onMounted(() => {
	queryList();
});
</script>
