From fb34ba28cb908bd328cf6690ab0b19a56428f4e2 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期五, 13 十一月 2026 10:56:55 +0800
Subject: [PATCH] 测试完成

---
 src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue | 1037 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 941 insertions(+), 96 deletions(-)

diff --git a/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue b/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
index 0c0dd0c..a5c3cf5 100644
--- a/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
+++ b/src/views/Satisfaction/sfstatistics/components/FollowupStatistics.vue
@@ -9,6 +9,23 @@
         label-width="100px"
         class="query-form"
       >
+        <el-form-item
+          v-if="isTongdeOrg"
+          label="婊℃剰搴︾被鍨�"
+          prop="satisfactionScope"
+        >
+          <el-select
+            v-model="satisfactionScope"
+            placeholder="榛樿鍦ㄩ櫌"
+            clearable
+            style="width: 150px"
+            @change="handleSatisfactionScopeChange"
+          >
+            <el-option label="绂婚櫌婊℃剰搴�" value="leave" />
+            <el-option label="鍦ㄩ櫌婊℃剰搴�" value="hospital" />
+          </el-select>
+        </el-form-item>
+
         <el-form-item label="缁熻绫诲瀷" prop="statisticaltype">
           <el-select
             v-model="queryParams.statisticaltype"
@@ -136,30 +153,70 @@
         style="width: 100%"
         @selection-change="handleSelectionChange"
         :row-key="getRowKey"
+        show-summary
+        :summary-method="getSummaries"
       >
-        <!-- 鐥呭尯鍒� -->
+        <!-- 鐥呭尯缁熻锛氬湪闄㈢梾鍖� + 绂婚櫌鐥呭尯 -->
         <el-table-column
           v-if="queryParams.statisticaltype == 1"
-          label="鍑洪櫌鐥呭尯"
+          label="鍦ㄩ櫌鐥呭尯"
+          align="center"
+          sortable
+          key="hospitaldistrictname"
+          prop="hospitaldistrictname"
+          :show-overflow-tooltip="true"
+          :sort-method="sortHospitalWard"
+          min-width="120"
+        >
+          <template slot-scope="scope">
+            {{ scope.row.hospitaldistrictname || "-" }}
+          </template>
+        </el-table-column>
+
+        <el-table-column
+          v-if="queryParams.statisticaltype == 1"
+          label="绂婚櫌鐥呭尯"
           align="center"
           sortable
           key="leavehospitaldistrictname"
           prop="leavehospitaldistrictname"
           :show-overflow-tooltip="true"
-          :sort-method="sortChineseNumber"
+          :sort-method="sortLeaveWard"
           min-width="120"
-        />
+        >
+          <template slot-scope="scope">
+            {{ scope.row.leavehospitaldistrictname || "-" }}
+          </template>
+        </el-table-column>
 
-        <!-- 绉戝鍒� -->
+        <!-- 绉戝缁熻锛氬湪闄㈢瀹� + 绂婚櫌绉戝 -->
         <el-table-column
           v-if="queryParams.statisticaltype == 2"
-          label="绉戝"
+          label="鍦ㄩ櫌绉戝"
+          align="center"
+          key="hospitaldeptname"
+          prop="hospitaldeptname"
+          :show-overflow-tooltip="true"
+          min-width="120"
+        >
+          <template slot-scope="scope">
+            {{ scope.row.hospitaldeptname || "-" }}
+          </template>
+        </el-table-column>
+
+        <el-table-column
+          v-if="queryParams.statisticaltype == 2"
+          label="绂婚櫌绉戝"
           align="center"
           key="deptname"
           prop="deptname"
           :show-overflow-tooltip="true"
           min-width="120"
-        />
+        >
+          <template slot-scope="scope">
+            {{ scope.row.deptname || "-" }}
+          </template>
+        </el-table-column>
 
         <el-table-column
           label="鍑洪櫌浜烘"
@@ -323,6 +380,7 @@
         :row-data="currentRow"
         :topicList="topiclist"
         :query-params="queryParams"
+        :topType="2"
         @close="topicVisible = false"
       />
     </el-dialog>
@@ -337,6 +395,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";
 
@@ -346,14 +405,26 @@
     SeedetailsDialog,
     TopicDialog,
   },
