mrechant.js
12.1 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// pages/tab/output/components/merchant/mrechant.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
import { setPrice } from '~/utils/format'
import { getNowMonth } from '~/utils/format'
const IMAGES = {
arrow: `${IMG_URL}/output/arrow.png`,
funnel: `${IMG_URL}/output/funnel.png`,
money: `${IMG_URL}/output/money.png`,
paper: `${IMG_URL}/output/paper.png`,
link: `${IMG_URL}/output/link.webp`,
empty: `${IMG_URL}/output/empty.png`,
funnelNew: `${IMG_URL}/output/funnelNew.webp`,
funnelNewSm: `${IMG_URL}/output/funnelNewSm.webp`,
totalIcon: `${IMG_URL}/output/totalIcon.webp`
}
Component({
options: {
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
noProduct: false,
IMAGES,
sceneIndx: 0,
startInd: 0,
isAct: false,
indicatorDots: true,
vertical: false,
autoplay: false,
interval: 2000,
duration: 500,
swiperHeight: 570,
// tabIndx: 4,
current: 0,
totalMoney: 0,
totalOrder: 0,
list: [],
nowList: [],
todayList: [],
monthList: [],
dataObj: {
todayTime: '',
monthTime: ''
},
list: [],
funnelList: {
start: [
{ label: '到店量', key: 'toShopCount' },
// { label: '核销数', key: 'couponUsedCount' },
{ label: '体验数', key: 'experienceCount' },
{ label: '成交量', key: 'upgradeCount' }
],
end: [
// { label: '转发量', key: 'shareCount' },
{ label: '访客数', key: 'visitCount' },
{ label: '成交数', key: 'dealCount' }
// { label: '产值', key: 'totalMoney' }
]
}
// showNothingSceneCon: false
},
lifetimes: {
attached() {
this.initTime()
this.init()
},
onPullDownRefresh() {
console.log('refresh')
// setTimeout(function () {
// uni.stopPullDownRefresh()
// }, 1000)
}
},
/**
* 组件的方法列表
*/
methods: {
init() {
let { userInfo } = wx.$storage.get()
this.setData({
userInfo: userInfo.subLoginUser
})
this.getTotalMerchantCount()
},
refreshList() {
console.log('refreshList')
let { dataObj, userInfo, list, current } = this.data
let merchantId = list[current]['merchantId']
let selectName = list[current]['selectName'] || '累计'
const itemList = ['本月', '本日', '累计']
let index = itemList.findIndex(item => {
return item == selectName
})
const keyName = {
0: 'monthTime',
1: 'todayTime',
2: 'defaultTime'
}
let params = {
partnerMerchantId: userInfo.merchantId, // userInfo.merchantId
merchantIdList: [merchantId],
...dataObj[keyName[index]]
}
console.log('params', params)
this.getMerchantById(params)
.then(result => {
console.log(result)
this.setData({
triggered: false
})
wx.$api.showToast({
title: '刷新成功',
icon: 'success'
})
that.setMerchantObj(current, result, itemList[res.tapIndex], item)
})
.catch(err => {})
},
pickSheet(e) {
let that = this
let { index, item } = e.currentTarget.dataset
let { dataObj, userInfo, list } = this.data
const itemList = ['本月', '本日', '累计']
wx.showActionSheet({
// '全部'
itemList,
// 先处理成全部默认去请求
success(res) {
// if (res.tapIndex!=2) {
// let parmas =
const keyName = {
0: 'monthTime',
1: 'todayTime',
2: 'defaultTime'
}
let key = keyName[res.tapIndex]
let merchantId = list[index]['merchantId']
let params = {
partnerMerchantId: userInfo.merchantId, // userInfo.merchantId
merchantIdList: [merchantId],
...dataObj[key]
}
that
.getMerchantById(params)
.then(result => {
console.log(result)
that.setMerchantObj(index, result, itemList[res.tapIndex], item)
})
.catch(err => {})
console.log(res.tapIndex)
},
fail(res) {
console.log(res.errMsg)
}
})
},
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
}
})
},
getTotalMerchantCount(type) {
// let { } = this.data
let { current, userInfo, dataObj } = this.data
// let { merchantId } = userInfo.subLoginUser
// console.log('merchantId', merchantId)
// console.log('test', userInfo.merchantId)
// debugger
// 默认返回2前两条的具体数据 剩下需要自己手动查询
// console.log(outputApi.partnerMerchantTotal)
// 44211548
try {
outputApi
.partnerMerchantTotal({ merchantId: userInfo.merchantId, ...dataObj.defaultTime })
.then(result => {
// debugger
console.log('result', result)
let { code, data } = result
// 没有关联园区店
if (code == -1) {
this.setData({
list: []
})
return wx.$api.showToast(result.message)
}
let { dataList, yqMerchantIds } = data
const list = yqMerchantIds.reduce((list, item, index) => {
let obj = {}
obj.totalMoney = setPrice(dataList[index]?.totalMoney || 0)
obj.totalOrder = dataList[index]?.totalOrder || 0
obj.merchantName = dataList[index]?.merchantName
obj.merchantId = item
let topObj = dataList[index]?.sceneList.shift()
dataList[index]?.sceneList.push(topObj)
const startInd =
dataList[index]?.sceneList.findIndex(item => {
return item != null
})
obj.startInd = typeof startInd === 'number'?startInd:-1
obj.showNothingSceneCon = item.startInd == -1
obj.showList = dataList[index]?.sceneList || []
// obj.norList = type?obj.
obj.norList = item.sceneList
list.push(obj)
return list
}, [])
// console.log('list', list)
// this.
// this
// totalMoney = list[current].totalMoney
// let sceneIndx = list[current].startInd
let swiperHeight
let index = list[current].startInd
// console.log(index)
// 动态计算swiper 高度
if ([3, -1].includes(index)) {
swiperHeight = 483
} else if ([0, 1].includes(index)) {
if (list[current]['showList'][index]['diagnoseList']) {
swiperHeight = 600
} else {
swiperHeight = 555
}
} else {
swiperHeight = 485
}
// console.log('swiperHeight', swiperHeight)
this.setData({
list,
yqMerchantIds,
totalMoney: list[current].totalMoney,
totalOrder: list[current].totalOrder,
sceneIndx: list[current].startInd,
swiperHeight
})
})
.catch(err => {
console.log(err)
})
} catch (error) {
console.log(error)
}
},
handleSceneChange(e) {
console.log(e)
let { list } = this.data
let { index, item } = e.currentTarget.dataset
let { sceneIdx } = e.detail
sceneIdx = sceneIdx - 1
let swiperHeight
// 动态计算swiper 高度
// 最后要判断 sceneIdx 为空也能切换的兼容问题
if (sceneIdx == 0 || item.startInd == -1 || item['showList'][sceneIdx] == null) {
swiperHeight = 483
} else if ([0, 1].includes(sceneIdx)) {
// console.log(item['diagnoseList'])
// item['showList'][index]['diagnoseList']
if (item['showList'][sceneIdx]?.diagnoseList) {
swiperHeight = 600
} else {
swiperHeight = 555
}
} else {
swiperHeight = 485
}
// let value = list[index][sceneIdx]
// console.log(list[index]['showList'][sceneIdx - 1])
// 没开通场景不给切换过去
// if (!list[index]['showList'][sceneIdx - 1]) return
list[index].startInd = sceneIdx
this.setData({
list,
startInd: sceneIdx + 1,
sceneIndx: sceneIdx,
swiperHeight
// sceneIndx: sceneIdx - 1
})
},
getMerchantById(params) {
// console.log(outPut)
return new Promise((resolve, reject) => {
// console.log(outPut)
outputApi
.getSignMerchant(params)
.then(result => {
resolve(result)
})
.catch(err => {
reject(err)
})
})
},
setMerchantObj(index, item, selectName, oldItem) {
item = item[0]
let obj = {}
obj.selectName = selectName || oldItem?.selectName
obj.totalMoney = setPrice(item?.totalMoney || 0)
obj.totalOrder = item?.totalOrder || 0
obj.merchantName = item?.merchantName
// obj.merchantId = item
let topObj = item?.sceneList.shift()
item?.sceneList.push(topObj)
const startInd =
dataList[index]?.sceneList.findIndex(item => {
return item != null
})
obj.startInd = typeof startInd === 'number' ?startInd:-1
obj.showNothingSceneCon = obj.startInd == -1
obj.showList = item?.sceneList || []
// obj.norList = type?obj.
// obj.norList = item.sceneList
let { list } = this.data
// item.list[index] = list[index]
// console.log('listObj', listObj)
let listObj = `list[${index}]`
this.setData({
[listObj]: Object.assign(list[index], obj)
})
},
swiperChange(e) {
console.log(e)
let { list, userInfo } = this.data
let { current } = e.detail
let swiperHeight
// 动态计算swiper 高度
if (list[current].startInd == 3 || list[current].startInd == -1) {
swiperHeight = 483
} else if ([0, 1].includes(list[current].startInd)) {
let subscript = list[current]['startInd']
let item = list[current]['showList']
if (item[subscript]?.diagnoseList) {
swiperHeight = 600
} else {
swiperHeight = 555
}
} else {
swiperHeight = 485
}
this.setData({
totalMoney: list[current].totalMoney || 0,
totalOrder: list[current].totalOrder || 0,
sceneIndx: list[current].startInd,
swiperHeight,
current
})
// list[current].startInd == 0? ''
// 692
// list
if (current >= 1 && list[current + 1] && list[current + 1].startInd == -1) {
// 请求
// partnerMerchantId
let merchantId = list[current + 1]['merchantId']
console.log(merchantId)
let params = {
partnerMerchantId: userInfo.merchantId,
merchantIdList: [merchantId]
}
// console.log()
console.log('params', params)
this.getMerchantById(params)
.then(result => {
console.log(result)
this.setMerchantObj(current + 1, result)
})
.catch(err => {
console.log(err)
})
}
// else {
// this.setData({
// totalMoney: list[current].totalMoney || 0,
// totalOrder: list[current].totalOrder || 0,
// sceneIndx: list[current].startInd
// })
// }
}
}
})