From d6aa663043a23bb37f1c712a19424690c5a2062f Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期二, 03 十一月 2026 09:35:12 +0800
Subject: [PATCH] nhfy@0230

---
 src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue |  410 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 393 insertions(+), 17 deletions(-)

diff --git a/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue b/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
index c299b30..d8687d5 100644
--- a/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
+++ b/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
@@ -389,6 +389,7 @@
 } from "@/api/system/user";
 import ExcelJS from "exceljs";
 import { saveAs } from "file-saver";
+import { getTaskservelist } from "@/api/AiCentre/SingleTask";
 import SeedetailsDialog from "./components/SeedetailsDialog.vue";
 import TopicDialog from "./components/TopicDialog.vue";
 
@@ -397,6 +398,13 @@
   components: {
     SeedetailsDialog,
     TopicDialog,
+  },
+  props: {
+    // 鏄惁鍦ㄩ《閮ㄧ敓鎴愭偅鑰呰〃鍗� / 闂璇︽儏鍒嗘瀽 tab锛堜粎婊℃剰搴︾粺璁′富椤靛紑鍚級
+    showAnalysisTabs: {
+      type: Boolean,
+      default: false,
+    },
   },
   data() {
     return {
@@ -458,6 +466,10 @@
       // 鍔犺浇鐘舵��
       loading: false,
       orgname: "",
+      // 宸插畬鎴愭槑缁嗚姹傚簭鍙凤紝閬垮厤蹇�熷垏鎹㈢瓫閫夋椂鏃ц姹傝鐩栨柊缁撴灉
+      completedRequestSeq: 0,
+      // 闂璇︽儏璇锋眰搴忓彿
+      questionRequestSeq: 0,
 
       // 閫変腑鐨勮
       ids: [],
@@ -522,12 +534,21 @@
     isInHospitalSatisfaction() {
       return this.satisfactionScope !== "leave";
     },
+    // patItem 鎺ュ彛鐨� serviceType 鍙帴鏀跺崟涓�硷紝澶氶�夋椂鍙栫涓�涓�
+    currentServiceType() {
+      const value = this.queryParams.serviceType;
+      const first = Array.isArray(value) ? value[0] : value;
+      return first || 6;
+    },
   },
 
   created() {
     this.orgname = localStorage.getItem("orgname");
 
     this.initData();
+    // 椤堕儴鎮h�呰〃鍗� / 闂璇︽儏鍒嗘瀽 tab锛氶粯璁ゆ寜褰撳墠缁熻鍙e緞鍔犺浇涓�娆�
+    this.maybeRefreshCompletedGroups();
+    this.maybeRefreshQuestionDetails();
   },
 
   methods: {
@@ -595,41 +616,41 @@
           // 鐥呭尯缁熻
           let wardCodes = params.leavehospitaldistrictcodes || [];
           if (wardCodes.includes("all")) {
-            // 濡傛灉閫夋嫨浜�"鍏ㄩ儴"锛屽垯浣跨敤褰撳墠鐢ㄦ埛鎵�灞炵殑鍏ㄩ儴鐥呭尯
-            wardCodes = (this.$store.getters.belongWards || []).map(
-              (ward) => ward.districtCode
-            );
+            // 閫夋嫨"鍏ㄩ儴"鏃朵笉鍔犵梾鍖洪檺鍒讹紝鏌ュ叏閮ㄧ梾鍖�
+            wardCodes = [];
           }
           delete params.leavehospitaldistrictcodes;
           delete params.hospitaldistrictcodes;
           delete params.deptcodes;
           delete params.leaveldeptcodes;
           delete params.hospitaldeptcodes;
-          if (this.isInHospitalSatisfaction) {
-            params.hospitaldistrictcodes = wardCodes;
-          } else {
-            params.leavehospitaldistrictcodes = wardCodes;
+          if (wardCodes.length) {
+            if (this.isInHospitalSatisfaction) {
+              params.hospitaldistrictcodes = wardCodes;
+            } else {
+              params.leavehospitaldistrictcodes = wardCodes;
+            }
           }
         } else if (params.statisticaltype == 2) {
           // 绉戝缁熻
           let deptCodes = params.deptcodes || [];
           if (deptCodes.includes("all")) {
-            // 濡傛灉閫夋嫨浜�"鍏ㄩ儴"锛屽垯绉婚櫎"all"鍊�
+            // 閫夋嫨"鍏ㄩ儴"鏃朵笉鍔犵瀹ら檺鍒讹紝鏌ュ叏閮ㄧ瀹�
+            deptCodes = [];
+          } else {
             deptCodes = deptCodes.filter((item) => item !== "all");
-            // 濡傛灉闇�瑕佷紶鎵�鏈夌瀹や唬鐮侊紝鍙互浠巗tore涓幏鍙�
-            deptCodes = (this.$store.getters.belongDepts || []).map(
-              (dept) => dept.deptCode
-            );
           }
           delete params.deptcodes;
           delete params.leaveldeptcodes;
           delete params.hospitaldeptcodes;
           delete params.leavehospitaldistrictcodes;
           delete params.hospitaldistrictcodes;
-          if (this.isInHospitalSatisfaction) {
-            params.hospitaldeptcodes = deptCodes;
-          } else {
-            params.leaveldeptcodes = deptCodes;
+          if (deptCodes.length) {
+            if (this.isInHospitalSatisfaction) {
+              params.hospitaldeptcodes = deptCodes;
+            } else {
+              params.leaveldeptcodes = deptCodes;
+            }
           }
         }
 
@@ -843,18 +864,371 @@
       }
       this.queryParams.pageNum = 1;
       this.getList();
+      this.maybeRefreshCompletedGroups();
+      this.maybeRefreshQuestionDetails();
     },
 
     // 澶勭悊鏌ヨ
     handleQuery() {
       this.queryParams.pageNum = 1;
       this.getList();
+      this.maybeRefreshCompletedGroups();
+      this.maybeRefreshQuestionDetails();
     },
 
     // 鍒囨崲婊℃剰搴︾被鍨嬶紙绂婚櫌/鍦ㄩ櫌锛夊悗閲嶆柊鏌ヨ
     handleSatisfactionScopeChange() {
       this.queryParams.pageNum = 1;
       this.getList();
+      this.maybeRefreshCompletedGroups();
+      this.maybeRefreshQuestionDetails();
+    },
+
+    /**
+     * 椤堕儴銆屽凡瀹屾垚鎮h�呮槑缁嗐�峵ab 鏁版嵁
+     * 缁村害娌跨敤涓嬫柟銆岀粺璁$被鍨嬨�嶏細鐥呭尯缁熻 -> 鎸夌梾鍖哄垎缁勶紱绉戝缁熻 -> 鎸夌瀹ゅ垎缁�
+     * 鏃堕棿娌跨敤涓嬫柟銆岄殢璁挎椂闂淬�嶏紝鐘舵�佸浐瀹氫负宸插畬鎴�
+     */
+    maybeRefreshCompletedGroups() {
+      if (this.showAnalysisTabs) {
+        this.refreshCompletedGroups();
+      }
+    },
+
+    async refreshCompletedGroups() {
+      const seq = ++this.completedRequestSeq;
+      const payload = this.buildCompletedPayload();
+
+      // 娌℃湁绉戝/鐥呭尯鏉冮檺鏃朵笉鍙戣捣璇锋眰锛岄伩鍏嶆妸鍏ㄩ噺鏁版嵁鏌ュ嚭鏉�
+      if (!payload) {
+        this.emitCompletedGroups([], seq);
+        return;
+      }
+
+      this.$emit("completed-rows-change", {
+        ...this.buildCompletedMeta(),
+        loading: true,
+      });
+
+      try {
+        const res = await getTaskservelist(payload);
+        if (seq !== this.completedRequestSeq) return;
+
+        const rows = this.pickCompletedRows(res);
+        this.emitCompletedGroups(rows, seq);
+      } catch (error) {
+        if (seq !== this.completedRequestSeq) return;
+        console.error("鑾峰彇宸插畬鎴愭偅鑰呮槑缁嗗け璐�:", error);
+        this.emitCompletedGroups([], seq);
+      }
+    },
+
+    // 缁勮绗竴寮犮�屾弧鎰忓害鐘舵�佹煡璇€�嶉〉鍚屾鏌ヨ鏉′欢
+    buildCompletedPayload() {
+      const scope = this.buildCompletedScope();
+      if (!scope.all && !scope.depts.length && !scope.wards.length) {
+        return null;
+      }
+
+      const payload = {
+        pageNum: null,
+        pageSize: null,
+        sendstate: null,
+        sendstateView: 2, // 2 = 宸插畬鎴�
+        sort: 2,
+        serviceType: this.currentServiceType,
+        searchscope: scope.searchscope,
+        visitCount: 1,
+        scopetype: [],
+        // 涓庣涓�寮犲浘涓�鑷达細閫変簡鍏蜂綋绉戝/鐥呭尯鏃跺彧浼犲搴旂淮搴︼紱銆屽叏閮ㄣ�嶆椂涓や釜缁村害閮戒紶
+        deptOrDistrict: scope.deptOrDistrict,
+      };
+
+      // 鍦ㄩ櫌婊℃剰搴︾敤 hospital*锛岀闄㈡弧鎰忓害鐢� leave*
+      if (this.satisfactionScope === "hospital") {
+        if (scope.depts.length) {
+          payload.deptcodes = scope.depts;
+        }
+        if (scope.wards.length) {
+          payload.hospitaldistrictcodes = scope.wards;
+        }
+      } else {
+        if (scope.depts.length) {
+          payload.leaveldeptcodes = scope.depts;
+        }
+        if (scope.wards.length) {
+          payload.leavehospitaldistrictcodes = scope.wards;
+        }
+      }
+
+      const range = this.queryParams.dateRange || [];
+      if (range.length === 2 && range[0] && range[1]) {
+        payload.finishtimeStart = range[0];
+        payload.finishtimeEnd = range[1];
+      }
+
+      return payload;
+    },
+
+    // 缁勮鏌ヨ鑼冨洿锛氱粺璁$被鍨嬪喅瀹氭寜鐥呭尯杩樻槸绉戝杩囨护
+    buildCompletedScope() {
+      const allDepts = (this.$store.getters.belongDepts || [])
+        .map((dept) => dept.deptCode)
+        .filter(Boolean);
+      const allWards = (this.$store.getters.belongWards || [])
+        .map((ward) => ward.districtCode)
+        .filter(Boolean);
+
+      // 鐥呭尯缁熻锛堝惈缁熻绫诲瀷涓虹┖鐨勬儏鍐碉級
+      if (this.queryParams.statisticaltype != 2) {
+        const rawSelected = this.queryParams.leavehospitaldistrictcodes || [];
+        const selected = rawSelected.filter(
+          (code) => code && code !== "all"
+        );
+        const useAll = !rawSelected.length || rawSelected.includes("all");
+
+        if (!useAll && selected.length) {
+          return {
+            depts: [],
+            wards: selected,
+            deptOrDistrict: 1,
+            searchscope: 2,
+          };
+        }
+        // 鍏ㄩ儴锛氫笉浼犵梾鍖�/绉戝缂栫爜锛岀敱鍚庣杩斿洖褰撳墠鏈烘瀯鍏ㄩ儴鏁版嵁
+        return {
+          depts: [],
+          wards: [],
+          deptOrDistrict: 2,
+          searchscope: 3,
+          all: true,
+        };
+      }
+
+      // 绉戝缁熻
+      const rawSelected = this.queryParams.deptcodes || [];
+      const selected = rawSelected.filter((code) => code && code !== "all");
+      const useAll = !rawSelected.length || rawSelected.includes("all");
+      if (!useAll && selected.length) {
+        return {
+          depts: selected,
+          wards: [],
+          deptOrDistrict: 1,
+          searchscope: 1,
+        };
+      }
+      return {
+        depts: [],
+        wards: [],
+        deptOrDistrict: 2,
+        searchscope: 3,
+        all: true,
+      };
+    },
+
+    // 闂璇︽儏鍗犳瘮 / 鍥捐〃 / 楗煎浘 鍏辩敤鏁版嵁
+    maybeRefreshQuestionDetails() {
+      if (this.showAnalysisTabs) {
+        this.refreshQuestionDetails();
+      }
+    },
+
+    async refreshQuestionDetails() {
+      const seq = ++this.questionRequestSeq;
+      const payload = this.buildQuestionPayload();
+
+      if (!payload) {
+        this.$emit("question-details-change", { loading: false, list: [] });
+        return;
+      }
+
+      this.$emit("question-details-change", { loading: true });
+
+      try {
+        const res = await getSfStatisticsJoyInfo(payload);
+        if (seq !== this.questionRequestSeq) return;
+
+        this.$emit("question-details-change", {
+          loading: false,
+          list: res.data || [],
+        });
+      } catch (error) {
+        if (seq !== this.questionRequestSeq) return;
+        console.error("鑾峰彇闂璇︽儏鍗犳瘮澶辫触:", error);
+        this.$emit("question-details-change", { loading: false, list: [] });
+      }
+    },
+
+    buildQuestionPayload() {
+      const scope = this.buildCompletedScope();
+      if (!scope.all && !scope.depts.length && !scope.wards.length) {
+        return null;
+      }
+
+      const params = {
+        configKey: "joyCount",
+        statisticaltype: this.queryParams.statisticaltype,
+        serviceType: this.queryParams.serviceType,
+        searchscope: scope.searchscope,
+        pageNum: 1,
+        pageSize: 999,
+      };
+
+      const range = this.queryParams.dateRange || [];
+      if (range.length === 2 && range[0] && range[1]) {
+        params.startTime = range[0];
+        params.endTime = range[1];
+      }
+
+      if (this.queryParams.statisticaltype == 2) {
+        if (scope.depts.length) {
+          if (this.isInHospitalSatisfaction) {
+            params.hospitaldeptcodes = scope.depts;
+          } else {
+            params.leaveldeptcodes = scope.depts;
+          }
+        }
+      } else if (scope.wards.length) {
+        if (this.isInHospitalSatisfaction) {
+          params.hospitaldistrictcodes = scope.wards;
+        } else {
+          params.leavehospitaldistrictcodes = scope.wards;
+        }
+      }
+
+      return params;
+    },
+
+    // 鍏煎鎺ュ彛涓嶅悓鐨勮繑鍥炲眰绾�
+    pickCompletedRows(res) {
+      if (!res) return [];
+      const rowsWrap = res.rows || (res.data && res.data.rows);
+      let list = [];
+
+      if (Array.isArray(rowsWrap) && rowsWrap[0]) {
+        list =
+          rowsWrap[0].serviceSubtaskList ||
+          (rowsWrap[0].sendname ? rowsWrap : []);
+      } else if (res.data && Array.isArray(res.data.serviceSubtaskList)) {
+        list = res.data.serviceSubtaskList;
+      } else if (Array.isArray(res.data)) {
+        list = res.data;
+      }
+
+      return (list || [])
+        .filter(Boolean)
+        .map((row) => this.normalizeCompletedRow(row));
+    },
+
+    normalizeCompletedRow(row) {
+      const item = { ...row };
+      if (item.endtime) {
+        item.endDay = this.daysBetween(item.endtime);
+      }
+      return item;
+    },
+
+    emitCompletedGroups(rows, seq) {
+      if (seq !== this.completedRequestSeq) return;
+      this.$emit("completed-rows-change", {
+        ...this.buildCompletedMeta(),
+        loading: false,
+        total: rows.length,
+        rows,
+      });
+    },
+
+    buildCompletedMeta() {
+      return {
+        dimension:
+          this.queryParams.statisticaltype == 2 ? "dept" : "ward",
+        scope: this.satisfactionScope,
+        dateRange: [...(this.queryParams.dateRange || [])],
+      };
+    },
+
+    // 鎸夊綋鍓嶇粺璁$被鍨嬪垎缁勶細鐥呭尯缁熻 -> 鐥呭尯锛岀瀹ょ粺璁� -> 绉戝
+    groupCompletedRows(rows) {
+      const dimension =
+        this.queryParams.statisticaltype == 2 ? "dept" : "ward";
+      const groupMap = new Map();
+
+      (rows || []).forEach((row) => {
+        const name =
+          dimension === "ward" ? this.wardNameOf(row) : this.deptNameOf(row);
+        const code =
+          dimension === "ward"
+            ? this.wardCodeOf(row)
+            : this.deptCodeOf(row);
+
+        const key = String(code || name || "unknown");
+        if (!groupMap.has(key)) {
+          groupMap.set(key, {
+            key,
+            label:
+              name || (dimension === "ward" ? "鏈垎鐥呭尯" : "鏈垎绉戝"),
+            rows: [],
+          });
+        }
+        groupMap.get(key).rows.push(row);
+      });
+
+      const orderMap = this.buildGroupOrder(dimension);
+      return Array.from(groupMap.values()).sort((a, b) => {
+        const aIndex = orderMap.has(a.key) ? orderMap.get(a.key) : 99999;
+        const bIndex = orderMap.has(b.key) ? orderMap.get(b.key) : 99999;
+        if (aIndex !== bIndex) return aIndex - bIndex;
+        return a.label.localeCompare(b.label, "zh-Hans-CN");
+      });
+    },
+
+    // tab 椤哄簭鎸夐〉闈㈠乏渚х瀹�/鐥呭尯鏉冮檺鍒楄〃鐨勯『搴忥紝淇濊瘉銆屼竴鐥呭尯銆佷簩鐥呭尯鈥︺�嶇殑鑷劧椤哄簭
+    buildGroupOrder(dimension) {
+      const list =
+        dimension === "ward"
+          ? this.$store.getters.belongWards
+          : this.$store.getters.belongDepts;
+      const orderMap = new Map();
+
+      (list || []).forEach((item, index) => {
+        const code =
+          dimension === "ward" ? item.districtCode : item.deptCode;
+        if (code) orderMap.set(String(code), index);
+      });
+
+      return orderMap;
+    },
+
+    wardNameOf(row) {
+      if (!row) return "";
+      const name =
+        this.satisfactionScope === "hospital"
+          ? row.hospitaldistrictname || row.leavehospitaldistrictname
+          : row.leavehospitaldistrictname || row.hospitaldistrictname;
+      return name === "-" ? "" : name;
+    },
+
+    wardCodeOf(row) {
+      if (!row) return "";
+      return this.satisfactionScope === "hospital"
+        ? row.hospitaldistrictcode || row.leavehospitaldistrictcode
+        : row.leavehospitaldistrictcode || row.hospitaldistrictcode;
+    },
+
+    deptNameOf(row) {
+      if (!row) return "";
+      const name =
+        this.satisfactionScope === "hospital"
+          ? row.deptname || row.leaveldeptname
+          : row.leaveldeptname || row.deptname;
+      return name === "-" ? "" : name;
+    },
+
+    deptCodeOf(row) {
+      if (!row) return "";
+      return this.satisfactionScope === "hospital"
+        ? row.hospitaldeptcode || row.deptcode
+        : row.deptcode || row.hospitaldeptcode;
     },
 
     // 閲嶇疆鏌ヨ锛堟仮澶嶉粯璁わ細绂婚櫌婊℃剰搴� + 鏈嶅姟绫诲瀷 6锛�
@@ -870,6 +1244,8 @@
         pageSize: 20,
       };
       this.getList();
+      this.maybeRefreshCompletedGroups();
+      this.maybeRefreshQuestionDetails();
     },
 
     // 澶勭悊鍒嗛〉澶у皬鍙樺寲

--
Gitblit v1.9.3