summary.js
10.9 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// packageOutput/pages/summary/summary.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
import { getNowMonth } from '~/utils/format'
Page({
/**
* 页面的初始数据
*/
data: {
IMGURL: IMG_URL,
sceneCodeList: ['SC001', 'SC002', 'SC003', 'SC004'],
merchantInfo: {},
sceneObj: {
scene1: null,
scene2: null,
scene3: null,
scene4: null
},
sceneActive: 4,
scenePriceList: [{
total: 0
}, {
total: 0
}, {
total: 0
}, {
total: 0
}],
// 活动内容
scrollLeft: 0,
activityActive: 0,
activityList: [],
sceneActivityObj: {
scene1: [],
scene2: [],
scene3: [],
scene4: []
},
// 产值
searchForm: {
scene2Idx: 0,
scene3Idx: 0,
scene4Idx: 0
},
baseData: {
timeList: ['全部', '本月', '本日'],
actStatusList: ['全部', '申请中', '活动中', '已结束']
}
},
// 场景切换
handleSceneChange(e) {
var idx = e.detail.sceneIdx
this.setData({
sceneActive: idx,
activityActive: 0
})
if (!this.data.sceneActivityObj['scene' + this.data.sceneActive].length) {
this.getSceneProStatus(this.data.sceneCodeList[this.data.sceneActive - 1])
return true
}
if ([2, 3].includes(this.data.sceneActive)) {
this.getCustomerDetail(false, false)
} else {
this.setCurActivity()
}
},
// 活动切换
handleActChange(e) {
var idx = e.currentTarget.dataset.idx
this.setData({
activityActive: idx
})
if ([2, 3].includes(this.data.sceneActive)) {
this.getCustomerDetail(false, false)
}
},
setCurActivity() {
this.setData({
activityList: JSON.parse(JSON.stringify(this.data.sceneActivityObj['scene' + (this.data.sceneActive)]))
})
// activityActive为0时,触发置顶(左)
if (this.data.activityActive == 0) {
this.setData({
scrollLeft: 0
})
}
},
// 搜索条件切换
handleSearch() {
wx.showActionSheet({
itemList: this.data.sceneActive != 4 ? this.data.baseData.timeList : this.data.baseData.actStatusList,
success: res => {
this.setData({
['searchForm.scene' + this.data.sceneActive + 'Idx']: res.tapIndex
})
this.data.sceneActive != 4 ? this.getCustomerDetail(false, false) : this.getActivityRevenue()
}
})
},
handleJump(e) {
// console.log(this.data.activityList[this.data.activityActive])
var params = {
merchantInfo: this.data.merchantInfo,
sceneActive: this.data.sceneActive
// sceneCodeList: this.data.sceneCodeList
}
wx.$router.go('packageOutput.openBusiness', params)
},
getSceneProStatus(sceneCode, isFirst = false) {
var params = {
serviceMerchantId: this.data.merchantInfo.pMerchantId,
merchant4sId: this.data.merchantInfo.merchantId,
sceneCode: sceneCode
}
outputApi.getSceneProStatus(params).then(res => {
this.setData({
['sceneActivityObj.scene1']: res[0].productList,
['sceneActivityObj.scene2']: res[1].productList,
['sceneActivityObj.scene3']: res[2].productList,
['sceneActivityObj.scene4']: res[3].productList
})
if (isFirst) {
this.getCustomerDetail(isFirst)
}
if ([2, 3].includes(+this.data.sceneActive)) {
this.getCustomerDetail()
} else if (this.data.sceneActive == 4) {
this.getActivityRevenue()
} else {
this.setCurActivity()
}
})
},
initTime() {
let date = new Date()
let today = date.getDate()
let month = getNowMonth()
const todayTime = {
startTime: `${month}-${today} 00:00:00`,
endTime: `${month}-${today} 23:59:59`
}
const monthTime = {
startTime: `${month}-01 00:00:00`,
endTime: `${month}-${today} 23:59:59`
}
const defaultTime = {
startTime: '',
endTime: `${month}-${today} 23:59:59`
}
this.setData({
dataObj: {
todayTime,
monthTime,
defaultTime
}
})
},
dealSearchTime() {
var params = {}
switch (this.data.searchForm['scene' + this.data.sceneActive + 'Idx']) {
// 本月
case 1:
params = this.data.dataObj.monthTime
break
// 本日
case 2:
params = this.data.dataObj.todayTime
break
}
return params
},
/** 1.1和1.2场景产品数据处理
* 调同一个接口,返回两个服务下面的全部产品的数据
*/
getCustomerDetail(isFirst = false, isChangeOtherTotal = true) {
var params = this.dealSearchTime()
outputApi.getCustomerDetail({ merchantId: this.data.merchantInfo.merchantId, ...params }).then(res => {
var actList = this.data.sceneActivityObj['scene' + (isFirst ? 2 : this.data.sceneActive)]
var actCodeList = actList.map(item => item.productCode)
var curTotal = 0
var otherTotal = 0
var otherScene = isFirst ? 2 : (this.data.sceneActive == 2 ? 3 : 2)
res.forEach(item => {
var idx = actCodeList.findIndex(i => i == item.productCode)
if (idx != -1) {
var orderTotal = item.orderTotal
if (item.orderTotal) {
item.orderTotal.calCustomerUnitPrice = Math.round(orderTotal.totalSubOrderOrderMoney / orderTotal.upgradeCount).toFixed(0)
item.orderTotal.calExperience = Math.round((orderTotal.experienceCount * 100) / orderTotal.toShopCount).toFixed(0)
item.orderTotal.calTransform = Math.round((orderTotal.upgradeCount * 100) / orderTotal.experienceCount).toFixed(0)
}
actList[idx] = {
...actList[idx],
orderTotal: item.orderTotal
}
curTotal = curTotal + (item.orderTotal?.totalSubOrderOrderMoney || 0)
} else {
otherTotal = otherTotal + (item.orderTotal?.totalSubOrderOrderMoney || 0)
}
})
if (!isFirst) {
this.setData({
['sceneActivityObj.scene' + this.data.sceneActive]: actList
})
}
// 总金额
this.setData({
['scenePriceList[' + (isFirst ? 1 : (this.data.sceneActive - 1)) + '].total']: curTotal.toFixed(2)
})
if (isChangeOtherTotal) {
this.setData({
['scenePriceList[' + (isFirst ? 2 : (otherScene - 1)) + '].total']: otherTotal.toFixed(2)
})
}
!isFirst && this.setCurActivity()
})
},
dealSearchStatus() {
var params = {}
switch (this.data.searchForm['scene' + this.data.sceneActive + 'Idx']) {
case 0:
params.activityStatuList = [1, 2, 3]
break
// 申请中
case 1:
params.activityStatuList = [1]
break
// 活动中
case 2:
params.activityStatuList = [2]
break
// 已结束
case 3:
params.activityStatuList = [3]
break
}
return params
},
/** 查询场景4的产值 */
getActivityRevenue(isFirst = false) {
wx.showLoading()
var params = this.dealSearchStatus()
outputApi.getActivityRevenue({ merchantId: this.data.merchantInfo.merchantId, ...params }).then(res => {
// console.log(res)
// console.log(this.data.sceneActivityObj, '++++++')
var actList = this.data.sceneActivityObj['scene' + (isFirst ? 4 : this.data.sceneActive)]
var total = 0
res.forEach(item => {
total = total + item.totalAmount
})
actList.forEach((item, idx) => {
var curItem = res.find(k => k.goodsCategoryCode == item.productCode)
if (curItem) {
curItem.totalNum = curItem.activityList.length
curItem.activityList.forEach(k => {
// 时间
k.time = k.startTime.slice(5).replace(/-/g, '/') + '~' + k.endTime.slice(5).replace(/-/g, '/')
let startTimeFormat = k.startTime.slice(0,10).replace(/-/g, '/') + ' 00:00:00'
let nowDateFormat = new Date().toLocaleDateString().replace(/-/g, '/') + ' 23:59:59'
// activityStatus 1:未开始 2:进行中 3:已结束
// 0-未开始;1-活动中;2-已结束
switch (k.activityStatus) {
case 1:
k.interDays = parseInt((new Date(startTimeFormat).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)) + 1
break
case 2:
let endTimeFormat = k.endTime.slice(0,10).replace(/-/g, '/') + ' 23:59:59'
k.interDays = parseInt((new Date().getTime() - new Date(startTimeFormat).getTime()) / (1000 * 60 * 60 * 24)) + 1
k.toEndDays = parseInt((new Date(endTimeFormat).getTime() - new Date(nowDateFormat).getTime()) / (1000 * 60 * 60 * 24)) + 1
break
case 3:
k.interDays = parseInt((new Date(nowDateFormat).getTime() - new Date(k.endTime.replace(/-/g, '/')).getTime()) / (1000 * 60 * 60 * 24)) + 1
break
}
k.suggestTxtList = []
k.suggestList = []
if (k.activityStatus == 2) {
if (k.visitCount < 200) {
k.suggestTxtList.push('距离活动结束剩余' + k.toEndDays + '天')
k.suggestList.push('低于200个独立访客,触达车主的数量太少,建议与4S店关键人沟通注册员工的转发执行情况')
}
if (k.shareRate < 0.4) {
k.suggestTxtList.push('分享员工占比低于40%')
k.suggestList.push('分享员工占比低于40%,建议与4S店关键人沟通下注册员工的转发执行情况')
}
if (k.conversionRate < 0.05) {
k.suggestTxtList.push('点击转化率低于5%')
k.suggestList.push('点击转化率低于5%,建议调整该产品的品类话术和营销内容')
}
k.suggestTxt = k.suggestTxtList.join(',') + '。'
}
})
actList[idx].outputData = curItem
} else {
actList[idx].outputData = []
}
})
if (!isFirst) {
this.setData({
['sceneActivityObj.scene' + this.data.sceneActive]: actList
})
}
this.setData({
['scenePriceList[3].total']: total.toFixed(2)
})
!isFirst && this.setCurActivity()
}).finally(() => {
wx.hideLoading()
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.initTime()
wx.$router.getData(obj => {
var scene = {}
Object.keys(this.data.sceneObj).forEach(item => {
scene[item] = obj[item]
})
this.setData({
merchantInfo: obj,
sceneObj: scene,
sceneCodeList: obj.sceneCodeList
})
this.getSceneProStatus(this.data.sceneCodeList[this.data.sceneActive - 1], true)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
wx.setNavigationBarTitle({
title: this.data.merchantInfo.merchantName,
})
}
})