From bbbc478129f72b26e2ec4a2e981ed8698a96880c Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 22 十月 2026 00:28:18 +0800
Subject: [PATCH] 当service_type=6时,需要根据传入的入院还是离院病区(病区)去后端查询

---
 src/views/Satisfaction/sfstatistics/components/ChartsPanel.vue |   46 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/views/Satisfaction/sfstatistics/components/ChartsPanel.vue b/src/views/Satisfaction/sfstatistics/components/ChartsPanel.vue
index cc1be67..86c5b41 100644
--- a/src/views/Satisfaction/sfstatistics/components/ChartsPanel.vue
+++ b/src/views/Satisfaction/sfstatistics/components/ChartsPanel.vue
@@ -21,6 +21,18 @@
           <el-radio-button label="month">鎸夋湀</el-radio-button>
           <el-radio-button label="year">鎸夊勾</el-radio-button>
         </el-radio-group>
+        <span class="filter-label">婊℃剰搴︾被鍨嬶細</span>
+        <el-select
+          v-model="satisfactionScope"
+          size="small"
+          clearable
+          placeholder="榛樿绂婚櫌"
+          class="filter-scope"
+          @change="refreshAll"
+        >
+          <el-option label="绂婚櫌婊℃剰搴�" value="leave" />
+          <el-option label="鍦ㄩ櫌婊℃剰搴�" value="hospital" />
+        </el-select>
         <span class="filter-label">缁熻缁村害锛�</span>
         <el-radio-group v-model="queryParams.dimension" size="small" @change="onDimensionChange">
           <el-radio-button label="ward">鎸夌梾鍖虹粺璁�</el-radio-button>
@@ -170,6 +182,8 @@
   dicts: ['dimensionality_type'],
   data() {
     return {
+      // 婊℃剰搴︾被鍨嬶細leave=绂婚櫌婊℃剰搴︼紙绂婚櫌绉戝/鐥呭尯锛夛紝hospital=鍦ㄩ櫌婊℃剰搴︼紙鍦ㄩ櫌绉戝/鐥呭尯锛�
+      satisfactionScope: 'leave',
       queryParams: {
         dateRange: [],
         interval: 'month',
@@ -226,6 +240,10 @@
     },
     defaultWardCodes() {
       return Array.from(new Set(this.wardCodeList.map((w) => w.districtCode)));
+    },
+    // 鏄惁鎸夈�屽湪闄㈡弧鎰忓害銆嶅彛寰勬煡璇紙娓呯┖涓嬫媺鏃舵寜榛樿鐨勭闄㈠彛寰勶級
+    isInHospitalSatisfaction() {
+      return this.satisfactionScope === 'hospital';
     },
     intervalLabel() {
       return { day: '鎸夊ぉ', week: '鎸夊懆', month: '鎸夋湀', year: '鎸夊勾' }[this.queryParams.interval] || '鎸夋湀';
@@ -371,6 +389,11 @@
       if (!den) return '0.00';
       return (num / den).toFixed(2);
     },
+    // 缁煎悎寰楀垎灞曠ず锛氱洿鎺ヤ娇鐢ㄥ悗绔� avgScore锛屾牸寮忓寲涓轰袱浣嶅皬鏁�
+    formatScore(val) {
+      const n = Number(val);
+      return isNaN(n) ? '0.00' : n.toFixed(2);
+    },
     // 瑙f瀽姣斾緥瀛楃涓诧細"14.29%"銆�"0"銆�"0.5" 鈫� 鏁板�硷紙鐧惧垎姣旓級锛涙棤鏁堣繑鍥� null
     parsePercent(value) {
       if (value == null || value === '') return null;
@@ -382,7 +405,13 @@
       const arr = Array.isArray(list) ? list : (list && (list.list || list.rows)) || [];
       const options = [];
       let total = 0;
+      let avgScore = null;
       arr.forEach((item) => {
+        // 缁煎悎寰楀垎锛氬悗绔繑鍥炵殑棰樼洰绾� avgScore锛堜笌棰樼洰鍚岀骇锛�
+        if (avgScore == null) {
+          const rawAvg = Number(item && item.avgScore);
+          if (!isNaN(rawAvg)) avgScore = rawAvg;
+        }
         const details = Array.isArray(item && item.subtaskDetailRatioExportList)
           ? item.subtaskDetailRatioExportList
           : [];
@@ -395,7 +424,7 @@
           total += count;
         });
       });
-      return { options, total };
+      return { options, total, avgScore };
     },
     // 鍗曢閫夐」缁熻锛堢湡瀹炴帴鍙� /smartor/serviceSubtaskDetail/sltdMydTotalByScore锛�
     async fetchSingleQuestion() {
@@ -415,17 +444,22 @@
           questionContent: this.singleQuestionContent,
         };
         const sel = this.singleDeptWards || [];
+        // 绉戝/鐥呭尯鏉′欢闅忋�屾弧鎰忓害绫诲瀷銆嶅垏鎹細鍦ㄩ櫌 => deptcodes/hospitaldistrictcodes锛岀闄� => leaveldeptcodes/leavehospitaldistrictcodes
         if (this.queryParams.dimension === 'dept') {
           const names = sel.map((s) => String(s).replace(/^dept:/, ''));
-          payload.leaveldeptcodes = names.length ? this.mapDeptNames(names) : this.defaultDeptCodes;
+          const codes = names.length ? this.mapDeptNames(names) : this.defaultDeptCodes;
+          if (this.isInHospitalSatisfaction) payload.deptcodes = codes;
+          else payload.leaveldeptcodes = codes;
         } else {
           const names = sel.map((s) => String(s).replace(/^ward:/, ''));
-          payload.leavehospitaldistrictcodes = names.length ? this.mapWardNames(names) : this.defaultWardCodes;
+          const codes = names.length ? this.mapWardNames(names) : this.defaultWardCodes;
+          if (this.isInHospitalSatisfaction) payload.hospitaldistrictcodes = codes;
+          else payload.leavehospitaldistrictcodes = codes;
         }
         const res = await sltdMydTotalByScore(payload);
         console.log('[sltdMydTotalByScore 鍗曢] code=', res && res.code, 'data=', JSON.stringify(res && res.data).slice(0, 1500));
         const list = res && res.code === 200 ? res.data : [];
-        const { options, total } = this.normalizeSingleQuestion(list);
+        const { options, total, avgScore } = this.normalizeSingleQuestion(list);
         this.singleQuestionData = options.map((o) => ({
           option: o.option,
           count: o.count,
@@ -435,7 +469,7 @@
         }));
         this.singleQuestionMeta = {
           total: total.toLocaleString(),
-          score: this.scoreOfOptions(options),
+          score: this.formatScore(avgScore),
         };
         if (!options.length) this.notify('褰撳墠鏉′欢涓嬫殏鏃犺棰樼殑閫夐」缁熻鏁版嵁', 'warning');
       } catch (e) {
@@ -864,7 +898,7 @@
 
 <style lang="scss" scoped>
 .export-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
-.filter-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; .filter-label { font-size: 13px; color: #606266; } .filter-date { width: 260px; } }
+.filter-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; .filter-label { font-size: 13px; color: #606266; } .filter-date { width: 260px; } .filter-scope { width: 140px; } }
 .chart-card { margin-bottom: 0; }
 .chart-box { width: 100%; height: 360px; }
 .chart-wrap { position: relative; width: 100%; }

--
Gitblit v1.9.3