+  props: {
+    // 鏄惁鍦ㄩ《閮ㄧ敓鎴愭偅鑰呰〃鍗� / 闂璇︽儏鍒嗘瀽 tab锛堜粎婊℃剰搴︾粺璁′富椤靛紑鍚級
+    showAnalysisTabs: {
+      type: Boolean,
+      default: false,
+    },
+  },
   data() {
     return {
+      // 婊℃剰搴︾被鍨嬶細leave=绂婚櫌婊℃剰搴︼紙鎸夊嚭闄㈢梾鍖虹粺璁★級锛宧ospital=鍦ㄩ櫌婊℃剰搴︼紙鎸夊湪闄㈢梾鍖虹粺璁★級
+      // 榛樿绂婚櫌婊℃剰搴�
+      satisfactionScope: "leave",
+
       // 鏌ヨ鍙傛暟
       queryParams: {
         statisticaltype: 1,
         leavehospitaldistrictcodes: ["all"],
         deptcodes: [],
-        serviceType: [2],
+        // 榛樿鏈嶅姟绫诲瀷锛�6=浣忛櫌婊℃剰搴︼紙鍑哄叆闄㈡弧鎰忓害锛�
+        serviceType: [6],
         dateRange: [],
         pageNum: 1,
         pageSize: 20,
@@ -372,7 +443,25 @@
       flatArraydept: [],
 
       // 鏈嶅姟绫诲瀷閫夐」
-      options: [],
+      options: [
+        {
+          value: 6,
+          label: "鍑哄叆闄㈡弧鎰忓害",
+          raw: {
+            cssClass: "",
+            listClass: "",
+          },
+        },
+
+        {
+          value: 14,
+          label: "闂ㄨ瘖婊℃剰搴�",
+          raw: {
+            cssClass: "",
+            listClass: "",
+          },
+        },
+      ],
 
       // 琛ㄦ牸鏁版嵁
       userList: [],
@@ -383,6 +472,10 @@
       // 鍔犺浇鐘舵��
       loading: false,
       orgname: "",
+      // 宸插畬鎴愭槑缁嗚姹傚簭鍙凤紝閬垮厤蹇�熷垏鎹㈢瓫閫夋椂鏃ц姹傝鐩栨柊缁撴灉
+      completedRequestSeq: 0,
+      // 闂璇︽儏璇锋眰搴忓彿
+      questionRequestSeq: 0,
 
       // 閫変腑鐨勮
       ids: [],
@@ -440,10 +533,28 @@
     };
   },
 
+  computed: {
+    // 鏄惁鎸夈�屽湪闄㈡弧鎰忓害銆嶅彛寰勭粺璁★細鍦ㄩ櫌鐢� hospitaldistrictcodes / hospitaldeptcodes锛�
+    // 绂婚櫌鐢� leavehospitaldistrictcodes / leaveldeptcodes
+    // 榛樿鍦ㄩ櫌锛屾墍浠ユ竻绌轰笅鎷夋椂浠嶆寜鍦ㄩ櫌鍙e緞澶勭悊
+    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.queryParams.serviceType = this.isTongdeOrg ? [6] : [2];
     this.initData();
+    // 椤堕儴鎮h�呰〃鍗� / 闂璇︽儏鍒嗘瀽 tab锛氶粯璁ゆ寜褰撳墠缁熻鍙e緞鍔犺浇涓�娆�
+    this.maybeRefreshCompletedGroups();
+    this.maybeRefreshQuestionDetails();
   },
 
   methods: {
@@ -455,8 +566,12 @@
 
     // 鑾峰彇绉戝鏍�
     getDeptTree() {
-      // 鑾峰彇鏈嶅姟绫诲瀷
-      this.options = this.$store.getters.tasktypes || [];
+      // 鑾峰彇鏈嶅姟绫诲瀷锛堝瓧鍏搁噷鐨勩�屼綇闄㈡弧鎰忓害銆嶅湪鏈〉鏄剧ず涓恒�屽嚭鍏ラ櫌婊℃剰搴︺�嶏級
+      const labelFix = { 浣忛櫌婊℃剰搴�: "鍑哄叆闄㈡弧鎰忓害" };
+      this.options = (this.$store.getters.tasktypes || []).map((o) =>
+        labelFix[o.label] ? { ...o, label: labelFix[o.label] } : o
+      );
+      console.log(11, this.options);
 
       // 鑾峰彇绉戝鍒楄〃
       this.flatArraydept = (this.$store.getters.belongDepts || []).map(
@@ -502,36 +617,56 @@
           params.endTime = this.queryParams.dateRange[1];
         }
 
-        // 澶勭悊鐥呭尯/绉戝閫夋嫨
+        // 澶勭悊鐥呭尯/绉戝閫夋嫨锛氬彧淇濈暀褰撳墠缁熻绫诲瀷 + 褰撳墠婊℃剰搴︾被鍨嬪搴旂殑瀛楁锛�
+        // 閬垮厤鍦ㄩ櫌/绂婚櫌涓ゅ鏉′欢鍚屾椂鎷艰繘 SQL
         if (params.statisticaltype == 1) {
           // 鐥呭尯缁熻
-          if (params.leavehospitaldistrictcodes.includes("all")) {
-            // 濡傛灉閫夋嫨浜�"鍏ㄩ儴"锛屽垯绉婚櫎"all"鍊�
-            params.leavehospitaldistrictcodes =
-              params.leavehospitaldistrictcodes.filter(
-                (item) => item !== "all"
-              );
-            // 濡傛灉闇�瑕佷紶鎵�鏈夌梾鍖轰唬鐮侊紝鍙互浠巗tore涓幏鍙�
-            params.leavehospitaldistrictcodes = (
-              this.$store.getters.belongWards || []
-            ).map((ward) => ward.districtCode);
+          let wardCodes = params.leavehospitaldistrictcodes || [];
+          if (wardCodes.includes("all")) {
+            // 閫夋嫨"鍏ㄩ儴"鏃朵笉鍔犵梾鍖洪檺鍒讹紝鏌ュ叏閮ㄧ梾鍖�
+            wardCodes = [];
+          }
+          delete params.leavehospitaldistrictcodes;
+          delete params.hospitaldistrictcodes;
+          delete params.deptcodes;
+          delete params.leaveldeptcodes;
+          delete params.hospitaldeptcodes;
+          if (wardCodes.length) {
+            if (this.isInHospitalSatisfaction) {
+              params.hospitaldistrictcodes = wardCodes;
+            } else {
+              params.leavehospitaldistrictcodes = wardCodes;
+            }
           }
         } else if (params.statisticaltype == 2) {
           // 绉戝缁熻
-          if (params.deptcodes.includes("all")) {
-            // 濡傛灉閫夋嫨浜�"鍏ㄩ儴"锛屽垯绉婚櫎"all"鍊�
-            params.deptcodes = params.deptcodes.filter(
-              (item) => item !== "all"
-            );
-            // 濡傛灉闇�瑕佷紶鎵�鏈夌瀹や唬鐮侊紝鍙互浠巗tore涓幏鍙�
-            params.deptcodes = (this.$store.getters.belongDepts || []).map(
-              (dept) => dept.deptCode
-            );
+          let deptCodes = params.deptcodes || [];
+          if (deptCodes.includes("all")) {
+            // 閫夋嫨"鍏ㄩ儴"鏃朵笉鍔犵瀹ら檺鍒讹紝鏌ュ叏閮ㄧ瀹�
+            deptCodes = [];
+          } else {
+            deptCodes = deptCodes.filter((item) => item !== "all");
+          }
+          delete params.deptcodes;
+          delete params.leaveldeptcodes;
+          delete params.hospitaldeptcodes;
+          delete params.leavehospitaldistrictcodes;
+          delete params.hospitaldistrictcodes;
+          if (deptCodes.length) {
+            if (this.isInHospitalSatisfaction) {
+              params.hospitaldeptcodes = deptCodes;
+            } else {
+              params.leaveldeptcodes = deptCodes;
+            }
           }
         }
 
         const response = await getSfStatisticsJoy(params);
-        this.userList = this.customSort(response.data) || [];
+        // 绉戝缁熻鎸夋帴鍙h繑鍥為『搴忥紝鐥呭尯缁熻淇濇寔鍘熸湁鐨勪腑鏂囧簭鍙锋帓搴�
+        this.userList =
+          this.queryParams.statisticaltype == 1
+            ? this.customSort(response.data) || []
+            : response.data || [];
         this.total = response.total || 0;
       } catch (error) {
         console.error("鑾峰彇缁熻鍒楄〃澶辫触:", error);
@@ -541,9 +676,25 @@
       }
     },
     sortChineseNumber(aRow, bRow) {
-      const a = aRow.leavehospitaldistrictname;
-      const b = bRow.leavehospitaldistrictname;
-
+      return this.compareWardNames(
+        this.getWardName(aRow),
+        this.getWardName(bRow)
+      );
+    },
+    sortHospitalWard(aRow, bRow) {
+      return this.compareWardNames(
+        aRow && aRow.hospitaldistrictname,
+        bRow && bRow.hospitaldistrictname
+      );
+    },
+    sortLeaveWard(aRow, bRow) {
+      return this.compareWardNames(
+        aRow && aRow.leavehospitaldistrictname,
+        bRow && bRow.leavehospitaldistrictname
+      );
+    },
+    // 姣旇緝涓や釜鐥呭尯鍚嶇О鐨勪腑鏂囧簭鍙凤紱鏃犲簭鍙锋椂鎸夊瓧绗︿覆姣旇緝
+    compareWardNames(a, b) {
       // 涓枃鏁板瓧鍒伴樋鎷変集鏁板瓧鐨勬槧灏勶紙鎵╁睍鍒�45锛�
       const chineseNumMap = {
         涓�: 1,
@@ -702,14 +853,12 @@
           return -1;
         };
 
-        const indexA = getIndex(a.leavehospitaldistrictname);
-        const indexB = getIndex(b.leavehospitaldistrictname);
+        const indexA = getIndex(this.getWardName(a));
+        const indexB = getIndex(this.getWardName(b));
 
         // 鎺掑簭閫昏緫
         if (indexA === -1 && indexB === -1) {
-          return (a.leavehospitaldistrictname || "").localeCompare(
-            b.leavehospitaldistrictname || ""
-          );
+          return this.getWardName(a).localeCompare(this.getWardName(b));
         }
         if (indexA === -1) return 1;
         if (indexB === -1) return -1;
@@ -725,26 +874,380 @@
       }
       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锛�
     resetQuery() {
+      this.satisfactionScope = "leave";
       this.queryParams = {
         statisticaltype: 1,
         leavehospitaldistrictcodes: [],
         deptcodes: [],
-        serviceType: [2],
+        serviceType: [6],
         dateRange: [],
         pageNum: 1,
         pageSize: 20,
       };
       this.getList();
+      this.maybeRefreshCompletedGroups();
+      this.maybeRefreshQuestionDetails();
     },
 
     // 澶勭悊鍒嗛〉澶у皬鍙樺寲
@@ -767,11 +1270,19 @@
       this.multiple = !selection.length;
     },
 
-    // 鑾峰彇琛宬ey
+    // 鑾峰彇琛宬ey锛堟寜褰撳墠缁熻绫诲瀷鍙栧搴旂淮搴︾紪鐮侊級
     getRowKey(row) {
-      return row.statisticaltype === 1
-        ? row.leavehospitaldistrictcode
-        : row.deptcode;
+      return this.queryParams.statisticaltype == 1
+        ? row.hospitaldistrictcode || row.leavehospitaldistrictcode
+        : row.hospitaldeptcode || row.deptcode;
+    },
+
+    // 褰撳墠婊℃剰搴︾被鍨嬪搴旂殑鐥呭尯鍚嶇О锛堢敤浜庢帓搴�/瀵煎嚭/璇︽儏鏍囬锛�
+    getWardName(row) {
+      if (!row) return "";
+      return this.isInHospitalSatisfaction
+        ? row.hospitaldistrictname || ""
+        : row.leavehospitaldistrictname || "";
     },
 
     // 鏍煎紡鍖栫櫨鍒嗘瘮
@@ -780,6 +1291,92 @@
       const num = parseFloat(value);
       if (isNaN(num)) return "-";
       return `${(num * 100).toFixed(2)}%`;
+    },
+
+    // 琛ㄦ牸鍚堣琛�
+    getSummaries(param) {
+      const { columns, data } = param;
+      const sums = [];
+
+      columns.forEach((column, index) => {
+        if (index === 0) {
+          sums[index] = "鍚堣";
+          return;
+        }
+
+        const prop = column.property;
+
+        // 鏁板�煎垪姹傚拰
+        if (
+          [
+            "dischargeCount",
+            "nonFollowUp",
+            "followUpNeeded",
+            "joyAllCount",
+            "joyCount",
+          ].includes(prop)
+        ) {
+          sums[index] = data.reduce(
+            (sum, item) => sum + (Number(item[prop]) || 0),
+            0
+          );
+          return;
+        }
+
+        // 瀹屾垚姣旂巼锛氭弧鎰忓害濉姤閲� / 婊℃剰搴﹂鐩�婚噺
+        if (prop === "joyTotal") {
+          const totalJoyAllCount = data.reduce(
+            (sum, item) => sum + (Number(item.joyAllCount) || 0),
+            0
+          );
+          const totalJoyCount = data.reduce(
+            (sum, item) => sum + (Number(item.joyCount) || 0),
+            0
+          );
+          sums[index] =
+            totalJoyAllCount > 0
+              ? ((totalJoyCount / totalJoyAllCount) * 100).toFixed(2) + "%"
+              : "0.00%";
+          return;
+        }
+
+        // 鐧惧垎姣斿垪锛堥殢璁跨巼/鍙婃椂鐜囷級锛氬彇骞冲潎鍊硷紙0 鍊间篃鍙備笌骞冲潎锛�
+        if (prop === "followUpRate" || prop === "rate") {
+          const percentageValues = data
+            .map((item) => {
+              const value = item[prop];
+              if (
+                value === null ||
+                value === undefined ||
+                value === "" ||
+                value === "-"
+              ) {
+                return null;
+              }
+              if (typeof value === "string" && value.includes("%")) {
+                const num = parseFloat(value.replace("%", "")) / 100;
+                return isNaN(num) ? null : num;
+              }
+              const num = parseFloat(value);
+              return isNaN(num) ? null : num;
+            })
+            .filter((value) => value !== null);
+
+          sums[index] =
+            percentageValues.length > 0
+              ? (
+                  (percentageValues.reduce((sum, value) => sum + value, 0) /
+                    percentageValues.length) *
+                  100
+                ).toFixed(2) + "%"
+              : "0.00%";
+          return;
+        }
+
+        sums[index] = "";
+      });
+
+      return sums;
     },
 
     // 鏌ョ湅鏈強鏃堕殢璁胯鎯�
@@ -808,12 +1405,33 @@
           params.endTime = this.queryParams.dateRange[1];
         }
 
