<template>
	<div class="business-publish-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<ProTable
				ref="proTableRef"
				:columns="columns"
				:data="state.tableData"
				@updateTable="queryList"
				:loading="state.loading"
				:total="state.total"
				v-model:page-index="state.queryParams.PageIndex"
				v-model:page-size="state.queryParams.PageSize"
			>
				<template #table-search>
					<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
						<el-form-item label="工单编码" prop="Keyword">
							<el-input v-model="state.queryParams.Keyword" placeholder="工单编码" clearable @keyup.enter="handleQuery" class="keyword-input" />
						</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-form-item>
					</el-form>
				</template>
				<template #title="{ row }">
					<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
				</template>
				<template #expiredStatusText="{ row }">
					<span :class="'overdue-status-' + row.expiredStatus" :title="row.expiredStatusText"></span>
				</template>
				<!-- 表格操作 -->
				<template #operation="{ row }">
					<el-button link type="primary" @click="onDetail(row)"  title="查看修改明细">
						查看明细
					</el-button>
				</template>
			</ProTable>
		</div>
		<edit-record ref="orderPublishEditRef" />
	</div>
</template>
<script setup lang="tsx" name="todoEditRecord">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { formatDate } from '@/utils/formatTime';
import { publishedList } from '@/api/business/publish';
import { getOrderModifyRecord } from '@/api/todo/center';
// 引入组件
const EditRecord = defineAsyncComponent(() => import('@/views/todo/edit/components/Edit-record.vue')); // 修改记录详情
const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const proTableRef = ref<RefType>(); // 表格ref
// 表格配置项
const columns = ref<any[]>([
	{ prop: 'expiredStatusText', label: '超期状态', align: 'center', minWidth: 80 },
	{ prop: 'statusText', label: '工单状态', minWidth: 100 },
	{ prop: 'sourceChannel', label: '来源渠道', minWidth: 100 },
	{ prop: 'currentStepName', label: '当前节点', minWidth: 100 },
	{ prop: 'no', label: '工单编码', minWidth: 140 },
	{ prop: 'title', label: '工单标题', minWidth: 200 },
	{ prop: 'auditUserName', label: '修改人', minWidth: 90 },
	{
		prop: 'creationTime',
		label: '修改时间',
		minWidth: 160,
		render: (scope) => {
			return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
		},
	},
	{ prop: 'operation', label: '操作', fixed: 'right', minWidth: 90, align: 'center' },
]);
const state = reactive({
	queryParams: {
		// 查询条件
		PageIndex: 1,
		PageSize: 20,
		Keyword: null, // 关键词
		No: null,
		Resolve: null, // 处理结果
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
// 手动查询，将页码设置为1
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
/** 获取列表 */
const queryList = () => {
	state.loading = true;
	getOrderModifyRecord(state.queryParams)
		.then((res: any) => {
			state.tableData = res.result?.items ?? [];
			state.total = res.result?.total ?? 0;
			state.loading = false;
		})
		.catch((err: any) => {
			state.loading = false;
		});
};
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
};
// 查看明细
const orderPublishEditRef = ref<RefType>();
const onDetail = (row: any) => {
	orderPublishEditRef.value.openDrawer(row.copyId);
};
onMounted(() => {
	queryList();
});
</script>
