From 7cd546b127d029cefef0ea9735ba69ffdae14e1e Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 29 七月 2026 15:36:54 +0800
Subject: [PATCH] fix: 新增应急预案的适用范围部门从接口获取

---
 src/views/safeProduction/emergencyPlanReview/index.vue |   85 ++++++++++++++++++++++++++++++------------
 1 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/src/views/safeProduction/emergencyPlanReview/index.vue b/src/views/safeProduction/emergencyPlanReview/index.vue
index cd3c020..c6ad69b 100644
--- a/src/views/safeProduction/emergencyPlanReview/index.vue
+++ b/src/views/safeProduction/emergencyPlanReview/index.vue
@@ -122,12 +122,13 @@
         </el-row>
         <el-form-item label="閫傜敤鑼冨洿锛�"
                       prop="applyScope">
-          <el-checkbox-group v-model="form.applyScope">
-            <el-checkbox label="all">鍏ㄤ綋鍛樺伐</el-checkbox>
-            <el-checkbox label="manager">绠$悊灞�</el-checkbox>
-            <el-checkbox label="hr">浜轰簨閮ㄩ棬</el-checkbox>
-            <el-checkbox label="finance">璐㈠姟閮ㄩ棬</el-checkbox>
-            <el-checkbox label="tech">鎶�鏈儴闂�</el-checkbox>
+          <el-checkbox-group v-model="form.applyScope"
+                             class="apply-scope-checkbox-group">
+            <el-checkbox v-for="dept in applyScopeOptions"
+                         :key="dept.deptId"
+                         :value="String(dept.deptId)">
+              {{ dept.deptName }}
+            </el-checkbox>
           </el-checkbox-group>
         </el-form-item>
         <el-form-item label="搴旀�ュ缃楠わ細"
@@ -202,11 +203,11 @@
         <div class="detail-section">
           <h4>閫傜敤鑼冨洿</h4>
           <div class="key-points">
-            <el-tag v-for="(point, index) in currentKnowledge.applyScope.split(',')"
-                    :key="index"
+            <el-tag v-for="(scope, index) in getApplyScopeTags(currentKnowledge)"
+                    :key="`${scope.value}-${index}`"
                     type="primary"
                     style="margin-right: 8px; margin-bottom: 8px;">
-              {{ getApplyScopeLabel(point.trim()) }}
+              {{ scope.label }}
             </el-tag>
           </div>
         </div>
@@ -250,6 +251,7 @@
   import { ElMessage, ElMessageBox } from "element-plus";
   import PIMTable from "@/components/PIMTable/PIMTable.vue";
   import { userListNoPage } from "@/api/system/user.js";
+  import { listDept } from "@/api/system/dept.js";
   import {
     safeContingencyPlanListPage,
     safeContingencyPlanAdd,
@@ -326,6 +328,13 @@
   // 琛ㄥ崟寮曠敤
   const formRef = ref();
   const execStepsList = ref([]);
+  const applyScopeOptions = ref([]);
+  const applyScopeNameMap = computed(() => {
+    return applyScopeOptions.value.reduce((map, dept) => {
+      map[String(dept.deptId)] = dept.deptName;
+      return map;
+    }, {});
+  });
 
   // 琛ㄦ牸鍒楅厤缃�
   const tableColumn = ref([
@@ -404,6 +413,7 @@
     userListNoPage().then(res => {
       userList.value = res.data;
     });
+    loadApplyScopeOptions();
     getList();
     startAutoRefresh();
   });
@@ -437,6 +447,22 @@
     } else {
       execStepsList.value = [];
     }
+  };
+
+  const loadApplyScopeOptions = () => {
+    listDept({ status: "0" }).then(res => {
+      applyScopeOptions.value = res.data || [];
+    });
+  };
+
+  const parseApplyScope = scope => {
+    if (Array.isArray(scope)) {
+      return scope.map(item => String(item)).filter(Boolean);
+    }
+    return String(scope || "")
+      .split(",")
+      .map(item => item.trim())
+      .filter(Boolean);
   };
   // 寮�濮嬭嚜鍔ㄥ埛鏂�
   const startAutoRefresh = () => {
@@ -483,6 +509,7 @@
       dialogTitle.value = "鏂板搴旀�ラ妗�";
       // 閲嶇疆琛ㄥ崟
       Object.assign(form.value, {
+        id: undefined,
         planCode: "", // 棰勬缂栧彿
         applyScope: [], // 閫傜敤鑼冨洿
         planType: "", // 棰勬绫诲瀷
@@ -499,7 +526,7 @@
       Object.assign(form.value, {
         id: row.id,
         planCode: row.planCode, // 棰勬缂栧彿
-        applyScope: row.applyScope ? row.applyScope.split(",") : [], // 閫傜敤鑼冨洿
+        applyScope: parseApplyScope(row.applyScope), // 閫傜敤鑼冨洿
         planType: row.planType, // 棰勬绫诲瀷
         planName: row.planName, // 棰勬鍚嶇О
         publishTime: row.publishTime, // 鍙戝竷鏃堕棿
@@ -519,14 +546,13 @@
     viewDialogVisible.value = true;
   };
   const getApplyScopeLabel = scope => {
-    const scopeMap = {
-      all: "鍏ㄤ綋鍛樺伐",
-      manager: "绠$悊灞�",
-      hr: "浜轰簨閮ㄩ棬",
-      finance: "璐㈠姟閮ㄩ棬",
-      tech: "鎶�鏈儴闂�",
-    };
-    return scopeMap[scope] || scope;
+    return applyScopeNameMap.value[String(scope)] || scope;
+  };
+  const getApplyScopeTags = row => {
+    return parseApplyScope(row?.applyScope).map((scope, index) => ({
+      value: scope,
+      label: getApplyScopeLabel(scope),
+    }));
   };
 
   // 鑾峰彇绫诲瀷鏍囩绫诲瀷
@@ -614,12 +640,14 @@
         }
       }
 
-      // 灏嗗簲鎬ュ缃楠よ浆鎹负JSON瀛楃涓�
-      form.value.execSteps = JSON.stringify(execStepsList.value);
+      const submitData = {
+        ...form.value,
+        applyScope: form.value.applyScope.join(","),
+        execSteps: JSON.stringify(execStepsList.value),
+      };
       if (dialogType.value === "add") {
         // 鏂板搴旀�ラ妗�
-        form.value.applyScope = form.value.applyScope.join(",");
-        safeContingencyPlanAdd({ ...form.value })
+        safeContingencyPlanAdd(submitData)
           .then(res => {
             if (res.code == 200) {
               ElMessage.success("娣诲姞鎴愬姛");
@@ -631,8 +659,7 @@
             ElMessage.error(err.msg);
           });
       } else {
-        form.value.applyScope = form.value.applyScope.join(",");
-        safeContingencyPlanUpdate({ ...form.value })
+        safeContingencyPlanUpdate(submitData)
           .then(res => {
             if (res.code == 200) {
               ElMessage.success("鏇存柊鎴愬姛");
@@ -752,6 +779,16 @@
     gap: 8px;
   }
 
+  .apply-scope-checkbox-group {
+    display: flex;
+    flex-wrap: wrap;
+    gap: 8px 16px;
+  }
+
+  .apply-scope-checkbox-group :deep(.el-checkbox) {
+    margin-right: 0;
+  }
+
   .usage-stats {
     margin-top: 16px;
   }

--
Gitblit v1.9.3