+        // 璇︽儏鍙寜褰撳墠鍒嗙粍缁村害杩囨护锛屾竻鎺夊叾浣欑淮搴︼紝閬垮厤鍦ㄩ櫌/绂婚櫌鏉′欢浜掔浉骞叉壈
+        delete params.deptcodes;
+        delete params.leaveldeptcodes;
+        delete params.hospitaldeptcodes;
+        delete params.leavehospitaldistrictcodes;
+        delete params.hospitaldistrictcodes;
+
         if (this.queryParams.statisticaltype == 1) {
-          this.topicvalue.name = row.leavehospitaldistrictname;
-          params.leavehospitaldistrictcodes = [row.leavehospitaldistrictcode];
+          if (this.isInHospitalSatisfaction) {
+            this.topicvalue.name = row.hospitaldistrictname || "-";
+            params.hospitaldistrictcodes = [row.hospitaldistrictcode].filter(
+              Boolean
+            );
+          } else {
+            this.topicvalue.name = row.leavehospitaldistrictname || "-";
+            params.leavehospitaldistrictcodes = [
+              row.leavehospitaldistrictcode,
+            ].filter(Boolean);
+          }
         } else {
-          this.topicvalue.name = row.deptname;
-          params.deptcodes = [row.deptcode];
+          if (this.isInHospitalSatisfaction) {
+            this.topicvalue.name = row.hospitaldeptname || "-";
+            params.hospitaldeptcodes = [row.hospitaldeptcode].filter(Boolean);
+          } else {
+            this.topicvalue.name = row.deptname || "-";
+            params.leaveldeptcodes = [row.deptcode].filter(Boolean);
+          }
         }
 
         const response = await getSfStatisticsJoyInfo(params);
