张延森 преди 5 години
родител
ревизия
a910281f8a

+ 0
- 88
src/components/charts/PieSecondChart.vue Целия файл

@@ -1,88 +0,0 @@
1
-<template>
2
-    <div>
3
-        <div class="grid-content" ref="secondChart"  id="secondChart" >
4
-        </div>
5
-    </div>
6
-</template>
7
-
8
-<script>
9
-    import Echarts from "echarts";
10
-    export default {
11
-        name: "PieSecondChart",
12
-        props: [
13
-            'value'
14
-        ],
15
-        data() {
16
-            return {
17
-                pieSecondChart: '', // 饼状图实例
18
-                dataVal: this.value,
19
-                pieData: [] // 渲染的数据
20
-            }
21
-
22
-        },
23
-        watch: {
24
-            dataVal(newVal, oldVal) {
25
-                this.pie()
26
-            }
27
-        },
28
-        created() {
29
-            // 饼图
30
-            this.pieSecondChart = Echarts.init(this.$refs.secondChart);
31
-            console.log('this.pieSecondChart : ', this.pieSecondChart)
32
-            // this.pieSecondChart.setOption()
33
-        },
34
-        methods: {
35
-            // init() {
36
-            //     // 饼图
37
-            //     this.pieSecondChart = Echarts.init(this.$refs.secondChart);
38
-            //     console.log('this.pieSecondChart : ', this.pieSecondChart)
39
-            //     this.pieSecondChart.setOption()
40
-            // },
41
-            pie () { // 饼状图绘制
42
-                // 绘制图表
43
-                this.pieSecondChart.setOption({
44
-                    tooltip: {
45
-                        trigger: "item",
46
-                        formatter: "{a} <br/>{b} : {c} ({d}%)"
47
-                    },
48
-                    legend: {
49
-                        orient: "vertical",
50
-                        left: "left",
51
-                        data: ["自主进入", "来源全民经纪人", "来源置业顾问"]
52
-                        // data: this.pieData.title
53
-                    },
54
-                    series: [
55
-                        {
56
-                            name: "访问来源",
57
-                            type: "pie",
58
-                            radius: "55%",
59
-                            center: ["50%", "60%"],
60
-                            label: {
61
-                                normal: {
62
-                                    position: "inner"
63
-                                }
64
-                            },
65
-                            data: [
66
-                                { value: 0, name: "自主进入" },
67
-                                { value: 0, name: "来源全民经纪人" },
68
-                                { value: 0, name: "来源置业顾问" }
69
-                            ],
70
-                            // data: this.pieData.data,
71
-                            itemStyle: {
72
-                                emphasis: {
73
-                                    shadowBlur: 10,
74
-                                    shadowOffsetX: 0,
75
-                                    shadowColor: "rgba(0, 0, 0, 0.5)"
76
-                                }
77
-                            }
78
-                        }
79
-                    ]
80
-                });
81
-            },
82
-        }
83
-    }
84
-</script>
85
-
86
-<style scoped>
87
-
88
-</style>

+ 49
- 6
src/views/indexEcharts/components/NewUsers.vue Целия файл

@@ -1,22 +1,65 @@
1 1
 <template>
2
-  <div class="chart-box">
3
-    <h3>新增客户 <small>最近七天</small></h3>
4
-    <el-table :data="tableData"  border  center  style="width: 100%; margin-top: 16px">
5
-      <el-table-column v-for="(item, index) in tableTitle" :key="index" :label="item" :prop="index == 0 ? 'label': item"></el-table-column>
6
-    </el-table>
2
+  <div>
3
+    <div class="chart-box" v-if="mode == 'all' || mode == 'line'">
4
+      <h3>新增客户</h3>
5
+      <v-chart class="chart" :options="options" />
6
+    </div>
7
+    <div class="chart-box" v-if="mode == 'all' || mode == 'table'">
8
+      <h3>新增客户 <small>最近七天</small></h3>
9
+      <el-table :data="tableData"  border  center  style="width: 100%; margin-top: 16px">
10
+        <el-table-column v-for="(item, index) in tableTitle" :key="index" :label="item" :prop="index == 0 ? 'label': item"></el-table-column>
11
+      </el-table>
12
+    </div>
7 13
   </div>
