Browse Source

feat: 企微数据 - 首页 - 新增"总消耗&总回收"折线图模块

zhengxy 2 years ago
parent
commit
de269d5660
1 changed files with 69 additions and 22 deletions
  1. 69 22
      project/src/components/HomeData.vue

+ 69 - 22
project/src/components/HomeData.vue

32
     </div>
32
     </div>
33
     <div class="trendBox" v-loading="trends_loading">
33
     <div class="trendBox" v-loading="trends_loading">
34
       <div class="legendBox">
34
       <div class="legendBox">
35
-        <div class="legendItem" v-for="(item,index) in legendList" :key="index" @click="changeLegend(item,index)">{{item.name}}
35
+        <div class="legendItem" v-for="(item,index) in legendList" :key="index" @click="changeLegend('legendList',item,index)">{{item.name}}
36
           <div :class="['checkbox',item.selectFlag?'checkbox_active':'']" :style="item.selectFlag?`background: ${item.color};
36
           <div :class="['checkbox',item.selectFlag?'checkbox_active':'']" :style="item.selectFlag?`background: ${item.color};
37
     border-color: ${item.color};`:''"><i class="el-icon-check"></i></div>
37
     border-color: ${item.color};`:''"><i class="el-icon-check"></i></div>
38
         </div>
38
         </div>
47
       <div id="trend" style="width:100%;height:250px"></div>
47
       <div id="trend" style="width:100%;height:250px"></div>
48
       <noData class="noData" v-if="custTrends&&custTrends.length<=0&&!trends_loading"></noData>
48
       <noData class="noData" v-if="custTrends&&custTrends.length<=0&&!trends_loading"></noData>
49
     </div>
49
     </div>