@@ -823,6 +1441,113 @@
         console.error("鑾峰彇婊℃剰搴﹁鎯呭け璐�:", error);
         this.$message.error("鑾峰彇璇︽儏澶辫触");
       }
+    },
+
+    // 鑾峰彇鎸囧畾鐥呭尯/绉戝鐨勯鐩鎯�
+    async fetchTopicDetail(row) {
+      const params = {
+        configKey: "joyCount",
+        ...this.queryParams,
+      };
+      // 瀵煎嚭闇�瑕佽鐥呭尯/绉戝鐨勫叏閮ㄩ鐩紝瑕嗙洊涓昏〃鍒嗛〉鍙傛暟
+      params.pageNum = 1;
+      params.pageSize = 1000;
+      if (
+        this.queryParams.dateRange &&
+        this.queryParams.dateRange.length === 2
+      ) {
+        params.startTime = this.queryParams.dateRange[0];
+        params.endTime = this.queryParams.dateRange[1];
+      }
+      if (this.queryParams.statisticaltype == 1) {
+        params.leavehospitaldistrictcodes = [row.leavehospitaldistrictcode];
+      } else {
+        params.deptcodes = [row.deptcode];
+      }
+      const response = await getSfStatisticsJoyInfo(params);
+      return response.data || {};
+    },
+
+    // 涓昏〃瀵煎嚭琛屾暟鎹�
+    getMainExportRow(item) {
+      return [
+        this.queryParams.statisticaltype == 1
+          ? item.leavehospitaldistrictname
+          : item.deptname,
+        item.dischargeCount || 0,
+        item.nonFollowUp || 0,
+        item.followUpNeeded || 0,
+        item.followUpRate || "0%",
+        item.rate ? this.formatPercent(item.rate) : "0%",
+        item.joyAllCount || 0,
+        item.joyCount || 0,
+        item.joyTotal ? this.formatPercent(item.joyTotal) : "0%",
+      ];
+    },
+
+    // 璁$畻鏂囨湰鏄剧ず瀹藉害锛堜腑鏂囨寜 2銆佽嫳鏂�/鏁板瓧鎸� 1锛�
+    textWidth(str) {
+      if (!str) return 0;
+      let width = 0;
+      for (const ch of String(str)) {
+        width += ch.charCodeAt(0) > 255 ? 2 : 1;
+      }
+      return width;
+    },
+
+    // 涓芥按甯備腑鍖婚櫌锛氭媺鍙栨墍鏈夌瀹ら鐩槑缁嗭紝鎵佸钩鍖栦负銆岄鐩�夐」銆嶅垪缁撴瀯
+    async buildLishuiTopicColumns() {
+      const topicMap = new Map();
+      const rowQuantities = [];
+
+      for (const item of this.userList) {
+        const topiclist = await this.fetchTopicDetail(item);
+        const qMap = new Map();
+
+        if (topiclist && Object.keys(topiclist).length) {
+          Object.keys(topiclist).forEach((key) => {
+            const topic = topiclist[key];
+            if (!topic || !topic.scriptContent) return;
+
+            const tKey =
+              topic.scriptid != null && topic.scriptid !== ""
+                ? String(topic.scriptid)
+                : topic.scriptContent;
+
+            if (!topicMap.has(tKey)) {
+              topicMap.set(tKey, {
+                key: tKey,
+                scriptContent: topic.scriptContent,
+                options: [],
+                optionSet: new Set(),
+              });
+            }
+
+            const t = topicMap.get(tKey);
+            const topicQ = new Map();
+            (topic.details || []).forEach((detail) => {
+              if (!detail || !detail.optionText) return;
+              if (!t.optionSet.has(detail.optionText)) {
+                t.optionSet.add(detail.optionText);
+                t.options.push(detail.optionText);
+              }
+              topicQ.set(detail.optionText, Number(detail.chosenQuantity) || 0);
+            });
+            qMap.set(tKey, topicQ);
+          });
+        }
+
+        rowQuantities.push(qMap);
+      }
+
+      const topics = Array.from(topicMap.values());
+      // 娌℃湁閫夐」鐨勯鐩粯璁ゅ~鍏呬竴涓┖閫夐」鍒楋紝閬垮厤琛ㄥご/鏁版嵁閿欎綅
+      topics.forEach((t) => {
+        if (!t.options.length) {
+          t.options = [""];
+        }
+      });
+      return { topics, rowQuantities };
     },
 
     // 瀵煎嚭鏁版嵁