8 14
 </template>
9 15
 
10 16
 <script>
17
+import ECharts from 'vue-echarts'
18
+import 'echarts/lib/chart/line'
19
+import 'echarts/lib/component/tooltip'
20
+
11 21
 export default {
12 22
   name: 'NewUsers',
13
-  props: ['value'],
23
+  props: ['value', 'mode'],
14 24
   data () {
15 25
     return {
16 26
       tableTitle: [ '类型' ],
27
+      lineOpt: {
28
+        color: ["purple", "green"],
29
+        tooltip: {
30
+          trigger: "axis"
31
+        },
32
+        legend: {
33
+          data: ["新用户数", "授权注册"]
34
+        },
35
+        toolbox: {},
36
+        xAxis: {
37
+          type: "category",
38
+        },
39
+        yAxis: {},
40
+        series: [
41
+          {
42
+            name: "新用户数",
43
+            type: "line",
44
+          },
45
+          {
46
+            name: "授权注册",
47
+            type: "line",
48
+          }
49
+        ]
50
+      },
17 51
     }
18 52
   },
19 53
   computed: {
54
+    options () {
55
+      return {
56
+        ...this.lineOpt,
57
+        dataset: {
58
+          dimensions: ['date', 'userCount', 'authorizationCount'],
59
+          source: this.value || []
60
+        }
61
+      }
62
+    },
20 63
     tableData () {
21 64
       return (this.value || []).reduce((acc, item, index) => {
22 65
           const { date, userCount, authorizationCount } = item

src/views/indexEcharts/components/UsrSRCLineAndPie.vue → src/views/indexEcharts/components/UserSource.vue Целия файл

@@ -1,26 +1,39 @@
1 1
 <template>
2
-  <div class="chart-box">
3
-    <h3>用户来源 <small>最近七天</small></h3>
4
-    <v-chart class="chart" :options="options" />
2
+  <div>
3
+    <div class="chart-box" v-if="mode == 'all' || mode == 'report'">
4
+      <h3>用户来源 <small>最近七天</small></h3>
5
+      <v-chart class="chart" :options="options" />
6
+    </div>
7
+    <div class="chart-box" v-if="mode == 'all' || mode == 'table'">
8
+      <el-select v-model="userType">
9
+        <el-option label="所有用户" value="all"></el-option>
10
+        <el-option label="注册用户" value="registered"></el-option>
11
+      </el-select>
12
+      <el-table :data="tableData"  border  center  style="width: 100%; margin-top: 16px">
13
+        <el-table-column v-for="(item, index) in tableTitle" :key="index" :label="item" :prop="index == 0 ? 'label' : item"></el-table-column>
14
+      </el-table>
15
+    </div>
5 16
   </div>
6 17
 </template>
7 18
 
8 19
 <script>
9 20
 import ECharts from 'vue-echarts'
10 21
 import 'echarts/lib/chart/bar'
22
+import 'echarts/lib/chart/pie'
11 23
 import 'echarts/lib/component/tooltip'
12 24
 
13 25
 export default {
14
-  name: 'UsrSRCLineAndPie',
26
+  name: 'UserSource',
15 27
   components: {
16 28
     'v-chart': ECharts,
17 29
   },
18 30
   props: [
19 31
     'value',
32
+    'mode',
20 33
   ],
21 34
   data () {
22 35
     return {
23
-      baseOpts: {
36
+      reportOpts: {
24 37
         legend: {},
25 38
         color: ['#286DD0', '#8565CE', '#6A96F8', '#F5749E', '#8B7FE2'],
26 39
         tooltip: {},
@@ -30,9 +43,24 @@ export default {
30 43
           { right: '5%' }
31 44
         ],
32 45
       },
46
+      userType: 'all',
47
+      tableTitle: ['类型'],
33 48
     }
34 49
   },
35 50
   computed: {
51
+    tableData () {
52
+      const data = (this.value || { data: [] }).data.reduce((acc, item, index) => {
53
+          const { date, fromName, count } = item
54
+          
55
+          this.tableTitle = this.tableTitle.indexOf(date) > -1 ? this.tableTitle : this.tableTitle.concat(date) // eslint-disable-line
56
+          acc[fromName] = { ...acc[fromName], [`${date}`]: !count ? 0 : count }
57
+
58
+          return acc
59
+        }, {})
60
+      
61
+      return Object.keys(data).map(x => ({ label:x, ...data[x] }))
62
+    },
63
+
36 64
     // 柱图
37 65
     barOptions () {
38 66
       const source = (this.value || {}).columnar || [];
@@ -82,7 +110,7 @@ export default {
82 110
     },
83 111
     options() {
84 112
       return {
85
-        ...this.baseOpts,
113
+        ...this.reportOpts,
86 114
         xAxis: [
87 115
           this.barOptions.xAxis,
88 116
           this.pieOptions.xAxis,

+ 4
- 4
src/views/indexEcharts/index.vue Целия файл

@@ -8,10 +8,10 @@
8 8
       <card label="总注册用户">{{echartsInfo.selectRegisteredCount}}</card>
9 9
     </el-col>
10 10
     <el-col :span="8">
11
-      <card label="最近7天新增" @click="toNewUsers()" class="under-line" >{{echartsInfo.selectRecentlyCount}}</card>
11
+      <card label="最近7天新增" @click.native="toNewUsers()" class="under-line" >{{echartsInfo.selectRecentlyCount}}</card>
12 12
     </el-col>
13 13
   </el-row>
14
-  <user-source :value="userSourceData"></user-source>
14
+  <user-source :value="userSourceData" mode="report"></user-source>
15 15
   <user-behavior class="marginTB" :value="userBehaviorData" @click="toBehaviorAnalysis()"></user-behavior>
16 16
  <el-row :gutter="20">
17 17
     <el-col :span="12">
@@ -27,7 +27,7 @@
27 27
       <user-city :value="userCityData"></user-city>
28 28
     </el-col>
29 29
   </el-row>
30
-  <new-users class="marginTB" :value="newUserData"></new-users>
30
+  <new-users class="marginTB" :value="newUserData" mode="table"></new-users>
31 31
   <intentional-customers  class="marginTB"></intentional-customers>
32 32
 </div>
33 33
 </template>
@@ -45,7 +45,7 @@ const {
45 45
 export default {
46 46
   components: {
47 47
     Card: () => import('./components/Card'),
48
-    UserSource: () => import('./components/UsrSRCLineAndPie'),
48
+    UserSource: () => import('./components/UserSource'),
49 49
     UserBehavior: () => import('./components/UserBehavior'),
50 50
     UserActive: () => import('./components/UserActive'),
51 51
     UserConversion: () => import('./components/UserConversion'),

+ 12
- 43
src/views/indexEcharts/newUsers.vue Целия файл

@@ -1,6 +1,7 @@
1 1
 <template>
2 2
 <div>
3
-  <p class="title"><span @click="choose(list.id)" :class="active==list.id?'active':''" v-for="(list,index) in dateList" :key="index" >{{list.date}}</span>  
3
+  <div class="title">
4
+    <span @click="choose(list.id)" :class="active==list.id?'active':''" v-for="(list,index) in dateList" :key="index" >{{list.date}}</span>  
4 5
     <el-date-picker
5 6
       v-model="value"
6 7
       type="daterange"
@@ -8,19 +9,17 @@
8 9
       end-placeholder="结束日期"
9 10
       @change="changeDate"
10 11
       default-value="2019-08-08">
11
-    </el-date-picker></p>
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>
15
-  </el-table>
12
+    </el-date-picker>
13
+  </div>
14
+  
15
+  <new-users :mode="all" :value="userData"></new-users>
16 16
 
17 17
 </div>
18 18
 </template>
19 19
 
20 20
 <script>
21
-import { createNamespacedHelpers } from "vuex";
22
-import apis from "../../config/api";
23
-import { mapState } from "vuex";
21
+import { createNamespacedHelpers } from "vuex"
22
+import { mapState } from "vuex"
24 23
 
25 24
 const {
26 25
   mapState: mapIndexEchartsState,
@@ -28,7 +27,7 @@ const {
28 27
 } = createNamespacedHelpers("indexEcharts");
29 28
 export default {
30 29
   components: {
31
-    XLine: () => import('@/components/charts/XLine.vue'),
30
+    NewUsers: () => import('./components/NewUsers'),
32 31
   },
33 32
   data() {
34 33
     return {
@@ -38,17 +37,7 @@ export default {
38 37
         {date:'最近一个月',id:2},
39 38
       ],
40 39
       active:1,
41
-      lineSeting: {
42
-        dataset: {
43
-          dimensions: ['date', 'userCount', 'authorizationCount'],
44
-          source: [],
45
-        },
46
-      },
47
-      tableData: [
48
-        { label: '新增用户', },
49
-        { label: '授权注册', }
50
-      ],
51
-      tableTitle: [ '类型' ],
40
+      userData: [],
52 41
     };
53 42
   },
54 43
   computed: {
@@ -62,38 +51,18 @@ export default {
62 51
       this.active = id;
63 52
     },
64 53
     changeDate(){
65
-      console.log(this.value,"value");
66 54
       if(this.value!=''){
67 55
         this.active = '3'
68 56
       }
69 57
     },
70 58
     initPage() {
71 59
       this.getNewsUserCount().then(x => {
72
-        const data = this.newsUserCount.selectNewsUserCount
73
-        this.lineSeting.dataset.source = data
74
-        this.tableData = (data || []).reduce((acc, item, index) => {
75
-          const { date, userCount, authorizationCount } = item
76
-
77
-          const row2 = {
78
-            ...acc[0],
79
-            [`${date}`]: userCount,
80
-          }
81
-
82
-          const row3 = {
83
-            ...acc[1],
84
-            [`${date}`]: authorizationCount,
85
-          }
86
-
87
-          this.tableTitle = this.tableTitle.concat(`${date}`)
88
-
89
-          return [row2, row3];          
90
-        }, this.tableData)
60
+        this.userData = this.newsUserCount.selectNewsUserCount
91 61
       });
92 62
     },
93 63
   },
94 64
   mounted() {
95
-    this.initPage();
96
-  
65
+    this.initPage();  
97 66
   }
98 67
 };
99 68
 </script>

+ 5
- 249
src/views/indexEcharts/userSource.vue Целия файл

@@ -9,67 +9,23 @@
9 9
       end-placeholder="结束日期"
10 10
       default-value="2019-08-08">
11 11
     </el-date-picker></p>
12
-  <el-row :gutter="20" :style="{ height: '560px',margin:'20px 0',border:'1px solid #eee',borderRadius:'5px'}">
13
-    <el-col :span="14">
14
-      <div class="grid-content" ref="firstChart"  id="firstChart"  :style="{ height: '500px' ,padding:'20px 10px'}" >
15
-      </div>
16
-    </el-col>
17
-    <el-col :span="10" :style="{ height: '560px',borderLeft:'1px solid #eee'}">
18
-      <div class="grid-content" ref="secondChart"  id="secondChart"  :style="{ height: '500px',padding:'20px 10px'}" >
19
-      </div>
20
-<!--        <pie-second-chart :style="{ height: '500px',padding:'20px 10px'}" ></pie-second-chart>-->
21
-    </el-col>
22
-  </el-row>
23
-  <el-select  :style="{ margin:'10px 0'}"  v-model="registeredType" @change="getInfo" placeholder="请选择">
24
-    <el-option
25
-      v-for="item in options"
26
-      :key="item.value"
27
-      :label="item.label"
28
-      :value="item.value">
29
-    </el-option>
30
-  </el-select>
31
-   <el-table :data="tableData2"  border  center  style="width: 100%">
32
-       <el-table-column   label="类型" prop="fromName" width="120" />
33
-       <template v-for="(item, index ) in header">
34
-           <el-table-column   :label="header[index]" :prop="header[index]" :key="index" width="110"/>
35
-       </template>
36
-
37
-
38
-  </el-table>
39
-
12
+    <user-source :value="userData" mode="all"></user-source>
40 13
 </div>
41 14
 </template>
42 15
 
43 16
 <script>
44 17
 import { createNamespacedHelpers } from "vuex";
45
-import PieSecondChart from '../../components/charts/PieSecondChart';
18
+
46 19
 const { mapActions: mapEchartsActions  } = createNamespacedHelpers("indexEcharts")
47
-import apis from "../../config/api";
48
-import { mapState } from "vuex";
49
-import Echarts from "echarts";
50 20
 
51 21
 export default {
52 22
   components: {
53
-      // eslint-disable-next-line vue/no-unused-components
54
-      'pie-second-chart' : PieSecondChart
23
+    UserSource: () => import('./components/UserSource'),
55 24
   },
56 25
   data() {
57 26
     return {
58 27
       value: '', // 时间
59
-      header: [], // 表头
60
-      tableData2: [], // 表格
61
-      fromNameType: [], // 类型名
62
-      options: [{
63
-          value: '',
64
-          label: '所有用户'
65
-        }, {
66
-          value: 'registered',
67
-          label: '注册用户'
68
-        }],
69
-        registeredType: '', // 类型  所有用户 或 注册用户 的值
70
-        pieSecondChart: '', // 饼状图实例
71
-        columnarSecondChart: '', // 柱状图
72
-
28
+      userData: {},
73 29
     };
74 30
   },
75 31
   computed: {},
@@ -80,153 +36,6 @@ export default {
80 36
      ...mapEchartsActions([
81 37
         'getUserResource'
82 38
      ]),
83
-    drawLine() {
84
-      // 基于准备好的dom,初始化echarts实例
85
-      this.columnarSecondChart = Echarts.init(this.$refs.firstChart);
86
-      // 饼图
87
-      this.pieSecondChart = Echarts.init(this.$refs.secondChart);
88
-    },
89
-    pie (obj) { // 饼状图绘制
90
-        // 绘制图表
91
-        this.pieSecondChart.setOption({
92
-            color: ["#7974ce","#f5749d","#3688f8"],
93
-            tooltip: {
94
-                trigger: "item",
95
-                formatter: "{a} <br/>{b} : {c} ({d}%)"
96
-            },
97
-            legend: {
98
-                orient: "vertical",
99
-                left: "left",
100
-                data: ["自主进入", "来源全民经纪人", "来源置业顾问"]
101
-            },
102
-            series: [
103
-                {
104
-                    name: "访问来源",
105
-                    type: "pie",
106
-                    radius: "55%",
107
-                    center: ["50%", "60%"],
108
-                    // label: {
109
-                    //     normal: {
110
-                    //         position: "inner"
111
-                    //     }
112
-                    // },
113
-                    data: [
114
-                        { value: obj.person_null, name: "自主进入" },
115
-                        { value: obj.person_estate_agent, name: "来源全民经纪人" },
116
-                        { value: obj.person_realty_consultant, name: "来源置业顾问" }
117
-                    ],
118
-                    itemStyle: {
119
-                        emphasis: {
120
-                            shadowBlur: 10,
121
-                            shadowOffsetX: 0,
122
-                            shadowColor: "rgba(0, 0, 0, 0.5)"
123
-                        }
124
-                    }
125
-                }
126
-            ]
127
-        });
128
-    },
129
-    columnar(obj) { // 柱状图
130
-         // 活动名称
131
-         const fromName = []
132
-
133
-         // 注册人数
134
-         const registered = []
135
-
136
-        // 注册人数
137
-        const userCount = []
138
-
139
-         obj.map((item, index) => {
140
-            fromName.push(item.fromName)
141
-            registered.push(item.registered)
142
-            userCount.push(item.userCount)
143
-         })
144
-
145
-        let labelOption = {
146
-            normal: {
147
-                show: true,
148
-                position: "top",
149
-                fontSize: 15,
150
-                rich: {
151
-                    name: {
152
-                        textBorderColor: "#fff"
153
-                    }
154
-                }
155
-            }
156
-        };
157
-        // 绘制图表
158
-        this.columnarSecondChart.setOption({
159
-            color: ["#3688f8", "#7974ce"],
160
-            backgroundColor: "#fff",
161
-            tooltip: {
162
-                trigger: "axis"
163
-            },
164
-            toolbox: {
165
-                show: false,
166
-                feature: {
167
-                    mark: { show: true },
168
-                    dataView: { show: true, readOnly: false },
169
-                    magicType: { show: true, type: ["bar"] },
170
-                    restore: { show: true },
171
-                    saveAsImage: { show: true }
172
-                }
173
-            },
174
-            calculable: true,
175
-            legend: {
176
-                data: ["所有用户", "注册用户"]
177
-            },
178
-            xAxis: [
179
-                {
180
-                    type: "category",
181
-                    axisLabel: {
182
-                        interval: 0,
183
-                        formatter: function(val) {
184
-                            // return val.split("").join("\n");
185
-                            return val;
186
-                        }
187
-                    },
188
-                    // data: ["生成海报", "好友分享", "群分享", "线下扫码", "名片分享", "小程序搜索"]
189
-                    data: fromName
190
-                }
191
-            ],
192
-            yAxis: [
193
-                {
194
-                    type: "value",
195
-                    name: "人数(人)",
196
-                    axisTick: {
197
-                        inside: true
198
-                    },
199
-                    axisLabel: {
200
-                        formatter: "{value}"
201
-                    }
202
-                }
203
-            ],
204
-            grid: {
205
-                left: "1%",
206
-                right: "1%",
207
-                containLabel: true,
208
-                y2: 10
209
-            },
210
-            series: [
211
-                {
212
-                    name: "所有用户",
213
-                    type: "bar",
214
-                    smooth: true,
215
-                    label: labelOption,
216
-                    // data: [78, 90, 13, 81, 170, 77]
217
-                    data: registered
218
-                },
219
-                {
220
-                    name: "注册用户",
221
-                    type: "bar",
222
-                    smooth: true,
223
-                    label: labelOption,
224
-                    // data: [26, 49, 62, 45, 21, 89]
225
-                    data: userCount
226
-                }
227
-            ]
228
-        });
229
-    },
230 39
     getInfo() { // 获取信息
231 40
 
232 41
          this.getUserResource({
@@ -234,67 +43,14 @@ export default {
234 43
              endDate: this.value[1],
235 44
              registeredType: this.registeredType
236 45
          }).then((res) => {
237
-            console.log(res)
238
-            this.setHeaderData(res)
239
-             this.pie(res.pie)
240
-             this.columnar(res.columnar)
46
+            this.userData = res
241 47
          }).catch((err) => {
242 48
              this.$notify.error(err.msg || err.message);
243 49
              console.log('indexEcharts/getUserResource err')
244 50
          })
245 51
     },
246
-    setHeaderData(obj) { // 设置表头
247
-        const header_data = new Set()
248
-        const from_name_type = new Set()
249
-
250
-        // 装载
251
-        const tab = []
252
-
253
-        // 请求的数据列表
254
-        const objData = obj.data
255
-        // 装载表头
256
-        objData.map((item, index) => {
257
-            // 时间表头
258
-            header_data.add(item.date)
259
-            from_name_type.add(item.fromCode)
260
-        })
261
-
262
-        this.header = Array.from(header_data).sort()
263
-        const fromNameType = Array.from(from_name_type)
264
-
265
-
266
-            fromNameType.map((type, index) => {
267
-                const dataObj = {}
268
-
269
-                // 获取类型和名称
270
-                objData.map((item, index) => {
271
-                    if (type === item.fromCode) {
272
-                        dataObj.fromName = item.fromName
273
-                        dataObj.fromCode = item.fromCode
274
-                        return
275
-                    }
276
-                })
277
-
278
-                // 装载时间
279
-                objData.map((item, index) => {
280
-                    if (type === item.fromCode) {
281
-                        let date = item.date
282
-                        dataObj[date] = item.count
283
-                    }
284
-                })
285
-
286
-                tab.push(dataObj)
287
-            })
288
-         this.tableData2 = tab
289
-
290
-
291
-
292
-
293
-
294
-    }
295 52
   },
296 53
   mounted() {
297
-    this.drawLine();
298 54
   }
299 55
 };
300 56
 </script>