1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
| <template>
| <div class="wrapper">
| <Affix :offset-top="100">
| <Card class="card fixed-bottom">
| <affixTime :closeShop="true" @selected="clickBreadcrumb" />
| </Card>
| </Affix>
|
| <Card class="card">
| <div>
| <h4>客户增长趋势 <Button style="margin-left:10px" @click="()=>{enableShowMemberCount = !enableShowMemberCount; initMemberChart()}" size="small">{{enableShowMemberCount ? '关闭' : '显示'}}用户总人数</Button></h4>
| <div id="orderChart"></div>
| </div>
| </Card>
|
| <Card class="card">
| <div>
| <h4>客户增长报表</h4>
| <Table class="mt_10" stripe :columns="columns" :data="data"></Table>
|
| </div>
| </Card>
|
| </div>
| </template>
| <script>
| import * as API_Member from "@/api/member";
| import { Chart } from "@antv/g2";
| import affixTime from "@/components/affix-time";
|
| export default {
| components: { affixTime },
| data() {
| return {
| columns: [ // 表头
| {
| key: "createDate",
| title: "日期",
| sortable: true,
| },
| {
| key: "memberCount",
| title: "当前会员",
| },
| {
| key: "newlyAdded",
| title: "新增会员",
| },
| {
| key: "activeQuantity",
| title: "活跃会员",
| },
| ],
| // 时间
| dateList: [
| {
| title: "今天",
| selected: false,
| value: "TODAY",
| },
| {
| title: "昨天",
| selected: false,
| value: "YESTERDAY",
| },
| {
| title: "过去7天",
| selected: true,
| value: "LAST_SEVEN",
| },
| {
| title: "过去30天",
| selected: false,
| value: "LAST_THIRTY",
| },
| ],
| year: "", // 当前年限
| orderChart: "", // 订单表格
| params: { // 请求参数
| searchType: "LAST_SEVEN",
| year: "",
| month: "",
| shopId: "",
| },
|
| data: [], // 数据
| enableShowMemberCount:false
| };
| },
| watch: {
| params: {
| handler(val) {
| this.init();
| },
| deep: true,
| immediate:true,
| },
| year(val) {
| this.params.year = new Date(val).getFullYear();
| },
| },
| methods: {
| // 订单图
| initMemberChart() {
| // 默认已经加载 legend-filter 交互
| /**
| * 将数据分成三组来进行展示
| */
|
| let count = [];
| let newly = [];
| let actives = [];
|
| this.data.forEach((item) => {
| if (this.enableShowMemberCount && (item.memberCount!="" || item.memberCount!=null)) {
| count.push({
| createDate: item.createDate,
| memberCount:item.memberCount,
| title: "当前会员数量",
| });
| }
| if (!this.enableShowMemberCount && (item.newlyAdded!="" || item.newlyAdded!=null)) {
| newly.push({
| createDate: item.createDate,
| memberCount: item.newlyAdded,
| title: "新增会员数量",
| });
| }
| if (!this.enableShowMemberCount && (item.activeQuantity!="" || item.activeQuantity!=null)) {
| actives.push({
| createDate: item.createDate,
| memberCount: item.activeQuantity,
| title: "当日活跃数量",
| });
| }
| });
|
| let data = [...count, ...newly, ...actives];
|
| this.orderChart.data(data);
| this.orderChart.scale({
| activeQuantity: {
| range: [0, 1],
| nice: true,
| },
| });
| this.orderChart.tooltip({
| showCrosshairs: true,
| shared: true,
| });
|
| this.orderChart
| .line()
| .position("createDate*memberCount")
| .color("title")
| .label("memberCount")
| .shape("smooth");
|
| this.orderChart
| .point()
| .position("createDate*memberCount")
| .color("title")
| .label("memberCount")
| .shape("circle")
| .style({
| stroke: "#fff",
| lineWidth: 1,
| });
| this.orderChart.area().position("createDate*memberCount").color("title").shape("smooth");
|
|
| this.orderChart.render();
| },
| // 条件查询
| clickBreadcrumb(item, index) {
| let callback = item;
|
| console.warn(callback);
| this.params = {...callback};
| },
| // 初始化数据
| init() {
| this.orderChart ? this.orderChart.clear() : ''
| API_Member.getMemberStatistics(this.params).then((res) => {
| if (res.result) {
| res.result.forEach((item) => {
| item.activeQuantity += "";
| });
| this.data = res.result;
|
| if (!this.orderChart) {
| this.orderChart = new Chart({
| container: "orderChart",
| autoFit: true,
| height: 500,
| padding: [70, 70, 70, 70],
| });
| }
| this.initMemberChart();
| }
| });
| },
| },
| mounted() {
| let data = new Date();
| this.year = data;
| },
| };
| </script>
| <style scoped lang="scss">
| .wrapper {
| padding-bottom: 200px;
| }
| .card {
| margin-bottom: 10px;
| }
| </style>
|
|