<template>
|
<view class="emergency-plan-detail">
|
<!-- 使用通用页面头部组件 -->
|
<PageHeader :title="isEdit ? '编辑应急预案' : '新增应急预案'"
|
@back="goBack" />
|
<!-- 表单区域 -->
|
<u-form :model="form"
|
label-width="110"
|
:rules="rules"
|
ref="formRef">
|
<!-- 应急预案编码 -->
|
<u-form-item label="应急预案编码"
|
border-bottom
|
required
|
prop="planCode">
|
<up-input v-model="form.planCode"
|
placeholder="请输入应急预案编码"
|
clearable />
|
</u-form-item>
|
<!-- 应急预案名称 -->
|
<u-form-item label="应急预案名称"
|
required
|
border-bottom
|
prop="planName">
|
<up-input v-model="form.planName"
|
placeholder="请输入应急预案名称"
|
clearable />
|
</u-form-item>
|
<!-- 发布生效时间 -->
|
<u-form-item label="发布生效时间"
|
required
|
border-bottom
|
prop="publishTime">
|
<up-input v-model="form.publishTime"
|
placeholder="请选择发布生效时间"
|
readonly
|
@click="showTime = true" />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showTime = true"></up-icon>
|
</template>
|
</u-form-item>
|
<!-- 预案类型 -->
|
<u-form-item label="预案类型"
|
prop="planType"
|
required
|
border-bottom>
|
<u-input v-model="emergencyPlanTypeLabel"
|
placeholder="请选择预案类型"
|
@click="showPlanTypeActionSheet = true"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showPlanTypeActionSheet = true"></up-icon>
|
</template>
|
</u-form-item>
|
<u-form-item label="核心责任人"
|
prop="coreResponsorUserId"
|
required
|
border-bottom>
|
<u-input v-model="form.coreResponsorUserName"
|
placeholder="请选择核心责任人"
|
@click="showUserActionSheet = true"
|
readonly />
|
<template #right>
|
<up-icon name="arrow-right"
|
@click="showUserActionSheet = true"></up-icon>
|
</template>
|
</u-form-item>
|
<!-- 备注 -->
|
<u-form-item label="备注"
|
prop="remark">
|
<up-input v-model="form.remark"
|
placeholder="请输入备注"
|
type="textarea"
|
rows="3"
|
clearable />
|
</u-form-item>
|
<!-- 适用范围 -->
|
<u-form-item label="适用范围"
|
required
|
prop="applyScope">
|
<view class="checkbox-group">
|
<u-checkbox-group v-model="form.applyScope"
|
@change="handleApplyScopeChange">
|
<u-checkbox shape="circle"
|
size="32rpx"
|
class="checkbox-item"
|
v-for="(item, index) in applyScopeOptions"
|
:key="index"
|
:label="item.label"
|
:name="item.value">
|
</u-checkbox>
|
</u-checkbox-group>
|
</view>
|
</u-form-item>
|
<!-- 应急处置步骤 -->
|
<view class="exec-steps-container">
|
<view class="steps-header">
|
<text class="steps-title">处置步骤列表</text>
|
<text class="steps-count">共 {{ execStepsList.length }} 个步骤</text>
|
</view>
|
<view class="steps-list">
|
<view v-for="(step, index) in execStepsList"
|
:key="index"
|
class="exec-step-item">
|
<view class="delete-btn"
|
@click="removeExecStep(index)">
|
<u-icon name="close"
|
color="#fff"
|
size="16" />
|
</view>
|
<view class="step-number">
|
{{ index + 1 }}
|
</view>
|
<view class="step-content">
|
<view class="step-row">
|
<text class="step-label">步骤名称:</text>
|
<u-textarea v-model="step.step"
|
placeholder="请输入步骤名称"
|
clearable
|
border-bottom
|
class="step-input" />
|
</view>
|
<view class="step-row">
|
<text class="step-label">处置措施:</text>
|
<u-textarea v-model="step.description"
|
placeholder="请输入具体的应急处置措施"
|
type="textarea"
|
clearable
|
class="step-textarea" />
|
</view>
|
</view>
|
</view>
|
</view>
|
<u-button type="primary"
|
@click="addExecStep"
|
class="add-step-btn">
|
<text>添加步骤</text>
|
</u-button>
|
</view>
|
</u-form>
|
<!-- 发布生效时间选择器 -->
|
<up-datetime-picker :show="showTime"
|
v-model="currentTime"
|
@confirm="handleDateConfirm"
|
@cancel="showTime = false"
|
mode="date" />
|
<!--预案类型选择器 -->
|
<up-action-sheet :show="showPlanTypeActionSheet"
|
:actions="emergencyPlanTypeOptions"
|
@select="handlePlanTypeConfirm"
|
title="选择预案类型" />
|
<!--核心责任人选择器 -->
|
<up-action-sheet :show="showUserActionSheet"
|
:actions="userList"
|
@select="handleUserConfirm"
|
title="选择核心责任人" />
|
</view>
|
<!-- 底部按钮 -->
|
<view class="bottom-buttons">
|
<u-button type="default"
|
size="default"
|
@click="goBack"
|
class="bottom-btn">
|
取消
|
</u-button>
|
<u-button type="primary"
|
size="default"
|
@click="submitForm"
|
class="bottom-btn">
|
保存
|
</u-button>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, onMounted, computed } from "vue";
|
import { onShow } from "@dcloudio/uni-app";
|
import PageHeader from "@/components/PageHeader.vue";
|
import {
|
safeContingencyPlanAdd,
|
safeContingencyPlanUpdate,
|
} from "@/api/safeProduction/emergencyPlanReview";
|
import { userListNoPage } from "@/api/system/user";
|
import { useDict } from "@/utils/dict";
|
import dayjs from "dayjs";
|
// 替换 toast 方法
|
defineOptions({ name: "emergency-plan-detail" });
|
const showToast = message => {
|
uni.showToast({
|
title: message,
|
icon: "none",
|
});
|
};
|
|
// 表单引用
|
const formRef = ref();
|
|
// 表单数据
|
const form = ref({
|
id: "",
|
planCode: "",
|
planName: "",
|
publishTime: "",
|
planType: "",
|
coreResponsorUserId: "",
|
coreResponsorUserName: "",
|
remark: "",
|
applyScope: [],
|
execSteps: "",
|
});
|
|
// 应急处置步骤列表
|
const execStepsList = ref([]);
|
|
// 日期范围
|
const minDate = new Date("2000-01-01");
|
const maxDate = new Date("2030-12-31");
|
const currentTime = ref(Date.now());
|
// 用户列表
|
const userList = ref([]);
|
|
// 应急预案类型选项
|
const { emergency_plan_type } = useDict("emergency_plan_type");
|
const emergencyPlanTypeOptions = computed(() => {
|
return (
|
emergency_plan_type?.value.map(item => ({
|
value: item.value,
|
name: item.label,
|
})) || []
|
);
|
});
|
|
// 应急预案类型标签
|
const emergencyPlanTypeLabel = ref("");
|
|
// 适用范围选项
|
const applyScopeOptions = [
|
{ value: "all", label: "全体员工" },
|
{ value: "manager", label: "管理层" },
|
{ value: "hr", label: "人事部门" },
|
{ value: "finance", label: "财务部门" },
|
{ value: "tech", label: "技术部门" },
|
];
|
|
// 是否为编辑模式
|
const isEdit = ref(false);
|
|
// ActionSheet 显示状态
|
const showPlanTypeActionSheet = ref(false);
|
const showUserActionSheet = ref(false);
|
const showTime = ref(false);
|
|
// 初始化数据
|
const initData = () => {
|
const emergencyPlan = uni.getStorageSync("emergencyPlan") || {};
|
if (emergencyPlan.id) {
|
// 编辑模式
|
isEdit.value = true;
|
form.value = {
|
id: emergencyPlan.id,
|
planCode: emergencyPlan.planCode || "",
|
planName: emergencyPlan.planName || "",
|
publishTime: emergencyPlan.publishTime || "",
|
planType: emergencyPlan.planType || "",
|
coreResponsorUserId: emergencyPlan.coreResponsorUserId || "",
|
coreResponsorUserName: emergencyPlan.coreResponsorUserName || "",
|
remark: emergencyPlan.remark || "",
|
applyScope: emergencyPlan.applyScope
|
? emergencyPlan.applyScope.split(",")
|
: [],
|
execSteps: emergencyPlan.execSteps || "",
|
};
|
currentTime.value = new Date(emergencyPlan.publishTime).getTime();
|
// 设置预案类型标签
|
const planTypeItem = emergencyPlanTypeOptions.value.find(
|
item => item.value === emergencyPlan.planType
|
);
|
emergencyPlanTypeLabel.value = planTypeItem ? planTypeItem.name : "";
|
console.log(form.value.applyScope, form.value.applyScope);
|
// 初始化应急处置步骤
|
initExecSteps(emergencyPlan.execSteps);
|
} else {
|
// 新增模式
|
isEdit.value = false;
|
form.value = {
|
planCode: "",
|
planName: "",
|
publishTime: new Date().toISOString().split("T")[0],
|
planType: "",
|
coreResponsorUserId: "",
|
coreResponsorUserName: "",
|
remark: "",
|
applyScope: [],
|
execSteps: "",
|
};
|
emergencyPlanTypeLabel.value = "";
|
execStepsList.value = [];
|
addExecStep();
|
}
|
};
|
const handleApplyScopeChange = e => {
|
// form.value.applyScope = e;
|
console.log(e, "e");
|
console.log(form.value.applyScope, "form.value.applyScope");
|
};
|
|
// 初始化应急处置步骤
|
const initExecSteps = execSteps => {
|
if (execSteps) {
|
try {
|
execStepsList.value = JSON.parse(execSteps);
|
} catch (e) {
|
execStepsList.value = [];
|
}
|
} else {
|
execStepsList.value = [];
|
}
|
if (execStepsList.value.length === 0) {
|
addExecStep();
|
}
|
};
|
|
// 添加应急处置步骤
|
const addExecStep = () => {
|
const stepNumber = execStepsList.value.length + 1;
|
execStepsList.value.push({
|
step: `步骤${stepNumber}`,
|
description: "",
|
});
|
};
|
|
// 删除应急处置步骤
|
const removeExecStep = index => {
|
if (execStepsList.value.length > 1) {
|
execStepsList.value.splice(index, 1);
|
} else {
|
showToast("至少保留一个步骤");
|
}
|
};
|
|
// 获取用户列表
|
const getUserList = () => {
|
userListNoPage()
|
.then(res => {
|
userList.value = res.data.map(item => ({
|
value: item.userId,
|
name: item.nickName,
|
}));
|
})
|
.catch(() => {
|
showToast("获取用户列表失败");
|
});
|
};
|
|
// 日期选择确认
|
const handleDateConfirm = e => {
|
form.value.publishTime = dayjs(e.value).format("YYYY-MM-DD");
|
showTime.value = false;
|
};
|
|
// 预案类型选择确认
|
const handlePlanTypeConfirm = e => {
|
form.value.planType = e.value;
|
const selectedType = emergencyPlanTypeOptions.value.find(
|
item => item.value === e.value
|
);
|
if (selectedType) {
|
emergencyPlanTypeLabel.value = selectedType.name;
|
}
|
showPlanTypeActionSheet.value = false;
|
};
|
|
// 用户选择确认
|
const handleUserConfirm = e => {
|
form.value.coreResponsorUserId = e.value;
|
const selectedUser = userList.value.find(user => user.value === e.value);
|
if (selectedUser) {
|
form.value.coreResponsorUserName = selectedUser.name;
|
}
|
showUserActionSheet.value = false;
|
};
|
|
// 返回上一页
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
// 表单验证规则
|
const rules = {
|
planCode: [
|
{
|
required: true,
|
message: "请输入应急预案编码",
|
trigger: ["submit", "blur"],
|
},
|
],
|
planName: [
|
{
|
required: true,
|
message: "请输入应急预案名称",
|
trigger: ["submit", "blur"],
|
},
|
],
|
publishTime: [
|
{
|
required: true,
|
message: "请选择发布生效时间",
|
trigger: ["submit", "change"],
|
},
|
],
|
planType: [
|
{
|
required: true,
|
message: "请选择预案类型",
|
trigger: ["submit", "change"],
|
},
|
],
|
coreResponsorUserId: [
|
{
|
required: true,
|
message: "请选择核心责任人",
|
trigger: ["submit", "change"],
|
},
|
],
|
applyScope: [
|
{
|
required: true,
|
message: "请选择适用范围",
|
trigger: ["submit", "change"],
|
},
|
],
|
};
|
|
// 提交表单
|
const submitForm = async () => {
|
// 验证表单必填项
|
if (!formRef.value) return;
|
|
const valid = await formRef.value.validate();
|
if (!valid) {
|
return;
|
}
|
|
// 验证应急处置步骤
|
for (let i = 0; i < execStepsList.value.length; i++) {
|
const step = execStepsList.value[i];
|
if (!step.step || !step.step.trim()) {
|
showToast(`第${i + 1}条步骤的"步骤"不能为空`);
|
return;
|
}
|
if (!step.description || !step.description.trim()) {
|
showToast(`第${i + 1}条步骤的"措施"不能为空`);
|
return;
|
}
|
}
|
|
// 将应急处置步骤转换为JSON字符串
|
form.value.execSteps = JSON.stringify(execStepsList.value);
|
|
// 处理适用范围
|
form.value.applyScope = form.value.applyScope.join(",");
|
|
showLoadingToast("保存中...");
|
|
try {
|
if (isEdit.value) {
|
// 编辑模式
|
const res = await safeContingencyPlanUpdate(form.value);
|
if (res.code === 200) {
|
showToast("更新成功");
|
setTimeout(() => {
|
uni.navigateBack();
|
}, 1000);
|
} else {
|
showToast(res.msg || "更新失败");
|
}
|
} else {
|
// 新增模式
|
const res = await safeContingencyPlanAdd(form.value);
|
if (res.code === 200) {
|
showToast("添加成功");
|
setTimeout(() => {
|
uni.navigateBack();
|
}, 1000);
|
} else {
|
showToast(res.msg || "添加失败");
|
}
|
}
|
} catch (error) {
|
console.error("提交失败:", error);
|
showToast("提交失败,请重试");
|
} finally {
|
closeToast();
|
}
|
};
|
|
// 显示加载提示
|
const showLoadingToast = message => {
|
uni.showLoading({
|
title: message,
|
mask: true,
|
});
|
};
|
|
// 关闭提示
|
const closeToast = () => {
|
uni.hideLoading();
|
};
|
|
onMounted(() => {
|
initData();
|
getUserList();
|
});
|
|
onShow(() => {
|
initData();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
.emergency-plan-detail {
|
min-height: 100vh;
|
background: #f8f9fa;
|
padding-bottom: 100px;
|
}
|
|
.form-section {
|
}
|
|
.checkbox-group {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 16px;
|
}
|
|
.checkbox-item {
|
margin-right: 16px;
|
}
|
|
.select-container {
|
position: relative;
|
width: 100%;
|
}
|
|
.select-container .up-input {
|
width: 100%;
|
border: 1px solid #e4e7ed;
|
border-radius: 8px;
|
padding: 12px 16px;
|
background-color: #ffffff;
|
}
|
|
.exec-steps-container {
|
padding: 20px;
|
background-color: #fff;
|
}
|
|
.steps-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 20px;
|
padding-bottom: 12px;
|
border-bottom: 1px solid #e4e7ed;
|
}
|
|
.steps-title {
|
font-size: 16px;
|
font-weight: 600;
|
color: #303133;
|
}
|
|
.steps-count {
|
font-size: 14px;
|
color: #909399;
|
}
|
|
.steps-list {
|
margin-bottom: 20px;
|
}
|
|
.exec-step-item {
|
position: relative;
|
display: flex;
|
margin-bottom: 16px;
|
padding: 16px;
|
background-color: #ffffff;
|
border: 1px solid #e4e7ed;
|
border-radius: 8px;
|
transition: all 0.3s ease;
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
|
}
|
|
.exec-step-item:hover {
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
border-color: #409eff;
|
transform: translateY(-1px);
|
}
|
|
.delete-btn {
|
position: absolute;
|
top: -25rpx;
|
right: -25rpx;
|
width: 50rpx;
|
height: 50rpx;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
text-align: center;
|
font-size: 20px;
|
border-radius: 50%;
|
background-color: red;
|
border: none;
|
z-index: 10;
|
}
|
|
.delete-btn:hover {
|
transform: scale(1.1);
|
box-shadow: 0 3px 6px rgba(245, 108, 108, 0.4);
|
}
|
|
.step-number {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
width: 32px;
|
height: 32px;
|
margin-right: 16px;
|
background-color: #ecf5ff;
|
color: #409eff;
|
font-size: 14px;
|
font-weight: 600;
|
border-radius: 50%;
|
flex-shrink: 0;
|
}
|
|
.step-content {
|
flex: 1;
|
min-width: 0;
|
}
|
|
.step-row {
|
display: flex;
|
align-items: flex-start;
|
margin-bottom: 12px;
|
}
|
|
.step-row:last-child {
|
margin-bottom: 0;
|
}
|
|
.step-label {
|
display: inline-block;
|
width: 80px;
|
font-size: 14px;
|
color: #606266;
|
margin-right: 12px;
|
flex-shrink: 0;
|
line-height: 36px;
|
}
|
|
.step-input {
|
flex: 1;
|
min-width: 0;
|
}
|
|
.step-input input {
|
font-size: 14px;
|
color: #303133;
|
}
|
|
.step-textarea {
|
flex: 1;
|
min-width: 0;
|
}
|
|
.step-textarea textarea {
|
font-size: 14px;
|
color: #303133;
|
min-height: 80px;
|
line-height: 1.5;
|
}
|
|
.add-step-btn {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
width: 100%;
|
height: 44px;
|
line-height: 44px;
|
font-size: 14px;
|
border-radius: 8px;
|
transition: all 0.3s ease;
|
gap: 8px;
|
}
|
|
.add-step-btn:hover {
|
transform: translateY(-1px);
|
box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
|
}
|
|
.add-step-btn text {
|
font-size: 14px;
|
}
|
|
.bottom-buttons {
|
position: fixed;
|
bottom: 0;
|
left: 0;
|
right: 0;
|
display: flex;
|
padding: 16px 20px;
|
background: #ffffff;
|
border-top: 1px solid #f0f0f0;
|
gap: 16px;
|
}
|
|
.bottom-btn {
|
flex: 1;
|
}
|
</style>
|