<template>
	<div class="statistics-order-detail-dispatch-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-toolbar
				ref="toolbarRef"
				:loading="state.loading"
				custom
				:refresh="{
					queryMethod: handleQuery,
				}"
			>
			</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="statisticsOrderDetailDispatch"
					:custom-config="{ storage: true }"
				>
					<vxe-column field="no" title="工单编码" width="140"></vxe-column>
					<vxe-column field="isProvinceText" title="省/市工单" width="100"></vxe-column>
					<vxe-column field="currentStepName" title="当前节点" width="120"></vxe-column>
					<vxe-column field="statusText" title="工单状态" width="100">
						<template #default="{ row }">
							<span class="color-danger" v-if="[1, 2, 3, 9, 101, 102, 103, 104, 105, 200].includes(row.status)">{{ row.statusText }}</span>
							<span>{{ row.statusText }}</span>
						</template>
					</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="creationTime" title="受理时间" width="160">
						<template #default="{ row }">
							{{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
						</template>
					</vxe-column>
					<vxe-column field="acceptType" title="受理类型" width="100"></vxe-column>
					<vxe-column field="sourceChannel" title="来源渠道" width="110"></vxe-column>
					<vxe-column field="hotspotName" title="热点分类" width="150"></vxe-column>
					<vxe-column field="acceptorName" title="受理人" width="120"></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="statisticsOrderDetailDispatch">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { formatDate } from '@/utils/formatTime';
import { departmentDispatchDetail } from '@/api/statistics/order';
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({
	queryParams: {
		// 查询条件
		PageIndex: 1,
		PageSize: 20,
		State: null, // 特提状态
		Keyword: null, // 关键字
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});

/** 搜索按钮操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
/** 获取列表 */
const route = useRoute();
const routeQueryParams = route.query;
const queryList = () => {
	state.loading = true;
	const request = {
		PageIndex: state.queryParams.PageIndex,
		PageSize: state.queryParams.PageSize,
		Keyword: state.queryParams.Keyword,
		UserId: routeQueryParams.UserId,
		StartTime: routeQueryParams.startTime,
		EndTime: routeQueryParams.endTime,
		TitleCode: routeQueryParams.TitleCode,
	};
	departmentDispatchDetail(request)
		.then((res: any) => {
			state.tableData = res.result?.items ?? [];
			state.total = res.result?.total ?? 0;
			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>
