﻿<template>
	<div class="eqTask-container">
		<el-dialog v-model="state.isShowDialog" v-if="state.isShowDialog" :width="800" draggable="" :close-on-click-modal="false">
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>{{ props.title }}</span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
				<el-row :gutter="35">
					<el-form-item v-show="false">
						<el-input v-model="state.ruleForm.id" />
					</el-form-item>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="创建人" prop="create_user_id">
							<el-input v-model="state.ruleForm.create_user_id" placeholder="请输入创建人" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="创建部门" prop="create_dept">
							<el-input v-model="state.ruleForm.create_dept" placeholder="请输入创建部门" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="创建时间" prop="create_time">
							<el-date-picker v-model="state.ruleForm.create_time" type="date" placeholder="创建时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="修改人" prop="update_user_id">
							<el-input v-model="state.ruleForm.update_user_id" placeholder="请输入修改人" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="修改时间" prop="update_time">
							<el-date-picker v-model="state.ruleForm.update_time" type="date" placeholder="修改时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="状态" prop="status">
							<el-input-number v-model="state.ruleForm.status" placeholder="请输入状态" clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="是否已删除" prop="is_deleted">
							<el-input-number v-model="state.ruleForm.is_deleted" placeholder="请输入是否已删除" clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务编号" prop="task_code">
							<el-input v-model="state.ruleForm.task_code" placeholder="请输入任务编号" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="指派状态" prop="assign_status">
							<el-input v-model="state.ruleForm.assign_status" placeholder="请输入指派状态" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务来源" prop="task_source">
							<el-input v-model="state.ruleForm.task_source" placeholder="请输入任务来源" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务状态" prop="task_status">
							<el-input v-model="state.ruleForm.task_status" placeholder="请输入任务状态" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="复核状态" prop="review_status">
							<el-input v-model="state.ruleForm.review_status" placeholder="请输入复核状态" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务结果" prop="task_result">
							<el-input v-model="state.ruleForm.task_result" placeholder="请输入任务结果" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="处置结果" prop="dispose_result">
							<el-input v-model="state.ruleForm.dispose_result" placeholder="请输入处置结果" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="超时状态" prop="overtime_status">
							<el-input v-model="state.ruleForm.overtime_status" placeholder="请输入超时状态" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="计划" prop="plan_id">
							<el-input v-model="state.ruleForm.plan_id" placeholder="请输入计划" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="计划编号" prop="plan_code">
							<el-input v-model="state.ruleForm.plan_code" placeholder="请输入计划编号" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="计划名称" prop="plan_name">
							<el-input v-model="state.ruleForm.plan_name" placeholder="请输入计划名称" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="对象" prop="object_id">
							<el-input v-model="state.ruleForm.object_id" placeholder="请输入对象" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="对象编码" prop="object_code">
							<el-input v-model="state.ruleForm.object_code" placeholder="请输入对象编码" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="对象名称" prop="object_name">
							<el-input v-model="state.ruleForm.object_name" placeholder="请输入对象名称" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="对象类型" prop="object_type">
							<el-input v-model="state.ruleForm.object_type" placeholder="请输入对象类型" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="模板类型" prop="type">
							<el-input v-model="state.ruleForm.type" placeholder="请输入模板类型" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="模板" prop="template_id">
							<el-input v-model="state.ruleForm.template_id" placeholder="请输入模板" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="模板编码" prop="template_code">
							<el-input v-model="state.ruleForm.template_code" placeholder="请输入模板编码" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="模板名称" prop="template_name">
							<el-input v-model="state.ruleForm.template_name" placeholder="请输入模板名称" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务开始时间" prop="task_start_time">
							<el-date-picker v-model="state.ruleForm.task_start_time" type="date" placeholder="任务开始时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务结束时间" prop="task_end_time">
							<el-date-picker v-model="state.ruleForm.task_end_time" type="date" placeholder="任务结束时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务类型" prop="task_type">
							<el-input v-model="state.ruleForm.task_type" placeholder="请输入任务类型" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="计划开始时间" prop="plan_start_time">
							<el-date-picker v-model="state.ruleForm.plan_start_time" type="date" placeholder="计划开始时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="计划结束时间" prop="plan_end_time">
							<el-date-picker v-model="state.ruleForm.plan_end_time" type="date" placeholder="计划结束时间" />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="标准用时" prop="standard_time">
							<el-input v-model="state.ruleForm.standard_time" placeholder="请输入标准用时" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="实际用时" prop="actual_time">
							<el-input v-model="state.ruleForm.actual_time" placeholder="请输入实际用时" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="接收形式(0员工，1岗位，2班组)" prop="receive_type">
							<el-input v-model="state.ruleForm.receive_type" placeholder="请输入接收形式(0员工，1岗位，2班组)" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="班组" prop="receive_group">
							<el-input v-model="state.ruleForm.receive_group" placeholder="请输入班组" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="员工" prop="receive_user">
							<el-input v-model="state.ruleForm.receive_user" placeholder="请输入员工" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="关闭原因" prop="shutdown_reason">
							<el-input v-model="state.ruleForm.shutdown_reason" placeholder="请输入关闭原因" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="文件" prop="file">
							<el-input v-model="state.ruleForm.file" placeholder="请输入文件" maxlength="500" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="复核说明" prop="review_info">
							<el-input v-model="state.ruleForm.review_info" placeholder="请输入复核说明" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="任务分发类型" prop="task_distribute_type">
							<el-input v-model="state.ruleForm.task_distribute_type" placeholder="请输入任务分发类型" maxlength="255" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="异常类型" prop="err_type">
							<el-input v-model="state.ruleForm.err_type" placeholder="请输入异常类型" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="异常类型分项" prop="err_subitem">
							<el-input v-model="state.ruleForm.err_subitem" placeholder="请输入异常类型分项" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="异常等级" prop="err_lv">
							<el-input v-model="state.ruleForm.err_lv" placeholder="请输入异常等级" maxlength="0" show-word-limit clearable />
							
						</el-form-item>
						
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
<script lang="ts" setup>
    import { ref,onMounted, reactive } from "vue";
	import { ElMessage } from "element-plus";
	import type { FormRules } from "element-plus";
	import { addEqTask, updateEqTask, detailEqTask } from "/@/api/cqds/eqTask";
	import { pageEqTask, deleteEqTask } from '/@/api/cqds/eqTask';

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

	//父级传递来的参数
	var props = defineProps({
		title: {
		type: String,
		default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
    const state = reactive({
    isShowDialog: false,
    ruleForm: {} as any,
});

	//自行添加其他规则
	const rules = ref<FormRules>({
	});

	// 页面加载时
	onMounted(() => {

	});

	// 打开弹窗
	const openDialog = async (row: any) => {
		// state.ruleForm = JSON.parse(JSON.stringify(row));
		// 改用detail获取最新数据来编辑
		let rowData = JSON.parse(JSON.stringify(row));
		if (rowData.id)
			state.ruleForm = (await detailEqTask(rowData.id)).data.result;
		else
			state.ruleForm = rowData;
		state.isShowDialog = true;
	};

	// 关闭弹窗
	const closeDialog = () => {
		emit("reloadTable");
		state.isShowDialog = false;
	};

	// 取消
	const cancel = () => {
		state.isShowDialog = false;
	};

	// 提交
	const submit = async () => {
		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
			if (isValid) {
				let values = state.ruleForm;
				if (state.ruleForm.id == undefined || state.ruleForm.id == null || state.ruleForm.id == "" || state.ruleForm.id == 0) {
					await addEqTask(values);
				} else {
					await updateEqTask(values);
				}
				closeDialog();
			} else {
				ElMessage({
					message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
					type: "error",
				});
			}
		});
	};






	//将属性或者函数暴露给父组件
	defineExpose({ openDialog });
</script>