@@ -916,7 +1641,11 @@
             pattern: "solid",
             fgColor: { argb: "FFF5F7FA" },
           },
-          alignment: { vertical: "middle", horizontal: "center" },
+          alignment: {
+            vertical: "middle",
+            horizontal: "center",
+            wrapText: true,
+          },
           border: {
             top: { style: "thin", color: { argb: "FFD0D0D0" } },
             left: { style: "thin", color: { argb: "FFD0D0D0" } },
@@ -936,15 +1665,17 @@
           },
         };
 
-        // 娣诲姞鎬绘爣棰�
-        worksheet.mergeCells(1, 1, 1, 10);
-        const titleCell = worksheet.getCell(1, 1);
-        titleCell.value = `婊℃剰搴﹂殢璁跨粺璁¤〃锛�${sheetNameSuffix}锛塦;
-        titleCell.style = titleStyle;
-        worksheet.getRow(1).height = 35;
+        // 涓芥按甯備腑鍖婚櫌锛氶鍏堟媺鍙栭鐩槑缁嗭紝鎵佸钩鍖栦负銆岄鐩�夐」銆嶅垪
+        let lishuiTopics = [];
+        let lishuiRowQuantities = [];
+        if (isLishuiHospital) {
+          const built = await this.buildLishuiTopicColumns();
+          lishuiTopics = built.topics;
+          lishuiRowQuantities = built.rowQuantities;
+        }
 
-        // 娣诲姞琛ㄥご
-        const headers = [
+        // 涓昏〃鍒�
+        const mainHeaders = [
           this.queryParams.statisticaltype == 1 ? "鍑洪櫌鐥呭尯" : "绉戝",
           "鍑洪櫌浜烘",
           "鏃犻渶闅忚浜烘",
@@ -955,47 +1686,161 @@
           "婊℃剰搴﹀~鎶ラ噺",
           "瀹屾垚姣旂巼",
         ];
+        const mainColumnCount = mainHeaders.length;
 
-        const headerRow = worksheet.addRow(headers);
-        headerRow.eachCell((cell) => {
-          cell.style = headerStyle;
-        });
-        headerRow.height = 25;
+        // 鎬诲垪鏁帮紙涓芥按甯備腑鍖婚櫌鍦ㄦ湯灏捐拷鍔犻鐩�夐」鍒楋級
+        const topicColumnCount = lishuiTopics.reduce(
+          (sum, t) => sum + (t.options.length || 1),
+          0
+        );
+        const totalColumns = mainColumnCount + topicColumnCount;
 
-        // 娣诲姞鏁版嵁琛�
-        this.userList.forEach((item) => {
-          const dataRow = worksheet.addRow([
-            this.queryParams.statisticaltype == 1
-              ? item.leavehospitaldistrictname
-              : item.deptname,
-            item.dischargeCount || 0,
-            item.nonFollowUp || 0,
-            item.followUpNeeded || 0,
-            item.followUpRate || "0%",
-            item.rate ? this.formatPercent(item.rate) : "0%",
-            item.joyAllCount || 0,
-            item.joyCount || 0,
-            item.joyTotal ? this.formatPercent(item.joyTotal) : "0%",
-          ]);
+        // 娣诲姞鎬绘爣棰�
+        worksheet.mergeCells(1, 1, 1, totalColumns);
+        const titleCell = worksheet.getCell(1, 1);
+        titleCell.value = `婊℃剰搴﹂殢璁跨粺璁¤〃锛�${sheetNameSuffix}锛塦;
+        titleCell.style = titleStyle;
+        worksheet.getRow(1).height = 35;
 
