﻿<template>
	<div class="eqTask-container">
		<el-card shadow="hover" :body-style="{ padding: '20px 20px 16px 10px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
			<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%" @submit.prevent="handleQuery" >
				<el-row :gutter="10">
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5">
						<el-form-item label="关键字" prop="searchKey">
							<el-input v-model="state.queryParams.searchKey" placeholder="请输入模糊查询关键字" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="创建人" prop="create_user_id">
							<el-input v-model="state.queryParams.create_user_id" placeholder="创建人" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="创建部门" prop="create_dept">
							<el-input v-model="state.queryParams.create_dept" placeholder="创建部门" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="创建时间" prop="create_time">
							<el-date-picker type="daterange" v-model="state.queryParams.create_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="修改人" prop="update_user_id">
							<el-input v-model="state.queryParams.update_user_id" placeholder="修改人" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="修改时间" prop="update_time">
							<el-date-picker type="daterange" v-model="state.queryParams.update_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="状态">
							<el-input-number v-model="state.queryParams.status" placeholder="请输入状态" clearable @keyup.enter.native="handleQuery" />
					</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="是否已删除">
							<el-input-number v-model="state.queryParams.is_deleted" placeholder="请输入是否已删除" clearable @keyup.enter.native="handleQuery" />
					</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务编号" prop="task_code">
							<el-input v-model="state.queryParams.task_code" placeholder="任务编号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="指派状态" prop="assign_status">
							<el-input v-model="state.queryParams.assign_status" placeholder="指派状态" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务来源" prop="task_source">
							<el-input v-model="state.queryParams.task_source" placeholder="任务来源" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务状态" prop="task_status">
							<el-input v-model="state.queryParams.task_status" placeholder="任务状态" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="复核状态" prop="review_status">
							<el-input v-model="state.queryParams.review_status" placeholder="复核状态" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务结果" prop="task_result">
							<el-input v-model="state.queryParams.task_result" placeholder="任务结果" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="处置结果" prop="dispose_result">
							<el-input v-model="state.queryParams.dispose_result" placeholder="处置结果" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="超时状态" prop="overtime_status">
							<el-input v-model="state.queryParams.overtime_status" placeholder="超时状态" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="计划" prop="plan_id">
							<el-input v-model="state.queryParams.plan_id" placeholder="计划" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="计划编号" prop="plan_code">
							<el-input v-model="state.queryParams.plan_code" placeholder="计划编号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="计划名称" prop="plan_name">
							<el-input v-model="state.queryParams.plan_name" placeholder="计划名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="对象" prop="object_id">
							<el-input v-model="state.queryParams.object_id" placeholder="对象" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="对象编码" prop="object_code">
							<el-input v-model="state.queryParams.object_code" placeholder="对象编码" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="对象名称" prop="object_name">
							<el-input v-model="state.queryParams.object_name" placeholder="对象名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="对象类型" prop="object_type">
							<el-input v-model="state.queryParams.object_type" placeholder="对象类型" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="模板类型" prop="type">
							<el-input v-model="state.queryParams.type" placeholder="模板类型" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="模板" prop="template_id">
							<el-input v-model="state.queryParams.template_id" placeholder="模板" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="模板编码" prop="template_code">
							<el-input v-model="state.queryParams.template_code" placeholder="模板编码" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="模板名称" prop="template_name">
							<el-input v-model="state.queryParams.template_name" placeholder="模板名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务开始时间" prop="task_start_time">
							<el-date-picker type="daterange" v-model="state.queryParams.task_start_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务结束时间" prop="task_end_time">
							<el-date-picker type="daterange" v-model="state.queryParams.task_end_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务类型" prop="task_type">
							<el-input v-model="state.queryParams.task_type" placeholder="任务类型" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="计划开始时间" prop="plan_start_time">
							<el-date-picker type="daterange" v-model="state.queryParams.plan_start_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="计划结束时间" prop="plan_end_time">
							<el-date-picker type="daterange" v-model="state.queryParams.plan_end_timeRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="标准用时" prop="standard_time">
							<el-input v-model="state.queryParams.standard_time" placeholder="标准用时" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="实际用时" prop="actual_time">
							<el-input v-model="state.queryParams.actual_time" placeholder="实际用时" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="接收形式(0员工，1岗位，2班组)" prop="receive_type">
							<el-input v-model="state.queryParams.receive_type" placeholder="接收形式(0员工，1岗位，2班组)" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="班组" prop="receive_group">
							<el-input v-model="state.queryParams.receive_group" placeholder="班组" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="员工" prop="receive_user">
							<el-input v-model="state.queryParams.receive_user" placeholder="员工" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="关闭原因" prop="shutdown_reason">
							<el-input v-model="state.queryParams.shutdown_reason" placeholder="关闭原因" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="文件" prop="file">
							<el-input v-model="state.queryParams.file" placeholder="文件" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="复核说明" prop="review_info">
							<el-input v-model="state.queryParams.review_info" placeholder="复核说明" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="任务分发类型" prop="task_distribute_type">
							<el-input v-model="state.queryParams.task_distribute_type" placeholder="任务分发类型" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="异常类型" prop="err_type">
							<el-input v-model="state.queryParams.err_type" placeholder="异常类型" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="异常类型分项" prop="err_subitem">
							<el-input v-model="state.queryParams.err_subitem" placeholder="异常类型分项" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="异常等级" prop="err_lv">
							<el-input v-model="state.queryParams.err_lv" placeholder="异常等级" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>

			<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />

			<el-row>
				<el-col>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"  :loading="options.loading"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
						<el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!state.showAdvanceQueryUI" style="margin-left: 5px"> 高级查询 </el-button>
						<el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="state.showAdvanceQueryUI" style="margin-left: 5px"> 隐藏 </el-button>
					</el-button-group>
				</el-col>
			</el-row>
		</el-card>

		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
				<template #toolbar_buttons>
					<el-button type="primary" icon="ele-Plus" @click="handleAdd"> 新增 </el-button>
				</template>
				<template #toolbar_tools> </template>
				<template #empty>
					<el-empty :image-size="200" />
				</template>
				<template #row_record="{ row }">
					<ModifyRecord :data="row" />
				</template>
				<template #row_buttons="{ row }">
					<el-tooltip content="编辑" placement="top">
						<el-button icon="ele-Edit" size="small" text type="primary" @click="handleEdit(row)" />
					</el-tooltip>
					<el-tooltip content="删除" placement="top">
						<el-button icon="ele-Delete" size="small" text type="danger" @click="handleDelete(row)"  />
					</el-tooltip>
				</template>
			</vxe-grid>
		</el-card>

		<PrintDialog ref="printDialogRef" :title="state.title" @reloadTable="handleQuery" />
		<EditDialog ref="editDialogRef" :title="state.title" @reloadTable="handleQuery" />
	</div>
