From 6f1e7a63fa6afc261ba2247bf1d56f59dbb9f4c9 Mon Sep 17 00:00:00 2001
From: WXL <1785969728@qq.com>
Date: 星期四, 07 八月 2025 17:29:46 +0800
Subject: [PATCH] 测试完成

---
 src/views/index.vue |  250 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 155 insertions(+), 95 deletions(-)

diff --git a/src/views/index.vue b/src/views/index.vue
index 352aa61..d76be1a 100644
--- a/src/views/index.vue
+++ b/src/views/index.vue
@@ -105,13 +105,13 @@
                 ></el-radio-button>
               </el-radio-group>
             </div>
-            <!-- 涓棿echars -->
+            <!-- 涓儴绾挎�ф煴鐘跺浘 -->
             <div class="boxEchars">
               <div class="echars1" id="echars"></div>
             </div>
           </div>
         </el-col>
-        <!-- 涓棿鍜屽彸杈� -->
+        <!-- 鍙宠竟鍒楄〃 -->
         <el-col :span="4" class="aside">
           <div class="grid-content bg-purple" style="margin-top: -180px">
             <div class="title">
@@ -134,9 +134,7 @@
                 ></el-table-column>
 
                 <el-table-column prop="rc" class-name="rc">
-                  <template slot-scope="scope">
-                    {{ scope.row.rc }}娆�
-                  </template>
+                  <template slot-scope="scope"> {{ scope.row.rc }}娆� </template>
                 </el-table-column>
               </el-table>
             </div>
@@ -292,7 +290,7 @@
   getechartsListCountdata,
   getechartsMedOuthospList,
   getechartsMedInhospList,
-  getechartsandData,
+  getServiceStatistics,
   getDeptRanking,
 } from "@/api/AiCentre/index";
 import dayjs from "dayjs";
@@ -310,6 +308,11 @@
       lastHeight: window.innerHeight,
       radio1: "鏈�",
       ticketStatistics: {},
+      timeTypeMap: {
+        鍛�: "day",
+        鏈�: "month",
+        骞�: "year",
+      },
       DischargeData: {
         rs: "",
         rc: "",
@@ -352,7 +355,7 @@
     this.getgraphdata();
     this.getranking();
     this.$nextTick(function () {
-      this.getregionAmountCollect();
+      this.myEcharts2();
       this.getnodeCollect();
       this.getSkuTop();
     });
@@ -379,7 +382,7 @@
       this.getgraphdata();
       this.getranking();
       this.getTopdata();
-      this.getregionAmountCollect();
+      this.myEcharts2();
       this.getnodeCollect();
       this.getSkuTop();
     },
@@ -396,15 +399,15 @@
     },
     // top鎺掕
     async getSkuTop() {
-       let Rankingdata = {
+      let Rankingdata = {
         startDate: this.endatd,
         endDate: this.statd,
         cy: 1,
       };
       await getDeptRanking(Rankingdata).then((res) => {
         if (res.code == 200) {
-          this.SkuTop=res.rows.sort((a, b) => b.rc - a.rc);
-          console.log(this.SkuTop,'this.SkuTop');
+          this.SkuTop = res.rows.sort((a, b) => b.rc - a.rc);
+          console.log(this.SkuTop, "this.SkuTop");
         }
       });
 
@@ -451,26 +454,141 @@
         }
       });
     },
-    // 鑾峰彇灏辫瘖鏁伴噺
-    getranking() {
-
-    },
     // 鑾峰彇涓儴绾挎煴鍥炬暟鎹�
