Browse Source

用户分析

cr 3 years ago
parent
commit
370379d9b1

+ 6 - 0
src/pages.json

@@ -595,6 +595,12 @@
595 595
             "style": {
596 596
                 "navigationBarTitleText": "修改店铺tab"
597 597
             }
598
+        },
599
+        {
600
+            "path": "pages/manage/statistics/user-data",
601
+            "style": {
602
+                "navigationBarTitleText": "用户分析"
603
+            }
598 604
         }
599 605
     ]
600 606
 }

+ 1 - 2
src/pages/manage/index.vue

@@ -92,7 +92,7 @@
92 92
 
93 93
         <!-- <button class="btn" @click="layout">退出登录</button> -->
94 94
 
95
-        <div class="ver">0.5.6</div>
95
+        <div class="ver">0.5.61</div>
96 96
         <wyg-bottom-tab
97 97
             ref="tabbar"
98 98
             :tabIndex="2"
@@ -237,7 +237,6 @@ export default {
237 237
             this.$store.commit("user/update", {
238 238
                 menuList: arr,
239 239
             });
240
-            console.log(arr, "menu");
241 240
             let arr2 = [];
242 241
             for (let item of arr) {
243 242
                 if (item.id !== "mobile_setting") {

+ 7 - 0
src/pages/manage/statistics/nav.vue

@@ -8,6 +8,13 @@
8 8
                     src="/static/common/arrows_left.png"
9 9
                 ></my-image>
10 10
             </li>
11
+            <li class="item" @click="jump('/pages/manage/statistics/user-data')">
12
+                <div class="name">用户分析</div>
13
+                <my-image
14
+                    class="arrow"
15
+                    src="/static/common/arrows_left.png"
16
+                ></my-image>
17
+            </li>
11 18
             <!-- <li class="item" @click="jump('/pages/manage/statistics/product')">
12 19
                 <div class="name">商品分析</div>
13 20
                 <my-image

+ 399 - 0
src/pages/manage/statistics/user-data.vue

@@ -0,0 +1,399 @@
1
+<template>
2
+    <div class="page">
3
+        <div class="filter">
4
+            <!-- <div >时间选择</div> -->
5
+            <ul class="date-list">
6
+                <li
7
+                    v-for="(item, index) of filterDateList"
8
+                    :key="index"
9
+                    @click="dateClick(item)"
10
+                    :class="{ on: activeDate.name === item.name }"
11
+                >
12
+                    {{ item.name }}
13
+                </li>
14
+            </ul>
15
+            <div class="filter-item">
16
+                <div class="name">排序:</div>
17
+                <div class="sort-main">
18
+                    <div class="box">
19
+                        <picker
20
+                            class="view"
21
+                            mode="selector"
22
+                            :range="sortByList"
23
+                            :range-key="'label'"
24
+                            @change="pickerChange($event, 'sortBy')"
25
+                        >
26
+                            <span class="view">{{ activeSortBy }}</span>
27
+                        </picker>
28
+                    </div>
29
+                    <div class="box">
30
+                        <picker
31
+                            class="view"
32
+                            mode="selector"
33
+                            :range="ascList"
34
+                            :range-key="'label'"
35
+                            @change="pickerChange($event, 'asc')"
36
+                        >
37
+                            <span class="view">{{ activeAsc }}</span>
38
+                        </picker>
39
+                    </div>
40
+                </div>
41
+            </div>
42
+        </div>
43
+        <!-- data-list -->
44
+        <div class="data-list">
45
+            <ul class="list">
46
+                <li class="item" v-for="item of dataList" :key="item.id">
47
+                    <div class="head-icon">
48
+                        <my-image :src="item.headIcon"></my-image>
49
+                    </div>
50
+                    <div class="info">
51
+                        <div class="name">{{ item.nickName }}</div>
52
+                        <div class="des">
53
+                            <section class="des-item">
54
+                                <span class="key">购买数量:</span
55
+                                >{{ item.buyCount }}
56
+                            </section>
57
+                            <section class="des-item">
58
+                                <span class="key">购买金额:</span
59
+                                >{{ item.buyAmount / 100 }}
60
+                            </section>
61
+                        </div>
62
+                        <div class="des">
63
+                            <section class="des-item">
64
+                                <span class="key">积分:</span>{{ item.points }}
65
+                            </section>
66
+                            <section class="des-item">
67
+                                <span class="key">访问次数:</span
68
+                                >{{ item.visitCount }}
69
+                            </section>
70
+                        </div>
71
+                        <div class="des time">
72
+                            最后登录时间:{{ item.lastLoginTime }}
73
+                        </div>
74
+                    </div>
75
+                </li>
76
+            </ul>
77
+            <div class="empty-text" v-if="dataLoading || dataEnd">
78
+                {{ dataLoading ? "加载中..." : "无更多数据" }}
79
+            </div>
80
+        </div>
81
+    </div>
82
+</template>
83
+
84
+<script>
85
+import MyImage from "../../../components/image/index";
86
+
87
+export default {
88
+    name: "",
89
+    components: { MyImage },
90
+
91
+    // 数据
92
+    data() {
93
+        return {
94
+            storeId: "",
95
+            filterDateList: [], // 快捷日期 [{name,startTime,endTime}]
96
+            activeDate: {},
97
+            dataList: [], // 数据列表
98
+            sortByList: [
99
+                { label: "购买次数", value: 0 },
100
+                { label: "最后登录时间", value: 1 },
101
+                { label: "访问次数", value: 2 },
102
+                { label: "购买金额", value: 3 },
103
+                { label: "积分数", value: 4 },
104
+            ],
105
+            ascList: [
106
+                { label: "降序", value: 0 },
107
+                { label: "升序", value: 1 },
108
+            ],
109
+            activeSortBy: "购买次数",
110
+            activeAsc: "降序",
111
+            pageIndex: 1,
112
+            dataEnd: false,
113
+            dataLoading: true,
114
+        };
115
+    },
116
+
117
+    onLoad() {
118
+        if (this.user.storeId) {
119
+            this.storeId = this.user.storeId;
120
+        }
121
+        this.initFilterDateList();
122
+        this.getDataList();
123
+    },
124
+    onReachBottom() {
125
+        this.getListMore();
126
+    },
127
+    async onShow() {},
128
+    // 函数
129
+    methods: {
130
+        // 生成日期过滤
131
+        initFilterDateList() {
132
+            let arr = [];
133
+            // 今天
134
+            let date = new Date();
135
+            let year = date.getFullYear();
136
+            let month =
137
+                date.getMonth() + 1 > 9
138
+                    ? "" + (date.getMonth() + 1)
139
+                    : "0" + (date.getMonth() + 1);
140
+            let day =
141
+                date.getDate() > 9 ? "" + date.getDate() : "0" + date.getDate();
142
+            arr.push({
143
+                name: "今天",
144
+                startTime: `${year}-${month}-${day} 00:00:00`,
145
+                endTime: `${year}-${month}-${day} 23:59:59`,
146
+            });
147
+            let date2 = new Date(date);
148
+            date2.setDate(date.getDate() - 1);
149
+            arr.push({
150
+                name: "昨天",
151
+                startTime: `${date2.getFullYear()}-${
152
+                    date2.getMonth() + 1
153
+                }-${date2.getDate()} 00:00:00`,
154
+                endTime: `${year}-${month}-${day - 1} 23:59:59`,
155
+            });
156
+            let date3 = new Date(date);
157
+            date3.setDate(date.getDate() - 7);
158
+            arr.push({
159
+                name: "近7天",
160
+                startTime: `${date3.getFullYear()}-${
161
+                    date3.getMonth() + 1
162
+                }-${date3.getDate()} 00:00:00`,
163
+                endTime: `${year}-${month}-${day} 23:59:59`,
164
+            });
165
+            let date4 = new Date(date);
166
+            date4.setDate(date.getDate() - 30);
167
+            arr.push({
168
+                name: "近30天",
169
+                startTime: `${date4.getFullYear()}-${
170
+                    date4.getMonth() + 1
171
+                }-${date4.getDate()} 00:00:00`,
172
+                endTime: `${year}-${month}-${day} 23:59:59`,
173
+            });
174
+            arr.push({
175
+                name: "全部",
176
+                startTime: null,
177
+                endTime: null,
178
+            });
179
+            this.filterDateList = arr;
180
+            this.activeDate = arr[3];
181
+        },
182
+
183
+        dateClick(val) {
184
+            this.activeDate = val;
185
+            this.getDataList();
186
+        },
187
+
188
+        pickerChange(e, name) {
189
+            let index = e.detail.value;
190
+            if (name === "sortBy") {
191
+                this.activeSortBy = this.sortByList[index].label;
192
+            }
193
+            if (name === "asc") {
194
+                this.activeAsc = this.ascList[index].label;
195
+            }
196
+            this.getDataList();
197
+        },
198
+
199
+        // 获取订单交易数据
200
+        getDataList() {
201
+            uni.showLoading({
202
+                title: "加载中...",
203
+            });
204
+            this.pageIndex = 1;
205
+            this.dataEnd = false;
206
+            let sendData = {
207
+                pageIndex: this.pageIndex++,
208
+                // sortBy:'',
209
+                // asc:'',
210
+            };
211
+            if (this.activeDate.startTime) {
212
+                sendData.startTime = this.activeDate.startTime;
213
+                sendData.endTime = this.activeDate.endTime;
214
+            }
215
+            for (let item of this.sortByList) {
216
+                if (item.label === this.activeSortBy) {
217
+                    sendData.sortBy = item.value;
218
+                }
219
+            }
220
+            for (let item of this.ascList) {
221
+                if (item.label === this.activeAsc) {
222
+                    sendData.asc = item.value;
223
+                }
224
+            }
225
+            this.api.get("/Data/GetUserDataList", sendData).then((res) => {
226
+                uni.hideLoading();
227
+                this.dataList = res.data.data;
228
+            });
229
+        },
230
+
231
+        getListMore() {
232
+            if (this.dataEnd) {
233
+                return;
234
+            }
235
+            let sendData = {
236
+                pageIndex: this.pageIndex++,
237
+                // sortBy:'',
238
+                // asc:'',
239
+            };
240
+            if (this.activeDate.startTime) {
241
+                sendData.startTime = this.activeDate.startTime;
242
+                sendData.endTime = this.activeDate.endTime;
243
+            }
244
+            for (let item of this.sortByList) {
245
+                if (item.label === this.activeSortBy) {
246
+                    sendData.sortBy = item.value;
247
+                }
248
+            }
249
+            for (let item of this.ascList) {
250
+                if (item.label === this.activeAsc) {
251
+                    sendData.asc = item.value;
252
+                }
253
+            }
254
+            this.dataLoading = true;
255
+            this.api.get("/Data/GetUserDataList", sendData).then((res) => {
256
+                this.dataLoading = false;
257
+                uni.hideLoading();
258
+                if (res.data.data.length < 20) {
259
+                    this.dataEnd = true;
260
+                }
261
+                this.dataList = [...this.dataList, ...res.data.data];
262
+            });
263
+        },
264
+    },
265
+
266
+    // 数据计算
267
+    computed: {
268
+        user() {
269
+            return this.$store.state.user.user;
270
+        },
271
+    },
272
+
273
+    // 数据监听
274
+    watch: {},
275
+};
276
+</script>
277
+
278
+<style lang="scss" scoped>
279
+.page {
280
+    padding-bottom: px(50);
281
+}
282
+.data-list {
283
+    margin-top: px(30);
284
+    background-color: #fff;
285
+}
286
+.filter {
287
+    padding: px(30);
288
+    background-color: #fff;
289
+    .date-list {
290
+        display: flex;
291
+        justify-content: space-between;
292
+        font-size: px(44);
293
+        text-align: center;
294
+        li {
295
+            border: 1px solid #f1f1f1;
296
+            padding: px(20) 0;
297
+            width: 20%;
298
+            flex-shrink: 0;
299
+            &.on {
300
+                border-color: rgb(0, 188, 38);
301
+                color: rgb(0, 188, 38);
302
+            }
303
+        }
304
+    }
305
+    .filter-item {
306
+        padding: px(20) 0;
307
+        display: flex;
308
+        justify-content: space-between;
309
+        align-items: center;
310
+        .name {
311
+            width: px(150);
312
+            flex-shrink: 0;
313
+            font-size: px(44);
314
+            margin-right: px(20);
315
+        }
316
+        .sort-main {
317
+            width: 100%;
318
+            display: flex;
319
+            justify-content: space-between;
320
+            align-items: center;
321
+        }
322
+        .box {
323
+            width: 49%;
324
+            height: px(100);
325
+            border: 1px solid #f1f1f1;
326
+            padding: 0 px(20);
327
+            font-size: px(44);
328
+            display: flex;
329
+            align-items: center;
330
+            position: relative;
331
+            &::after {
332
+                content: "";
333
+                position: absolute;
334
+                right: px(30);
335
+                top: 50%;
336
+                z-index: 1;
337
+                width: 0;
338
+                height: 0;
339
+                border-style: solid;
340
+                border-width: 5px 5px 0 5px;
341
+                border-color: #666 transparent transparent transparent;
342
+            }
343
+            .view {
344
+                width: 100%;
345
+                height: 100%;
346
+                line-height: px(100);
347
+                display: block;
348
+            }
349
+        }
350
+    }
351
+}
352
+.data-list {
353
+    padding: px(40) 0;
354
+    background-color: #fff;
355
+    .item {
356
+        border-bottom: 1px solid #f1f1f1;
357
+        display: flex;
358
+        align-items: stretch;
359
+        justify-content: space-between;
360
+        padding: px(30) px(40);
361
+    }
362
+    .head-icon {
363
+        width: px(230);
364
+        height: px(230);
365
+        flex-shrink: 0;
366
+        margin-right: px(30);
367
+        /deep/ img {
368
+            width: px(230);
369
+            height: px(230);
370
+        }
371
+    }
372
+    .info {
373
+        width: 100%;
374
+    }
375
+    .name {
376
+        font-size: px(44);
377
+    }
378
+    .des {
379
+        font-size: px(42);
380
+        margin-top: px(10);
381
+        display: flex;
382
+        justify-content: space-between;
383
+        align-items: center;
384
+        .des-item {
385
+            width: 45%;
386
+        }
387
+    }
388
+    .key,
389
+    .time {
390
+        color: #999;
391
+    }
392
+}
393
+.empty-text {
394
+    text-align: center;
395
+    padding: px(30);
396
+    font-size: px(44);
397
+    color: #999;
398
+}
399
+</style>