许静 5 years ago
parent
commit
ce92a99ba8

+ 80
- 0
src/components/charts/XLine.vue View File

1
+<template>
2
+   <div ref="thirdChart" ></div>
3
+</template>
4
+<script>
5
+import Echarts from "echarts";
6
+export default {
7
+  name: "XLine",
8
+  props: ["value"],
9
+  data() {
10
+    return {
11
+      chart: undefined,
12
+      defaultOpts: {
13
+        //  dataset: {
14
+        //   dimensions: ['date', 'userCount', 'authorizationCount'],
15
+        //   source,
16
+        // },
17
+        title: {
18
+          text: "新增用户"
19
+        },
20
+        color: ["purple", "green"],
21
+        tooltip: {
22
+          trigger: "axis"
23
+        },
24
+        legend: {
25
+          data: ["新用户数", "授权注册"]
26
+        },
27
+        grid: {
28
+          left: "3%",
29
+          right: "4%",
30
+          bottom: "3%",
31
+          containLabel: true
32
+        },
33
+        toolbox: {},
34
+        xAxis: {
35
+          type: "category",
36
+          boundaryGap: false
37
+        },
38
+        yAxis: {
39
+          type: "value"
40
+        },
41
+        series: [
42
+          {
43
+            name: "新用户数",
44
+            type: "line",
45
+            stack: "1"
46
+          },
47
+          {
48
+            name: "授权注册",
49
+            type: "line",
50
+            stack: "2"
51
+          }
52
+        ]
53
+      }
54
+    };
55
+  },
56
+  watch: {
57
+    value (val) {
58
+      this.renderChart(val)
59
+    },
60
+  },
61
+  mounted() {
62
+    if (!this.chart) {
63
+      this.chart = Echarts.init(this.$refs.thirdChart);
64
+      this.renderChart(this.value)
65
+    }
66
+  },
67
+  methods: {
68
+    renderChart(val) {
69
+      // 绘制图表
70
+      this.chart.setOption({
71
+        ...this.defaultOpts,
72
+        ...val
73
+      });
74
+    }
75
+  }
76
+};
77
+</script>
78
+<style>
79
+</style>
80
+

+ 4
- 0
src/config/api.js View File

323
       method:'get',
323
       method:'get',
324
       url: `${commPrefix}/indexStatistical`
324
       url: `${commPrefix}/indexStatistical`
325
     },
325
     },
326
+    newsUserCount:{
327
+      method:'get',
328
+      url: `${commPrefix}/selectNewsUserCount`
329
+    },
326
   },
330
   },
327
 }
331
 }
328
 export default apis
332
 export default apis

+ 20
- 0
src/store/modules/indexEcharts.js View File

5
   namespaced: true,
5
   namespaced: true,
6
   state: {
6
   state: {
7
     echartsInfo: {},
7
     echartsInfo: {},
8
+    newsUserCount:{}
8
   },
9
   },
9
   mutations: {
10
   mutations: {
10
     updateList (state, payload) {
11
     updateList (state, payload) {
11
       state.echartsInfo = payload
12
       state.echartsInfo = payload
12
     },
13
     },
14
+    updateNewsUserCount (state, payload) {
15
+      state.newsUserCount = payload
16
+    },
13
   },
17
   },
14
   actions: {
18
   actions: {
15
     setDetailNull ({ commit }) {
19
     setDetailNull ({ commit }) {
31
         })
35
         })
32
       })
36
       })
33
     },
37
     },
38
+    getNewsUserCount ({ commit }, payload) {
39
+      return new Promise((resolve, reject) => {
40
+        request({
41
+          ...apis.indexEcharts.newsUserCount,
42
+          params: payload,
43
+        }).then((data) => {
44
+          commit('updateNewsUserCount', data)
45
+          resolve(data)
46
+        }).catch((err) => {
47
+          const message = err.message || err.msg
48
+          if (typeof message === 'string') {
49
+            reject(message)
50
+          }
51
+        })
52
+      })
53
+    },
34
     // changeExchangeStatus (_, payload) {
54
     // changeExchangeStatus (_, payload) {
35
     //   return new Promise((resolve, reject) => {
55
     //   return new Promise((resolve, reject) => {
36
     //     request({
56
     //     request({

+ 1
- 1
src/views/indexEcharts/index.vue View File

540
       //   this.members.push(this.echartsInfo.selectUserBehavior[i].members);
540
       //   this.members.push(this.echartsInfo.selectUserBehavior[i].members);
541
       // }
541
       // }
542
     }
542
     }
543
-    this.drawLine();
543
+    this.initPage();
544
   }
544
   }
545
 };
545
 };
546
 </script>
546
 </script>

+ 57
- 57
src/views/indexEcharts/newUsers.vue View File

9
       end-placeholder="结束日期"
9
       end-placeholder="结束日期"
10
       default-value="2019-08-08">
10
       default-value="2019-08-08">
11
     </el-date-picker></p>
11
     </el-date-picker></p>