50
+    <!-- S 新增"总消耗"、"总回收"图表 -->
51
+    <div class="trendBox mt-10" v-loading="trends_loading">
52
+      <div class="legendBox">
53
+        <div class="legendItem" v-for="(item,index) in legendListNew" :key="index" @click="changeLegend('legendListNew',item,index)">{{item.name}}
54
+          <div :class="['checkbox',item.selectFlag?'checkbox_active':'']" :style="item.selectFlag?`background: ${item.color};
55
+    border-color: ${item.color};`:''"><i class="el-icon-check"></i></div>
56
+        </div>
57
+      </div>
58
+      <div id="trendNew" style="width:100%;height:250px"></div>
59
+      <noData class="noData" v-if="custTrendsNew&&custTrendsNew.length<=0&&!trends_loading"></noData>
60
+    </div>
61
+    <!-- E 新增"总消耗"、"总回收"图表 -->
50
     <div class="listBox" v-loading="custDataListLoading">
62
     <div class="listBox" v-loading="custDataListLoading">
51
       <h3>企微列表</h3>
63
       <h3>企微列表</h3>
52
       <ux-grid ref="plxTable" :border="false" @row-click="()=>{return}" :header-cell-style="()=>{return { backgroundColor: '#FFFFFF !important', border: 'none!important' }}" :height="height" show-footer-overflow="tooltip" show-overflow="tooltip" size="mini">
64
       <ux-grid ref="plxTable" :border="false" @row-click="()=>{return}" :header-cell-style="()=>{return { backgroundColor: '#FFFFFF !important', border: 'none!important' }}" :height="height" show-footer-overflow="tooltip" show-overflow="tooltip" size="mini">
70
 <script>
82
 <script>
71
 import datePicker from '@/components/assembly/screen/datePicker.vue'
83
 import datePicker from '@/components/assembly/screen/datePicker.vue'
72
 import noData from "@/components/assembly/noData";
84
 import noData from "@/components/assembly/noData";
85
+import _lodash from 'lodash'
73
 export default {
86
 export default {
74
   components: { datePicker, noData },
87
   components: { datePicker, noData },
75
   data () {
88
   data () {
89
         { name: '付费金额', key: 'cust_pay_amount', color: '#F28544', selectFlag: true },
102
         { name: '付费金额', key: 'cust_pay_amount', color: '#F28544', selectFlag: true },
90
         { name: '付费用户客单价', key: 'charge_user_cost', color: '#E360C8', selectFlag: true },
103
         { name: '付费用户客单价', key: 'charge_user_cost', color: '#E360C8', selectFlag: true },
91
       ],
104
       ],
105
+      legendListNew: [
106
+        { name: '总消耗', key: 'total_cost', color: '#2983DF', selectFlag: true },
107
+        { name: '总回收', key: 'total_cust_pay_amount', color: '#EB4315', selectFlag: true },
108
+      ],
92
       data_loading: false,
109
       data_loading: false,
93
       custTotal: [
110
       custTotal: [
94
         {
111
         {
184
       default_time: [this.$getDay(-8, false), this.$getDay(-1, false)],
201
       default_time: [this.$getDay(-8, false), this.$getDay(-1, false)],
185
       time: [],
202
       time: [],
186
       myChart: null,
203
       myChart: null,
204
+      myChartNew: null,
187
       custTrends: [],
205
       custTrends: [],
206
+      custTrendsNew: [],
188
       trends_loading: false,
207
       trends_loading: false,
189
       lastName: '',
208
       lastName: '',
190
       enterpriseList: [],
209
       enterpriseList: [],
328
           start: this.time[0],
347
           start: this.time[0],
329
           end: this.time[1],
348
           end: this.time[1],
330
         }
349
         }
331
-      }).then((res) => {
332
-        var res = res.data
350
+      }).then((_res) => {
351
+        const res = _res.data
333
         this.trends_loading = false
352
         this.trends_loading = false
334
         if (res && res.errno == 0) {
353
         if (res && res.errno == 0) {
335
-          this.custTrends = res.rst;
354
+          // 处理后端返回的数据 => 分离&提取新图表数据
355
+          this.custTrends = _lodash.cloneDeep(res.rst)
356
+          this.custTrends.forEach(item => {
357
+            delete item['total_cost']
358
+            delete item['total_cust_pay_amount']
359
+          })
360
+          this.custTrendsNew = _lodash.cloneDeep(res.rst).map(item => ({
361
+            idate: item['idate'],
362
+            total_cost: item['total_cost'],
363
+            total_cust_pay_amount: item['total_cust_pay_amount']
364
+          }))
336
           this.$nextTick(() => {
365
           this.$nextTick(() => {
337
-            this.trendEvent()
366
+            this.trendEvent('custTrends') // 绘制图表
367
+            this.trendEvent('custTrendsNew') // 绘制新图表
338
           })
368
           })
339
         } else if (res.errno != 4002) {
369
         } else if (res.errno != 4002) {
340
           this.$message({
370
           this.$message({
346
         this.trends_loading = false
376
         this.trends_loading = false
347
       });
377
       });
348
     },
378
     },
349
-    trendEvent () {
350
-      this.myChart && this.myChart.clear()
351
-      var _this = this;
352
-      var series = [], yAxis = []
353
-      let xArr = this.custTrends.map((v) => {
379
+    /**
380
+     * chartDataName 图表数据名称
381
+     */
382
+    trendEvent (chartDataName) {
383
+      // 旧图表
384
+      chartDataName === 'custTrends' && this.myChart && this.myChart.clear()
385
+      // 新图表
386
+      chartDataName === 'custTrendsNew' && this.myChartNew && this.myChartNew.clear()
387
+
388
+      const _this = this;
389
+      let series = [], yAxis = []
390
+      let xArr = this[chartDataName].map((v) => {
354
         return v.idate
391
         return v.idate
355
       });
392
       });
356
-      this.legendList.forEach((item, index) => {
393
+      this[chartDataName === 'custTrends' ? 'legendList' : 'legendListNew'].forEach((item, index) => {
357
         if (item.selectFlag) {
394
         if (item.selectFlag) {
358
           yAxis.push(
395
           yAxis.push(
359
             {
396
             {
385
                 fontSize: 12,
422
                 fontSize: 12,
386
                 show: true,
423
                 show: true,
387
                 formatter: function (params) {
424
                 formatter: function (params) {
388
-                  var result = params;
389
-                  var resultData;
425
+                  let result = params;
426
+                  let resultData;
390
                   resultData = _this.$NumberHandle(result)
427
                   resultData = _this.$NumberHandle(result)
391
                   return resultData;
428
                   return resultData;
392
                 }
429
                 }
394
             })
431
             })
395
 
432
 
396
           // series
433
           // series
397
-          let data = this.custTrends.map((v) => {
434
+          let data = this[chartDataName].map((v) => {
398
             return v[item.key] || v[item.key] == 0 ? v[item.key] : '-'
435
             return v[item.key] || v[item.key] == 0 ? v[item.key] : '-'
399
           });
436
           });
400
           series.push({
437
           series.push({
420
       series.forEach((item, index) => {
457
       series.forEach((item, index) => {
421
         item.yAxisIndex = index
458
         item.yAxisIndex = index
422
       })
459
       })
423
-      var option = {
460
+      let option = {
424
         title: '',
461
         title: '',
425
         tooltip: {
462
         tooltip: {
426
           trigger: 'axis',
463
           trigger: 'axis',
427
           show: true,
464
           show: true,
428
           formatter: function (params) {
465
           formatter: function (params) {
429
-            var result = params[0].name;
466
+            let result = params[0].name;
430
             result += '<br/>'
467
             result += '<br/>'
431
             params.forEach((item, index) => {
468
             params.forEach((item, index) => {
432
               result +=
469
               result +=
484
         series: series
521
         series: series
485
       };
522
       };
486
       //初始化echarts实例
523
       //初始化echarts实例
487
-      this.myChart = this.myChart ? this.myChart : this.$echarts.init(document.getElementById('trend'));
488
-      this.myChart.setOption(option);
524
+      if (chartDataName === 'custTrends') {
525
+        this.myChart = this.myChart ? this.myChart : this.$echarts.init(document.getElementById('trend'));
526
+        this.myChart.setOption(option);
527
+      } else if (chartDataName === 'custTrendsNew') {
528
+        this.myChartNew = this.myChartNew ? this.myChartNew : this.$echarts.init(document.getElementById('trendNew'));
529
+        this.myChartNew.setOption(option);
530
+      }
489
     },
531
     },
490
-    changeLegend (data, index) {
491
-      let arr = this.legendList.filter((v) => {
532
+    changeLegend (legendListName, data, index) {
533
+      let arr = this[legendListName].filter((v) => {
492
         return v.selectFlag
534
         return v.selectFlag
493
       })
535
       })
494
       if (arr.length == 1 && arr[0].key == data.key) {
536
       if (arr.length == 1 && arr[0].key == data.key) {
500
       }
542
       }
501
       let item = data;
543
       let item = data;
502
       item.selectFlag = !item.selectFlag;
544
       item.selectFlag = !item.selectFlag;
503
-      this.$set(this.legendList, index, item)
545
+      this.$set(this[legendListName], index, item)
504
       this.$nextTick(() => {
546
       this.$nextTick(() => {
505
-        this.trendEvent()
547
+        legendListName === 'legendList' && this.trendEvent('custTrends')
548
+        legendListName === 'legendListNew' && this.trendEvent('custTrendsNew')
506
       })
549
       })
507
     },
550
     },
508
     changeTime (time) {//筛选时间变化
551
     changeTime (time) {//筛选时间变化
516
   },
559
   },
517
   beforeDestroy () {
560
   beforeDestroy () {
518
     this.myChart && this.myChart.clear()
561
     this.myChart && this.myChart.clear()
562
+    this.myChartNew && this.myChartNew.clear()
519
   },
563
   },
520
   beforeRouteEnter (to, from, next) {
564
   beforeRouteEnter (to, from, next) {
521
     next(vm => {          //  这里的vm指的就是vue实例,可以用来当做this使用
565
     next(vm => {          //  这里的vm指的就是vue实例,可以用来当做this使用
525
 }
569
 }
526
 </script>
570
 </script>
527
 <style lang="scss" scoped>
571
 <style lang="scss" scoped>
572
+.mt-10 {
573
+  margin-top: 10px;
574
+}
528
 .dataInfoBox {
575
 .dataInfoBox {
529
   display: flex;
576
   display: flex;
530
   flex-wrap: wrap;
577
   flex-wrap: wrap;