Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

chen.cheng 10 сар өмнө
parent
commit
a49fa4ec62

+ 85 - 61
ems-ui/src/views/mgr/charging.vue

@@ -163,7 +163,6 @@ export default {
     const nowDay = new Date()
     const lastMonth = new Date(nowDay.getFullYear(), nowDay.getMonth() - 1)
     return {
-
       activeTab: 'first',
       // 总条数
       areaName: undefined,
@@ -204,6 +203,7 @@ export default {
   created() {
     this.setDefaultMonthRange()
     this.handleTabChange()
+
   },
   computed: {
     pieOptions() {
@@ -488,7 +488,6 @@ export default {
     }
   },
   methods: {
-
     meterClsChange(value) {
       this.queryParams.meterCls = value;
       this.getList('current')
@@ -498,7 +497,7 @@ export default {
       const nowDay = new Date()
       const lastMonth = new Date(nowDay.getFullYear(), nowDay.getMonth() - 1)
       const months = this.getPreviousFiveMonthsYearMonth(lastMonth)
-      const { year, month } = months[months.length - 1]
+      const {year, month} = months[months.length - 1]
       const lastFiveMonth = month < 10 ? `0${month}` : month
       this.queryParams.historyRange = [`${year}${lastFiveMonth}`, this.lastMonth]
     },
@@ -512,7 +511,7 @@ export default {
             month: 12 + month
           }
         }
-        return { year, month: month + 1 }
+        return {year, month: month + 1}
       })
       return months
     },
@@ -525,68 +524,91 @@ export default {
       })
       return name
     },
-    getList(type) {
-      let startTime = null
-      let endTime = null
-      const { areaCode, meterCls, historyRange } = this.queryParams
+    async getList(type) {
+      let startTime = null;
+      let endTime = null;
+      const { areaCode, meterCls, historyRange } = this.queryParams;
+
       if (type === 'current') {
-        startTime = this.lastMonth
-        endTime = this.lastMonth
+        startTime = this.lastMonth;
+        endTime = this.lastMonth;
       } else {
-        startTime = historyRange[0]
-        endTime = historyRange[1]
+        startTime = historyRange[0];
+        endTime = historyRange[1];
       }
-      // 个户
-      if (this.activeTab === 'second') {
-        chargingList({
-          areaPath: areaCode,
-          tier: 'Zoning',
-          meterCls,
-          startTime,
-          endTime
-        }).then(({ data }) => {
-          if (type === 'current') {
-            this.currentData = data || []
+
+      try {
+        // 个户
+        if (this.activeTab === 'second') {
+          const response = await chargingList({
+            areaPath: areaCode,
+            tier: 'Zoning',
+            meterCls,
+            startTime,
+            endTime
+          });
+          if (response && response.data) {
+            if (type === 'current') {
+              this.currentData = response.data;
+              console.log("现在数据", this.currentData);
+            } else {
+              this.historyData = response.data;
+            }
           } else {
-            this.historyData = data || []
+            console.error('请求数据失败,无数据返回');
           }
-        })
-      } else {
-        overviewInfo({
-          areaPath: areaCode,
-          tier: 'Area',
-          meterCls,
-          startTime,
-          endTime
-        }).then(({ data }) => {
-          if (type === 'current') {
-            this.currentData = data || []
+        } else {
+          const response = await overviewInfo({
+            areaPath: areaCode,
+            tier: 'Area',
+            meterCls,
+            startTime,
+            endTime
+          });
+          if (response && response.data) {
+            if (type === 'current') {
+              this.currentData = response.data;
+            } else {
+              this.historyData = response.data;
+            }
           } else {
-            this.historyData = data || []
+            console.error('请求数据失败,无数据返回');
           }
-        })
+        }
+      } catch (error) {
+        console.error('请求数据失败1111111:', error);
       }
     },
+
     async handleTabChange() {
-      // 根据newTabName给someParam赋值
       if (this.activeTab === 'first') {
-        await this.getAreaTreeByTag('Area', 'Area_01')
-        this.queryParams.areaCode = this.areaOptions[0].id
-        this.$refs['tree'].setCurrentKey(this.queryParams.areaCode)
+        await this.getAreaTreeByTag('Area', 'Area_01');
+        if (this.areaOptions.length > 0) {
+          // 设置默认展开的节点
+          this.defalutArr = [];
+          this.recursion(this.areaOptions[0], this.defalutArr);
+          this.queryParams.areaCode = this.defalutArr.join('/');
+          this.$refs['tree'].setCurrentKey(this.defalutArr[this.defalutArr.length - 1]);
+          this.$refs['tree'].setCheckedKeys([this.queryParams.areaCode]);
+        }
       } else if (this.activeTab === 'second') {
-        await this.getAreaTreeByTag('Zoning', 'Area_01')
-        this.defalutArr = []
-        this.recursion(this.areaOptions[0], this.defalutArr)
-        this.queryParams.areaCode = this.defalutArr.join('/')
-        this.$refs['tree'].setCurrentKey(this.defalutArr[this.defalutArr.length - 1])
+        await this.getAreaTreeByTag('Zoning', 'Area_01');
+        this.defalutArr = [];
+        this.recursion(this.areaOptions[0], this.defalutArr);
+        this.queryParams.areaCode = this.defalutArr.join('/');
+        this.$refs['tree'].setCurrentKey(this.defalutArr[this.defalutArr.length - 1]);
+        this.$refs['tree'].setCheckedKeys([this.queryParams.areaCode]);
       }
-      this.meterClsChange(45)
+      this.meterClsChange(45);
     },
+
     recursion(data, defalutArr) {
-      defalutArr.push(data.id)
       if (data.children && data.children.length) {
-        this.recursion(data.children[0], defalutArr)
+        data.children.forEach((child) => {
+          this.recursion(child, defalutArr);
+        });
       }
+      defalutArr.push(data.id);
     },
     /** 查询区域树结构 */
     async getAreaTreeByTag(tier, tagCode) {
@@ -601,23 +623,25 @@ export default {
     },
     handleNodeClick(data, node) {
       // 商户树形结构只能点击最后一级
-      if (this.activeTab === 'second' && node.level < 3) return this.$refs['tree'].setCurrentKey(null)
-      const nodeArr = []
-      //  获取点击当节点的dom的信息
-      const selectNode = this.$refs.tree.getNode(data)
-      // 调用递归函数
-      this.platform(selectNode, nodeArr)
-      this.queryParams.areaCode = nodeArr.map(item => item.id).join('/')
+      if (this.activeTab === 'second' && node.level < 3) {
+        return this.$refs['tree'].setCurrentKey(null);
+      }
+      const nodeArr = [];
+      const selectNode = this.$refs.tree.getNode(data);
+      this.platform(selectNode, nodeArr);
+      this.queryParams.areaCode = nodeArr.map(item => item.id).join('/');
+      this.$refs['tree'].setCurrentKey(this.queryParams.areaCode);
+      this.getList('current'); // 获取当月数据
+      this.getList('history'); // 获取历史数据
     },
     // 递归函数
     platform(node, array) {
       if (!node.parent) {
-        return
+        return;
       }
-      array.unshift(node.data)
-      // 调用递归
-      this.platform(node.parent, array)
-    }
+      array.unshift(node.data);
+      this.platform(node.parent, array);
+    },
   }
 }
 </script>