</template>

<script lang="ts" setup name="eqTask">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from "element-plus";
import { auth } from '/@/utils/authFunction';

import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage';

import { formatDate } from '/@/utils/formatTime';

// 子窗口
import PrintDialog from '/@/views/system/print/component/hiprint/preview.vue';
import EditDialog from '/@/views/cqds/eqTask/component/editDialog.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';

import { pageEqTask, deleteEqTask } from '/@/api/cqds/eqTask';

// 子窗口对象
const xGrid = ref<VxeGridInstance>();
const printDialogRef = ref<InstanceType<typeof PrintDialog>>();
const editDialogRef = ref<InstanceType<typeof EditDialog>>();

// 变量
const state = reactive({
	showAdvanceQueryUI: false,
	queryParams: {
		searchKey: undefined,
		create_user_id: undefined,
		create_dept: undefined,
		create_time: undefined,
		update_user_id: undefined,
		update_time: undefined,
		status: undefined,
		is_deleted: undefined,
		task_code: undefined,
		assign_status: undefined,
		task_source: undefined,
		task_status: undefined,
		review_status: undefined,
		task_result: undefined,
		dispose_result: undefined,
		overtime_status: undefined,
		plan_id: undefined,
		plan_code: undefined,
		plan_name: undefined,
		object_id: undefined,
		object_code: undefined,
		object_name: undefined,
		object_type: undefined,
		type: undefined,
		template_id: undefined,
		template_code: undefined,
		template_name: undefined,
		task_start_time: undefined,
		task_end_time: undefined,
		task_type: undefined,
		plan_start_time: undefined,
		plan_end_time: undefined,
		standard_time: undefined,
		actual_time: undefined,
		receive_type: undefined,
		receive_group: undefined,
		receive_user: undefined,
		shutdown_reason: undefined,
		file: undefined,
		review_info: undefined,
		task_distribute_type: undefined,
		err_type: undefined,
		err_subitem: undefined,
		err_lv: undefined,
	},
	localPageParam: {
		pageSize: 50 as number,
		defaultSort: { field: 'createTime', order: 'asc', descStr: 'desc' },
	},
	visible: false,
	title: '',
});

// 本地存储参数
const localPageParamKey = 'localPageParam:eqTask';

// 改变高级查询的控件显示状态
const changeAdvanceQueryUI = () => {
	state.showAdvanceQueryUI = !state.showAdvanceQueryUI;
};