-          dataRow.eachCell((cell) => {
-            cell.style = cellStyle;
+        if (isLishuiHospital && lishuiTopics.length) {
+          // 璁$畻姣忎釜棰樼洰鐨勯�夐」鍒楀锛堥�夐」鏂囧瓧鑷�傚簲锛岄骞茶繃闀挎椂鎽婂鍒椼�佸繀瑕佹椂鎹㈣锛�
+          const topicColumns = lishuiTopics.map((topic) => {
+            const n = topic.options.length || 1;
+            const baseWidths = topic.options.map((opt) =>
+              opt === "" ? 10 : Math.max(10, this.textWidth(opt) + 4)
+            );
+            const sumWidth = baseWidths.reduce((s, w) => s + w, 0);
+            const topicWidth = this.textWidth(topic.scriptContent) + 4;
+            const groupWidth = Math.max(sumWidth, topicWidth);
+            const extra = (groupWidth - sumWidth) / n;
+            const widths = baseWidths.map((w) => w + extra);
+            const lines = Math.max(1, Math.ceil(topicWidth / groupWidth));
+            return { widths, lines };
           });
-          dataRow.height = 22;
-        });
+          const maxHeaderLines = topicColumns.reduce(
+            (m, t) => Math.max(m, t.lines),
+            1
+          );
 
-        // 璁剧疆鍒楀
-        worksheet.columns = [
-          { width: 20 },
-          { width: 12 },
-          { width: 12 },
-          { width: 12 },
-          { width: 12 },
-          { width: 12 },
-          { width: 15 },
-          { width: 15 },
-          { width: 12 },
-        ];
+          // 涓よ琛ㄥご锛氱涓�琛� = 涓昏〃鍒� + 棰樼洰鍚嶏紱绗簩琛� = 閫夐」鍚�
+          const headerRow1 = worksheet.addRow([]);
+          const headerRow2 = worksheet.addRow([]);
+
+          mainHeaders.forEach((h, i) => {
+            const col = i + 1;
+            headerRow1.getCell(col).value = h;
+            headerRow1.getCell(col).style = headerStyle;
+            headerRow2.getCell(col).style = headerStyle;
+            worksheet.mergeCells(
+              headerRow1.number,
+              col,
+              headerRow2.number,
+              col
+            );
+          });
+
+          let colIndex = mainColumnCount + 1;
+          lishuiTopics.forEach((topic) => {
+            const optCount = topic.options.length || 1;
+            for (let k = 0; k < optCount; k++) {
+              headerRow1.getCell(colIndex + k).style = headerStyle;
+            }
+            headerRow1.getCell(colIndex).value = topic.scriptContent;
+            if (optCount > 1) {
+              worksheet.mergeCells(
+                headerRow1.number,
+                colIndex,
+                headerRow1.number,
+                colIndex + optCount - 1
+              );
+            }
+            topic.options.forEach((opt, k) => {
+              headerRow2.getCell(colIndex + k).value = opt;
+              headerRow2.getCell(colIndex + k).style = headerStyle;
+            });
+            colIndex += optCount;
+          });
+
+          // 琛ㄥご楂樺害锛氶骞叉崲琛屾椂鎸夋渶闀块鐩鐣�
+          headerRow1.height = Math.max(30, 15 * maxHeaderLines + 8);
+          headerRow2.height = 25;
+
+          // 鏁版嵁琛�
+          this.userList.forEach((item, idx) => {
+            const row = worksheet.addRow([]);
+            const main = this.getMainExportRow(item);
+            main.forEach((v, i) => {
+              const cell = row.getCell(i + 1);
+              cell.value = v;
+              cell.style = cellStyle;
+            });
+
+            const qMap = lishuiRowQuantities[idx] || new Map();
+            let cIndex = mainColumnCount + 1;
+            for (const topic of lishuiTopics) {
+              const topicQ = qMap.get(topic.key);
+              topic.options.forEach((opt) => {
+                const cell = row.getCell(cIndex);
+                if (opt === "") {
+                  // 绌洪�夐」鍗犱綅鍒椾笉濉暟瀛�
+                  cell.value = "";
+                } else {
+                  const val = topicQ ? topicQ.get(opt) : undefined;
+                  cell.value = val === undefined || val === null ? 0 : val;
+                }
+                cell.style = cellStyle;
+                cIndex++;
+              });
+            }
+            row.height = 22;
+          });
+
+          // 鍒楀锛氫富琛ㄥ垪 + 棰樼洰閫夐」鍒�
+          const columns = [
+            { width: 20 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 15 },
+            { width: 15 },
+            { width: 12 },
+          ];
+          lishuiTopics.forEach((topic, ti) => {
+            topicColumns[ti].widths.forEach((w) => {
+              columns.push({ width: w });
+            });
+          });
+          worksheet.columns = columns;
+        } else {
+          // 鍏朵粬鍖婚櫌锛氬崟琛岃〃澶�
+          const headerRow = worksheet.addRow(mainHeaders);
+          headerRow.eachCell((cell) => {
+            cell.style = headerStyle;
+          });
+          headerRow.height = 25;
+
+          this.userList.forEach((item) => {
+            const dataRow = worksheet.addRow(this.getMainExportRow(item));
+            dataRow.eachCell((cell) => {
+              cell.style = cellStyle;
+            });
+            dataRow.height = 22;
+          });
+
+          worksheet.columns = [
+            { width: 20 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 12 },
+            { width: 15 },
+            { width: 15 },
+            { width: 12 },
+          ];
+        }
 
         // 鐢熸垚骞朵笅杞芥枃浠�
         const buffer = await workbook.xlsx.writeBuffer();

--
Gitblit v1.9.3