outputCrowdfund.js
8.85 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
// packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
import wxqrcode from '~/utils/lib/wxqrcode'
import { IMG_URL } from '~/utils/constantData'
import { deleteSecond } from '~/utils/format'
import outputApi from '~/api/outputApi/index'
const IMAGES = Object.freeze({
download: `${IMG_URL}/output/download.webp`
})
Component({
/**
* 组件的属性列表
*/
properties: {
orderObj: {
type: Object,
value: () => { },
observer(n) {
n && this.dealStaffList()
}
},
sceneCode: {
type: String,
value: 'SC004'
},
hasReport: {
type: Boolean,
value: true
}
},
options: {
styleIsolation: 'shared'
},
/**
* 组件的初始数据
*/
data: {
IMGURL: IMG_URL,
IMAGES,
isShowTip: true,
isShowPoster: false,
orderFormList: [
{
label: '总场次',
name: 'totalNum'
},
{
label: '总订单',
name: 'totalOrderCount'
},
{
label: '成交金额',
name: 'totalAmount',
prefix: '¥'
}
],
merchantFormList: [
{
label: '预计活动时间',
name: 'time',
className: 'medium-no-bold'
},
{
label: '实际活动时间',
name: 'realTime',
className: 'medium-no-bold'
},
{
label: '订单数',
name: 'orderCount',
SC003Name: 'totalOrderCount',
className: 'font-number'
},
{
label: '产值',
name: 'realAmount',
SC003Name: 'totalOutputValue',
className: 'red font-number',
prefix: '¥',
isNumber: true
},
{
label: '预估产值',
name: 'predictAmount',
className: 'font-number',
prefix: '¥',
isNumber: true,
isHide: false
}
],
tableHeadList: [
{
label: 'rankIdx',
width: '40rpx'
},
{
label: '业务员',
name: 'shareName'
},
{
label: '转发',
name: 'shareCount'
},
{
label: '浏览',
name: 'browseCount'
},
{
label: '成交',
name: 'dealCount',
width: '92rpx'
},
{
label: '产值',
name: 'totalAmount',
prefix: '¥'
}
]
},
lifetimes: {
attached() {
let { sceneCode, merchantFormList } = this.data
if (sceneCode == 'SC003') {
let idx = merchantFormList.findIndex(item => item.name == 'predictAmount')
this.setData({
[`merchantFormList[${idx}].isHide`]: true
})
}
}
},
/**
* 组件的方法列表
*/
methods: {
dealStaffList() {
let { sceneCode } = this.data
if (sceneCode != 'SC004') {
return true
}
var list = this.data.orderObj
list &&
list.activityList?.forEach(item => {
// 1-未开始;2-活动中;3-已结束
let sliceNum = item.activityStatus == 3 ? 3 : 10
item.showStaffList = item.staffList.length > sliceNum ? item.staffList.slice(0, sliceNum) : item.staffList
item.staffList = item.staffList.length > sliceNum ? item.staffList.slice(sliceNum) : []
})
this.setData({
orderObj: list
})
},
handleMore(e) {
var { idx } = e.currentTarget.dataset
var list = this.data.orderObj
var item = list.activityList[idx]
list.activityList[idx].showStaffList = list.activityList[idx].showStaffList.concat(item.staffList.length > 10 ? item.staffList.slice(0, 10) : item.staffList)
list.activityList[idx].staffList = item.staffList.length > 10 ? item.staffList.slice(10) : []
this.setData({
orderObj: list
})
},
handleCopy(e) {
var { idx } = e.currentTarget.dataset
var currentItem = this.data.orderObj.activityList[idx]
var qr = wxqrcode.createQrCodeImg(currentItem.activityUrl)
const base64src = function (base64data) {
return new Promise((resolve, reject) => {
const [a, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []
if (!format) reject(new Error('ERROR_BASE64SRC_PARSE'))
const filePath = `${wx.env.USER_DATA_PATH}/tmp_base64src.${format}`
const buffer = wx.base64ToArrayBuffer(bodyData)
wx.getFileSystemManager().writeFile({
filePath,
data: buffer,
encoding: 'binary',
success() {
resolve(filePath)
},
fail() {
reject(new Error('ERROR_BASE64SRC_WRITE'))
}
})
})
}
base64src(qr).then(res => {
wx.getImageInfo({
src: res,
success(obj) {
wx.showShareImageMenu({
path: obj.path
})
},
fail() { }
})
})
},
handleJumpH5(e) {
// const { item } = e.currentTarget.dataset
// wx.$router.jumpH5(item.activityUrl)
},
async download(e) {
const { item } = e.currentTarget.dataset
if (item.mockPoster) {
item.posterUrl = item.mockPoster
this.setData({
crowdPosterItem: item,
isShowTip: false
})
return
}
// posterObj = this.selectComponent('#crowdPoster'),
// { options } = wx.$router.getPageInstance()
// const { options } = wx.$router.getPageInstance()
// console.log(options)
// try {
// let flag = await posterObj.check(item)
// posterObj.setData({
// poster: flag,
// show: true
// })
// } catch (error) {
wx.$api.showLoading('加载中...')
outputApi
.getPosterUrl({
id: item.activityId
})
.then(res => {
item.posterUrl = res
this.setData({
crowdPosterItem: item,
isShowTip: false
})
})
.catch(() => {
wx.$api.showToast('下载海报失败')
})
// }
},
/**长按海报 */
async longtouch(e) {
console.log('长按海报', e)
let { activityId } = e.detail
const res = await outputApi.reportPosterTrack({
activityId
})
this.triggerEvent('posterTrack')
},
/**长按战报/喜报 */
async handlePosterTouch(e) { },
/**战报 */
handleReport(e) {
const { item, idx } = e.currentTarget.dataset
wx.$api.showLoading('战报生成中')
outputApi
.getNewReportUrl({ activityId: item.activityId })
.then(res => {
// console.log(res)
if (!res.url) {
wx.$api.showToast('战报生成失败')
return true
}
var posterItem = {
...item,
posterUrl: res.url,
updatedTime: deleteSecond(res.updatedDate),
type: 'warReport'
}
this.setData({
crowdPosterItem: posterItem,
isShowTip: false
})
wx.$api.hideLoading()
this.triggerEvent('handleZhanReport', { item: item, idx: idx, posterItem: posterItem })
})
.catch(() => {
wx.$api.showToast('下载战报失败')
})
.finally(() => {
wx.$api.hideLoading()
})
},
/**喜报 */
handleXiReport(e) {
const { item } = e.currentTarget.dataset
wx.$api.showLoading('喜报生成中')
outputApi
.getNewGoodUrl({ activityId: item.activityId })
.then(res => {
if (!res.goodUrl) {
wx.$api.showToast('暂无喜报')
return true
}
var posterItem = {
...item,
posterUrl: res.goodUrl,
updatedTime: res.goodReportDate ? deleteSecond(res.goodReportDate) : '',
type: 'warReport'
}
this.setData({
crowdPosterItem: posterItem
})
wx.$api.hideLoading()
})
.catch(() => {
wx.$api.showToast('下载喜报失败')
})
.finally(() => {
// wx.$api.hideLoading()
})
// var posterItem = {
// ...item,
// posterUrl: item.goodUrl,
// // date: item.goodReportDate,
// updatedTime: deleteSecond(item.goodReportDate),
// type: 'warReport'
// }
// this.setData({
// // posterItem: posterItem,
// // isShowPoster: true,
// crowdPosterItem: posterItem,
// isShowTip: false
// })
},
// 活动详情-跳转门店助手
toActivity(e) {
const { item } = e.currentTarget.dataset
wx.navigateToMiniProgram({
appId: 'wxe10067a63c1856ac',
path: 'packageShopmall/packageExpandedGold/pages/activity/index/index?id=' + item.activityId + '&noOperate=true',
envVersion: 'trial',
success(res) {
// 打开成功
}
})
}
}
})