// 表格参数配置
const options = useVxeTable<any>(
	{
		id: 'EqTask',
		name: '任务管理',
		columns: [
			{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
			// { field: 'create_user_id', title: '创建人', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'create_dept', title: '创建部门', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'create_time', title: '创建时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			// { field: 'update_user_id', title: '修改人', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'update_time', title: '修改时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			// { field: 'is_deleted', title: '是否已删除', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'task_code', title: '任务编号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'status', title: '状态', minWidth: 100, showOverflow: 'tooltip', sortable: false},

			{ field: 'assign_status', title: '指派状态', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'task_source', title: '任务来源', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'task_status', title: '任务状态', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'review_status', title: '复核状态', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'task_result', title: '任务结果', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'dispose_result', title: '处置结果', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'overtime_status', title: '超时状态', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'plan_id', title: '计划', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'plan_code', title: '计划编号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'plan_name', title: '计划名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'object_id', title: '对象', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'object_code', title: '对象编码', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'object_name', title: '对象名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'object_type', title: '对象类型', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'type', title: '模板类型', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'template_id', title: '模板', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'template_code', title: '模板编码', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'template_name', title: '模板名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'task_start_time', title: '任务开始时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'plan_start_time', title: '计划开始时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'plan_end_time', title: '计划结束时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			
			{ field: 'task_end_time', title: '任务结束时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'task_type', title: '任务类型', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'standard_time', title: '标准用时', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'actual_time', title: '实际用时', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'receive_type', title: '接收形式(0员工，1岗位，2班组)', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'receive_group', title: '班组', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'receive_user', title: '员工', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'shutdown_reason', title: '关闭原因', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'file', title: '文件', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'review_info', title: '复核说明', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'task_distribute_type', title: '任务分发类型', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'err_type', title: '异常类型', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'err_subitem', title: '异常类型分项', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			// { field: 'err_lv', title: '异常等级', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
			{ title: '操作', fixed: 'right', width: 180, showOverflow: true, slots: { default: 'row_buttons' } },
		],
	},
	// vxeGrid配置参数(此处可覆写任何参数)，参考vxe-table官方文档
	{
		// 代理配置
		proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
		// 排序配置
		sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
		// 分页配置
		pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
		// 工具栏配置
		toolbarConfig: { export: false },
		// 行设置
		// rowConfig: { height: 80 },
	}
);

// 页面初始化
onMounted(() => {});

// 查询api
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
	const params = Object.assign(state.queryParams, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as any;
	return pageEqTask(params);
};

// 查询操作
const handleQuery = async (reset = false) => {
	options.loading = true;
	await xGrid.value?.commitProxy('query');
	options.loading = false;
};

// 重置操作
const resetQuery = async () => {
	state.queryParams.searchKey = undefined,
	state.queryParams.create_user_id = undefined,
	state.queryParams.create_dept = undefined,
	state.queryParams.create_time = undefined,
	state.queryParams.update_user_id = undefined,
	state.queryParams.update_time = undefined,
	state.queryParams.status = undefined,
	state.queryParams.is_deleted = undefined,
	state.queryParams.task_code = undefined,
	state.queryParams.assign_status = undefined,
	state.queryParams.task_source = undefined,
	state.queryParams.task_status = undefined,
	state.queryParams.review_status = undefined,
	state.queryParams.task_result = undefined,
	state.queryParams.dispose_result = undefined,
	state.queryParams.overtime_status = undefined,
	state.queryParams.plan_id = undefined,
	state.queryParams.plan_code = undefined,
	state.queryParams.plan_name = undefined,
	state.queryParams.object_id = undefined,
	state.queryParams.object_code = undefined,
	state.queryParams.object_name = undefined,
	state.queryParams.object_type = undefined,
	state.queryParams.type = undefined,
	state.queryParams.template_id = undefined,
	state.queryParams.template_code = undefined,
	state.queryParams.template_name = undefined,
	state.queryParams.task_start_time = undefined,
	state.queryParams.task_end_time = undefined,
	state.queryParams.task_type = undefined,
	state.queryParams.plan_start_time = undefined,
	state.queryParams.plan_end_time = undefined,
	state.queryParams.standard_time = undefined,
	state.queryParams.actual_time = undefined,
	state.queryParams.receive_type = undefined,
	state.queryParams.receive_group = undefined,
	state.queryParams.receive_user = undefined,
	state.queryParams.shutdown_reason = undefined,
	state.queryParams.file = undefined,
	state.queryParams.review_info = undefined,
	state.queryParams.task_distribute_type = undefined,
	state.queryParams.err_type = undefined,
	state.queryParams.err_subitem = undefined,
	state.queryParams.err_lv = undefined,
	await xGrid.value?.commitProxy('reload');
};

// 打开新增页面
const handleAdd = () => {
	state.title = '添加任务管理';
	editDialogRef.value?.openDialog({ type: 1 });
};

// 打开编辑页面
const handleEdit = (row: any) => {
	state.title = '编辑任务管理';
	editDialogRef.value?.openDialog(row);
};

// 打开打印页面
const handlePrint = async (row: any) => {
	state.title = '打印任务管理';
};

// 删除
const handleDelete = (row: any) => {
	ElMessageBox.confirm(`确定删除任务管理：【${row.title}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(async () => {
		await deleteEqTask(row);
		await handleQuery();
		ElMessage.success('删除成功');
	})
	.catch(() => {});
};

// 表格事件
const gridEvents: VxeGridListeners<any> = {
	// 只对 pager-config 配置时有效，分页发生改变时会触发该事件
	async pageChange({ pageSize }) {
		state.localPageParam.pageSize = pageSize;
		Local.set(localPageParamKey, state.localPageParam);
	},
	// 当排序条件发生变化时会触发该事件
	async sortChange({ field, order }) {
		state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
		Local.set(localPageParamKey, state.localPageParam);
	},
};

</script>

<style lang="scss" scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
