<template>
	<div class="judicial-statistics-detail-department-container layout-padding">
    <div class="layout-padding-auto layout-padding-view pd20">
			<vxe-toolbar
				ref="toolbarRef"
				:loading="state.loading"
				custom
				:refresh="{
					queryMethod: queryList,
				}"
				:tools="[{ toolRender: { name: 'exportCurrent' } }, { 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="judicialDetailDepartment"
					:custom-config="{ storage: true }"
					:params="{ exportMethod: departmentStatisticsDetailExport, exportParams: requestParams }"
					showHeaderOverflow
				>
					<vxe-column field="no" title="工单编码" width="160"></vxe-column>
					<vxe-column field="title" title="工单标题" min-width="200">
						<template #default="{ row }">
							<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
						</template>
					</vxe-column>
					<vxe-column field="acceptType" title="受理类型" width="100"></vxe-column>
					<vxe-column field="hotspotName" title="热点分类" width="150"></vxe-column>
					<vxe-column field="enforcementOrdersHandlerText" title="执法部门" min-width="150"></vxe-column>
					<vxe-column field="incidentAddressText" title="事发地址" min-width="150"></vxe-column>
					<vxe-column field="creationTime" title="生成时间" width="160">
						<template #default="{ row }">
							{{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
						</template>
					</vxe-column>
					<vxe-column field="acceptorName" title="受理人" width="120"></vxe-column>
					<vxe-column field="isPassTheBuckOrderText" title="是否推诿工单" width="120"></vxe-column>
					<vxe-column field="isTheClueTrueText" title="线索是否属实" width="120"></vxe-column>
					<vxe-column field="isEnforcementOrderText" title="是否行政执法类工单" width="150"></vxe-column>
					<vxe-column field="eventTypeName" title="事项类型" width="150"></vxe-column>
				</vxe-table>
			</div>
			<pagination
				@pagination="queryList"
				:total="state.total"
				v-model:current-page="state.queryParams.PageIndex"
				v-model:page-size="state.queryParams.PageSize"
				:disabled="state.loading"
			/>
		</div>
	</div>
</template>
<script setup lang="tsx" name="judicialDetailDepartment">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { useRoute } from 'vue-router';
import { formatDate } from '@/utils/formatTime';
import { departmentStatisticsDetail, departmentStatisticsDetailExport } from '@/api/judicial';

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

// 定义变量内容
const state = reactive<any>({
	queryParams: {
		PageIndex: 1, // 当前页
		PageSize: 20, // 每页条数
		// 查询条件
		EventTypeId: null, // 事件类型
		AreaCode: null, // 区域编码
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
const route = useRoute(); // 路由
/** 获取列表 */
const routeQueryParams = route.query;
const requestParams = ref({});
const queryList = () => {
	const data = {
		PageIndex: state.queryParams.PageIndex,
		PageSize: state.queryParams.PageSize,
		StartTime: routeQueryParams.StartTime,
		EndTime: routeQueryParams.EndTime,
		OrgCode: routeQueryParams.OrgCode,
	};
	switch (routeQueryParams.type) {
		case 'countNum':
			requestParams.value = {
				...data,
			};
			break;
		case 'theClueIsTrue':
			requestParams.value = {
				...data,
				TheClueIsTrue: true,
			};
			break;
		case 'theClueIsNotTrue':
			requestParams.value = {
				...data,
				TheClueIsNotTrue: true,
			};
			break;
		case 'enforcementOrder':
			requestParams.value = {
				...data,
				EnforcementOrder: true,
			};
			break;
	}
	state.loading = true;
	departmentStatisticsDetail(requestParams.value)
		.then((response: any) => {
			state.tableData = response?.result.items ?? [];
			state.total = response?.result.total;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
const toolbarRef = ref<RefType>();
const tableRef = ref<RefType>();
onMounted(() => {
	queryList();
	if (tableRef.value && toolbarRef.value) {
		tableRef.value.connect(toolbarRef.value);
	}
});
</script>
