index.js
8.02 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// pages/index/account/index.js
const App = getApp();
const customBehavior = require('../../../extends/custom.behavior.js');
import _ from 'underscore';
import cardConfig from '../../../utils/card'
Component({
behaviors: [customBehavior],
/**
* 组件的属性列表
*/
properties: {
timeType: String,
time: Object,
isMall:Boolean,
mallId: String,
orgName:String
},
/**
* 组件的初始数据
*/
data: {
picUrl:App.globalData.picUrl,
windowWidth: App.globalData.windowWidth,
navHeight: getApp().globalData.navHeight,
deploymentType: wx.getStorageSync('deploymentType'),
trendVal: '',
trendName: '',
rankVal: 'total_passenger',
rankData: {},
belongTo: 'NewMall',
params: {
orgType: 'mall',
dateType: 'day',
startDate: '',
endDate: '',
chartIds: ''
},
dateStr: '昨日',
trendData: {},
hbarData: {},
cardData: {},
isOnce:true,
cardsList:[],
showTab:true
/********************************************/
},
lifetimes: {
attached: function () {
this.data.isOnce = false
this.getCharts().then(res => {
this.data.cardsList = res.data.cards
this.data.isOnce = true
this.changeTimerFn({
...this.data.time,
dateType: this.data.timeType
});
})
}
},
/**
* 组件的方法列表
*/
methods: {
mallBtn(){
if(!this.data.isMall){
this.triggerEvent('showMall');
}
},
// 获取报表chartIds
getReportCharts: function (res) {
if (this.data.chartList.length == 0) return;
wx.showLoading({
title: '数据加载中',
mask: true
});
this.loadHeadData();
this.loadBarData();
this.loaRankData();
},
loadHeadData() {
let orgIds = this.data.mallId;
let chartIds = this.getCardIds();
this.getHeadReport({
chartIds,
orgIds
}).then(res => {
let cardData = [];
Object.keys(res.data).forEach(key => {
let item = res.data[key];
if (this.data.params.dateType == 'day') {
item.value = item.today;
item.ratio = item.yesterdayRatio;
} else if (this.data.params.dateType == 'month') {
item.value = item.month;
item.ratio = item.lastMonthDayRatio;
} else if (this.data.params.dateType == 'year') {
item.value = item.year;
item.ratio = item.lastYearRatio;
}
item.value = String(item.value && this.toThousands(item.value)).replace('分','');
item.rstatus = (item.ratio && item.ratio.includes('-')) ? 1 : 2;
item.name = this.getChartName(key);
item.key = key;
item.dateType = this.data.params.dateType
cardData.push(item)
});
let newData = []
this.data.cardsList.forEach(item=>{
cardData.forEach(card=>{
if(item.chartKey==card.key){
newData.push(card)
}
})
})
let name = '',title = ''
this.data.trendVal = ''
Object.keys(cardConfig).forEach(key=>{
newData.forEach(card=>{
if(key==card.key){
card.unit = cardConfig[key].unit;
card.hasTrend = cardConfig[key][card.dateType].level && cardConfig[key][card.dateType].level.length>0
if(!name && card.hasTrend){
name = key
title = card.name
}
}
})
})
this.data.showTab = true
this.setData({
trendVal: name,
trendName: title
}, () => {
this.loaTrendData();
})
this.setData({
cardData:newData
})
})
},
loaRankData() {
let orgIds = this.data.mallId;
let chartIds = this.getChartIds('mall_ranking');
this.getBodyReport({
chartIds,
sortType: 'desc',
sortKey:this.data.rankVal,
orgIds
}).then(res => {
let rankData = res.data.mall_ranking;
rankData.key = this.data.rankVal;
this.setData({
rankData
}, () => {
wx.hideLoading();
})
});
},
changeTrend(e) {
let {
name,title
} = e.detail;
this.setData({
trendVal: name,
trendName: title
}, () => {
this.loaTrendData();
})
},
changeRank(e) {
let {
name,title
} = e.detail;
this.setData({
rankVal: name
}, () => {
this.loaRankData();
})
},
loaTrendData() {
let orgIds = this.data.mallId;
let chartIds = this.getChartIds(this.data.trendVal);
this.getBodyReport({
chartIds,
orgIds,
timeLevel: this.data.params.dateType == 'day' ? 'HOUR' : 'DAY'
}).then(res => {
let trendData = res.data[this.data.trendVal];
if (trendData.series && trendData.series[0]) {
trendData.series[0].name = this.data.trendName;
}
this.setData({
trendData: trendData
}, () => {
wx.hideLoading();
})
});
},
loadBarData() {
let orgIds = this.data.mallId;
let chartKey = 'stay_time_statistics';
let chartIds = this.getChartIds(chartKey);
this.getBodyReport({
chartIds,
orgIds,
}).then(res => {
let hbarData = res.data[chartKey];
this.setData({
hbarData
}, () => {
wx.hideLoading();
})
});
},
changeAccountFn: function (value) {
// this.getReportCharts();
if(!this.data.isOnce) return
this.getCharts({mallId:value}).then(res=>{
this.data.cardsList = res.data.cards
this.getReportCharts();
})
},
changeTimerFn: async function (value) {
let {
startDate,
dateType,
endDate
} = value;
let reportType, dateStr;
if (dateType == 0) {
reportType = 'day';
dateStr = '昨日';
} else if (dateType === 1) {
reportType = 'month';
dateStr = '上月';
} else {
reportType = 'year';
dateStr = '去年';
}
this.setData({
dateStr,
'params.dateType': reportType,
'params.startDate': startDate,
'params.endDate': endDate
}, () => {
this.getReportCharts();
})
},
}
})