-    getgraphdata() {
-      let Outhospdata = {
+    getranking() {},
+
+    async getgraphdata() {
+      let params = {
         startDate: this.endatd,
         endDate: this.statd,
-        cy: 1,
+        timeType:
+          this.radio1 === "鍛�"
+            ? "day"
+            : this.radio1 === "鏈�"
+            ? "month"
+            : "year",
       };
-      let Inhospdata = {
-        startDate: this.endatd,
-        endDate: this.statd,
-        cy: 1,
+
+      try {
+        const res = await getServiceStatistics(params);
+        if (res.code === 200) {
+          this.processChartData(res.data);
+        }
+      } catch (error) {
+        console.error("鑾峰彇鍥捐〃鏁版嵁澶辫触:", error);
+      }
+    },
+    processChartData(data) {
+      // 鎸夋椂闂存帓搴忕‘淇濇暟鎹『搴忔纭�
+      const sortedData = [...data].sort(
+        (a, b) => new Date(a.timePeriod) - new Date(b.timePeriod)
+      );
+
+      const xAxisData = [];
+      const dischargeFollowData = [];
+      const outpatientFollowData = [];
+      const pmiData = [];
+      const pmoData = [];
+
+      sortedData.forEach((item) => {
+        // 鏍规嵁鏃堕棿绫诲瀷鏍煎紡鍖栨樉绀�
+        let timeLabel = item.timePeriod;
+        if (this.radio1 === "鍛�") {
+          timeLabel = dayjs(item.timePeriod).format("MM-DD");
+        } else if (this.radio1 === "鏈�") {
+          timeLabel = item.timePeriod.split("-")[1] + "鏈�";
+        } else {
+          timeLabel = item.timePeriod.split("-")[0] + "骞�";
+        }
+
+        xAxisData.push(timeLabel);
+        dischargeFollowData.push(item.dischargeFollowCount);
+        outpatientFollowData.push(item.outpatientFollowCount);
+        pmiData.push(item.pmiCount);
+        pmoData.push(item.pmoCount);
+      });
+
+      // 鏇存柊鍥捐〃
+      this.updateChart(
+        xAxisData,
+        dischargeFollowData,
+        outpatientFollowData,
+        pmiData,
+        pmoData
+      );
+    },
+    updateChart(
+      xAxisData,
+      dischargeFollowData,
+      outpatientFollowData,
+      pmiData,
+      pmoData
+    ) {
+      if (!this.myChart2) {
+        this.myEcharts2();
+        return;
+      }
+
+      // 璁$畻闅忚閲忕殑鏈�澶у��
+      const maxFollow = Math.max(
+        ...dischargeFollowData,
+        ...outpatientFollowData
+      );
+      // 璁$畻鏈嶅姟浜烘鐨勬渶澶у��
+      const maxService = Math.max(...pmiData, ...pmoData);
+
+      // 鍔ㄦ�佽绠梚nterval鍊�
+      const followInterval = this.calculateOptimalInterval(maxFollow);
+      const serviceInterval = this.calculateOptimalInterval(maxService);
+
+      const option = {
+        xAxis: {
+          data: xAxisData,
+        },
+        yAxis: [
+          {
+            interval: followInterval,
+            max: Math.ceil(maxFollow / followInterval) * followInterval,
+          },
+          {
+            interval: serviceInterval,
+            max: Math.ceil(maxService / serviceInterval) * serviceInterval,
+          },
+        ],
+        series: [
+          { data: dischargeFollowData },
+          { data: outpatientFollowData },
+          { data: pmiData },
+          { data: pmoData },
+        ],
       };
-      getechartsMedOuthospList(Outhospdata).then((res) => {});
-      getechartsMedInhospList(Inhospdata).then((res) => {});
+
+      this.myChart2.setOption(option);
     },
 
+    // 璁$畻鏈�浼樼殑interval鍊�
+    calculateOptimalInterval(maxValue) {
+      if (maxValue <= 0) return 50; // 榛樿鍊�
+
+      // 鏍规嵁鏈�澶у�艰绠楀悎閫傜殑闂撮殧
+      const magnitude = Math.pow(10, Math.floor(Math.log10(maxValue)));
+      const stepRatio = maxValue / magnitude;
+
+      let interval;
+      if (stepRatio > 5) {
+        interval = magnitude;
+      } else if (stepRatio > 2) {
+        interval = magnitude / 2;
+      } else {
+        interval = magnitude / 5;
+      }
+
+      // 纭繚interval鏄暣鏁�
+      interval = Math.round(interval);
+
+      // 闄愬埗鏈�灏忛棿闅�
+      return Math.max(interval, 50);
+    },
     // 鑾峰彇绾跨姸鍥炬椂闂�
     async getregionAmountCollect() {
       //getregionAmountCollect(1, this.endatd, this.statd);
@@ -480,11 +598,12 @@
       this.series = [123, 123, 223, 212, 432, 123, 442, 234];
       this.myEcharts2();
     },
-    // 绾挎�у浘
+    // 绾挎�у浘鍙婃煴鐘跺浘
     myEcharts2() {
       var echarts = require("echarts");
       var myChart2 = echarts.init(document.getElementById("echars"));
       this.myChart2 = myChart2;
+
       var option2 = {
         tooltip: {
           trigger: "axis",
@@ -504,30 +623,12 @@
           },
         },
         legend: {
-          data: [
-            "鍑洪櫌闅忚閲�",
-            "闂ㄨ瘖闅忚閲�",
-            // "鍦ㄩ櫌闅忚閲�",
-            // "闂ㄨ瘖澶嶈瘖閫氱煡",
-            "鍑洪櫌鏈嶅姟浜烘",
-            "闂ㄨ瘖鏈嶅姟浜烘",
-          ],
+          data: ["鍑洪櫌闅忚閲�", "闂ㄨ瘖闅忚閲�", "鍑洪櫌鏈嶅姟浜烘", "闂ㄨ瘖鏈嶅姟浜烘"],
         },
         xAxis: [
           {
             type: "category",
-            data: [
-              "涓�鏈�",
-              "浜屾湀",
-              "涓夋湀",
-              "鍥涙湀",
-              "浜旀湀",
-              "鍏湀",
-              "涓冩湀",
-              "鍏湀",
-              "涔濇湀",
-              "鍗佹湀",
-            ],
+            data: [], // 鍒濆涓虹┖锛屽皢閫氳繃API鏁版嵁濉厖
             axisPointer: {
               type: "shadow",
             },
@@ -538,18 +639,14 @@
             type: "value",
             name: "闅忚閲�",
             min: 0,
-            max: 250,
-            interval: 50,
             axisLabel: {
               formatter: "{value} 浜�",
             },
           },
           {
             type: "value",
-            name: "澶嶈瘖/璇勪及娆℃暟",
+            name: "鏈嶅姟浜烘",
             min: 0,
-            max: 250,
-            interval: 50,
             axisLabel: {
               formatter: "{value} 娆�",
             },
@@ -565,18 +662,8 @@
                 return value + " 浜�";
               },
             },
-            data: [120, 150, 165, 90, 140, 200, 130, 85, 175, 95, 110, 160],
+            data: [], // 鍒濆涓虹┖锛屽皢閫氳繃API鏁版嵁濉厖
           },
-          // {
-          //   name: "褰卞儚闅忚閲�",
-          //   type: "bar",
-          //   tooltip: {
-          //     valueFormatter: function (value) {
-          //       return value + " 浜�";
-          //     },
-          //   },
-          //   data: [102, 190, 135, 88, 175, 160, 83, 145, 200, 110, 97, 180],
-          // },
           {
             name: "闂ㄨ瘖闅忚閲�",
             type: "bar",
@@ -585,21 +672,8 @@
                 return value + " 浜�";
               },
             },
-            data: [145, 92, 178, 134, 167, 85, 199, 112, 156, 88, 120, 145],
+            data: [], // 鍒濆涓虹┖锛屽皢閫氳繃API鏁版嵁濉厖
           },
-
-          // {
-          //   name: "鍑洪櫌澶嶈瘖閫氱煡",
-          //   type: "line",
-          //   smooth: 0.3,
-          //   yAxisIndex: 1,
-          //   tooltip: {
-          //     valueFormatter: function (value) {
-          //       return value + " 娆�";
-          //     },
-          //   },
-          //   data: [45, 123, 78, 156, 89, 34, 199, 112, 67, 145, 88, 175],
-          // },
           {
             name: "鍑洪櫌鏈嶅姟浜烘",
             type: "line",
@@ -610,7 +684,7 @@
                 return value + " 娆�";
               },
             },