12
-  <div class="grid-content" ref="thirdChart"  id="thirdChart"  :style="{ height: '500px',margin:'20px 0',border:'1px solid #eee', padding:'20px',borderRadius:'5px'}" ></div>
13
-   <el-table :data="tableData2"  border  center  style="width: 100%">
14
-    <el-table-column label="用户姓名" prop="name"></el-table-column>
15
-    <el-table-column label="手机号" prop="phone"></el-table-column>
16
-    <el-table-column label="意向楼盘" prop="building"></el-table-column>
17
-    <el-table-column label="意向值" prop="num"></el-table-column>
12
+  <x-line :style="{ height: '500px',margin:'20px 0',border:'1px solid #eee', padding:'20px',borderRadius:'5px'}"  :value="lineSeting"></x-line>
13
+   <el-table :data="tableData"  border  center  style="width: 100%">
14
+    <el-table-column v-for="(item, index) in tableTitle" :key="index" :label="item" :prop="index == 0 ? 'label': item"></el-table-column>
18
   </el-table>
15
   </el-table>
19
 
16
 
20
 </div>
17
 </div>
24
 import { createNamespacedHelpers } from "vuex";
21
 import { createNamespacedHelpers } from "vuex";
25
 import apis from "../../config/api";
22
 import apis from "../../config/api";
26
 import { mapState } from "vuex";
23
 import { mapState } from "vuex";
27
-import Echarts from "echarts";
28
 
24
 
25
+const {
26
+  mapState: mapIndexEchartsState,
27
+  mapActions: mapIndexEchartsActions
28
+} = createNamespacedHelpers("indexEcharts");
29
 export default {
29
 export default {
30
-  components: {},
30
+  components: {
31
+    XLine: () => import('@/components/charts/XLine.vue'),
32
+  },
31
   data() {
33
   data() {
32
     return {
34
     return {
33
-      value: '',
34
-       tableData2: [
35
+      value: "",
36
+      lineSeting: {
37
+        dataset: {
38
+          dimensions: ['date', 'userCount', 'authorizationCount'],
39
+          source: [],
40
+        },
41
+      },
42
+      tableData: [
43
+        { label: '新增用户', },
44
+        { label: '授权注册', }
45
+      ],
46
+      tableTitle: [ '类型' ],
47
+      tableData2: [
35
         {
48
         {
36
           num: "98",
49
           num: "98",
37
           name: "王晓红",
50
           name: "王晓红",
59
       ]
72
       ]
60
     };
73
     };
61
   },
74
   },
62
-  computed: {},
75
+  computed: {
76
+    ...mapIndexEchartsState({
77
+      newsUserCount: x => x.newsUserCount
78
+    })
79
+  },
63
   methods: {
80
   methods: {
64
-    drawLine() {
65
-      // 折线图
66
-      let thirdChart = Echarts.init(this.$refs.thirdChart);
67
-      // 绘制图表
68
-      thirdChart.setOption({
69
-        title: {
70
-          text: "新增用户"
71
-        },
72
-        color: ["purple", "green"],
73
-        tooltip: {
74
-          trigger: "axis"
75
-        },
76
-        legend: {
77
-          data: ["新用户数", "授权注册"]
78
-        },
79
-        grid: {
80
-          left: "3%",
81
-          right: "4%",
82
-          bottom: "3%",
83
-          containLabel: true
84
-        },
85
-        toolbox: {},
86
-        xAxis: {
87
-          type: "category",
88
-          boundaryGap: false,
89
-          data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
90
-        },
91
-        yAxis: {
92
-          type: "value"
93
-        },
94
-        series: [
95
-          {
96
-            name: "新用户数",
97
-            type: "line",
98
-            stack: "1",
99
-            data: [120, 132, 101, 134, 90, 230, 210]
100
-          },
101
-          {
102
-            name: "授权注册",
103
-            type: "line",
104
-            stack: "2",
105
-            data: [220, 182, 191, 234, 290, 330, 310]
106
-          },
107
-        ]
81
+    ...mapIndexEchartsActions(["getNewsUserCount"]),
82
+    initPage() {
83
+      this.getNewsUserCount().then(x => {
84
+        const data = this.newsUserCount.selectNewsUserCount
85
+        this.lineSeting.dataset.source = data
86
+        this.tableData = (data || []).reduce((acc, item, index) => {
87
+          const { date, userCount, authorizationCount } = item
88
+
89
+          const row2 = {
90
+            ...acc[0],
91
+            [`${date}`]: userCount,
92
+          }
93
+
94
+          const row3 = {
95
+            ...acc[1],
96
+            [`${date}`]: authorizationCount,
97
+          }
98
+
99
+          this.tableTitle = this.tableTitle.concat(`${date}`)
100
+
101
+          return [row2, row3];          
102
+        }, this.tableData)
103
+
104
+
105
+        window.console.log(this.tableData, '-------')
108
       });
106
       });
109
-    }
107
+    },
110
   },
108
   },
111
   mounted() {
109
   mounted() {
112
-    this.drawLine();
110
+    this.initPage();
111
+    // this.drawLine();
112
+  
113
   }
113
   }
114
 };
114
 };
115
 </script>
115
 </script>