From e2b55c8bbba3492d7cc97e5bfe97589aaf932b1f Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期三, 20 十二月 2023 19:24:24 +0800
Subject: [PATCH] 整合代码

---
 Source/UBCS-WEB/src/views/statistic/statisticPage.vue |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/Source/UBCS-WEB/src/views/statistic/statisticPage.vue b/Source/UBCS-WEB/src/views/statistic/statisticPage.vue
index 0369f5c..ea9146a 100644
--- a/Source/UBCS-WEB/src/views/statistic/statisticPage.vue
+++ b/Source/UBCS-WEB/src/views/statistic/statisticPage.vue
@@ -100,10 +100,12 @@
   },
   created() {
     this.getMasterList();
-    this.getEcharts();
     // deleteChartId({btmname:'zxssaac',chartId:'3'}).then(res=>{
     //   console.log('res',res)
     // })
+  },
+  mounted() {
+    this.getEcharts();
   },
   methods: {
     getMasterList() {
@@ -114,21 +116,45 @@
         this.$message.error(error)
       })
     },
-    getEcharts() {
-      getBtmAndChart().then(firstResponse => {
-        console.log('btm', firstResponse)
+    async getEcharts() {
+      try {
+        const firstResponse = await getBtmAndChart();
+        const typeList = {
+          "0": "lineList",
+          "1": "pieList",
+          "2": "columnarList",
+          "3": "mixList"
+        };
+
         const btmNames = Object.keys(firstResponse.data.data).join(',');
         const firstData = firstResponse.data.data;
-        Object.keys(firstData).forEach((item,index) => {
-          let firstIndex = firstData[item].split(',');
-          console.log('firstIndex',firstIndex);
-        });
         if (btmNames) {
-          getStatisticAnalysis({btmNames}).then(secondResponse => {
-            console.log('getStatisticAnalysis', secondResponse)
+          const secondResponse = await getStatisticAnalysis({btmNames});
+          const secondData = secondResponse.data.data;
+          //Object.keys瀵艰嚧瀵硅薄椤哄簭涓嶄竴鑷达紝浣跨敤sort鎺掑簭涓庡悗绔繑鍥炴牸寮忎竴鑷�
+          Object.keys(firstData).sort().forEach((key, index) => {
+            if (firstData[key]) {
+              const indexes = firstData[key].split(',');
+              for (const indexSec of indexes) {
+                const type = typeList[indexSec];
+                const List = secondData.map(record => {
+                  return {
+                    menuData: record.menuData,
+                    menuName: record.menuName
+                  }
+                })
+                List.forEach((i, j) => {
+                  if (index === j) {
+                    this[type].push(i)
+                  }
+                })
+              }
+            }
           })
         }
-      })
+      } catch (error) {
+        console.error('Error:', error);
+      }
     },
     //鏂板
     addHandler() {
@@ -179,8 +205,6 @@
         const dataKey = typeList[item.codeType];
         if (dataKey) {
           this[dataKey].push(item);
-          this[dataKey].forEach(res => {
-          })
           hasValidData = true;
         }
       });
@@ -192,6 +216,7 @@
     },
     //琛ㄦ牸澶氶��
     selectChange(selection) {
+      console.log('selection', selection)
       this.selectData = selection;
     },
   }

--
Gitblit v1.9.3