<template>
	<el-dialog v-model="state.dialogVisible" draggable title="重复工单" ref="dialogRef" width="60%" append-to-body>
		<vxe-table
			border
			:loading="state.loading"
			:data="state.tableData"
			:sort-config="{ remote: true }"
			:column-config="{ resizable: true }"
			:row-config="{ isHover: true, height: 30, useKey: true }"
			ref="tableRef"
			max-height="500px"
			show-overflow
			:scrollY="{ enabled: true, gt: 100 }"
		>
			>
			<vxe-column field="title" title="工单标题">
				<template #default="{ row }">
					<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
				</template>
			</vxe-column>
			<vxe-column field="no" title="工单编码"></vxe-column>
			<vxe-column field="hotspotName" title="热点分类"></vxe-column>
			<vxe-column field="currentStepName" title="当前节点"></vxe-column>
			<vxe-column field="statusText" title="重办次数"></vxe-column>
		</vxe-table>
		<pagination
			@pagination="queryList"
			:total="state.total"
			v-model:current-page="state.queryParams.PageIndex"
			v-model:page-size="state.queryParams.PageSize"
			:disabled="state.loading"
		/>
	</el-dialog>
</template>

<script setup lang="tsx" name="orderRepeat">
import { reactive, ref, defineAsyncComponent } from 'vue';
import { duplicateOrder } from '@/api/business/order';

const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
// 定义变量内容
const state = reactive<any>({
	dialogVisible: false, // 弹窗显示隐藏
	queryParams: {
		PageIndex: 1, // 当前页
		PageSize: 10, // 每页条数
	},
	tableData: [], // 表格数据
	total: 0, // 总条数
	loading: false, // 加载状态
	ruleForm: {}, // 表单数据
});
// 表格配置项
const columns = ref<any[]>([
	{ prop: 'title', label: '工单标题', minWidth: 200 },
	{ prop: 'no', label: '工单编码', minWidth: 140 },
	{ prop: 'hotspotName', label: '热点分类' },
	{ prop: 'currentStepName', label: '当前节点',minWidth: 120 },
	{ prop: 'statusText', label: '重办次数', width: 100 },
]);
// 打开弹窗
const openDialog = (row: any) => {
	state.ruleForm = row;
	queryList();
	state.dialogVisible = true;
};
const dialogRef = ref<RefType>();
// 关闭弹窗
const closeDialog = () => {
	state.dialogVisible = false;
};
/** 获取历史工单 */
const queryList = () => {
	if (!state.ruleForm.duplicateIds) return;
	state.loading = true;
	let req = {
		...state.queryParams,
		OrderIds: state.ruleForm.duplicateIds,
	};
	duplicateOrder(req)
		.then((response: any) => {
			state.tableData = response?.result.items ?? [];
			state.total = response?.result.total;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
// 暴露变量
defineExpose({
	openDialog,
	closeDialog,
});
</script>