-            data: [102, 190, 135, 88, 175, 160, 83, 145, 200, 110, 97, 180],
+            data: [], // 鍒濆涓虹┖锛屽皢閫氳繃API鏁版嵁濉厖
           },
           {
             name: "闂ㄨ瘖鏈嶅姟浜烘",
@@ -622,29 +696,15 @@
                 return value + " 娆�";
               },
             },
-            data: [120, 150, 165, 90, 140, 200, 130, 85, 175, 95, 110, 160],
+            data: [], // 鍒濆涓虹┖锛屽皢閫氳繃API鏁版嵁濉厖
           },
         ],
       };
-      myChart2.on("updateAxisPointer", function (event) {
-        const xAxisInfo = event.axesInfo[0];
-        if (xAxisInfo) {
-          const dimension = xAxisInfo.value + 1;
-          myChart2.setOption({
-            series: {
-              id: "pie",
-              label: {
-                formatter: "{b}: {@[" + dimension + "]} ",
-              },
-              encode: {
-                value: dimension,
-                tooltip: dimension,
-              },
-            },
-          });
-        }
-      });
+
       myChart2.setOption(option2);
+
+      // 鍒濆鍔犺浇鏁版嵁
+      this.getgraphdata();
     },
     // 楗肩姸鍥�
     myPieChart() {

--
Gitblit v1.9.3