taskDetail.js
22.5 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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// packageActivity/pages/taskDetail/taskDetail.js
import index_const from '~/pages/tab/storeAssistant/pages/index/index_const'
import ActivityApi from '~/api/activityApi/index'
import { showEmoji } from '~/utils/emoji'
import { domain } from '~/utils/request/environment'
import { toUnicode } from '~/utils/format'
import {
shopmallApi
} from '~/api/api'
import USERAPI from '~/api/usersApi/index'
Page({
/**
* 页面的初始数据
*/
data: {
activityTypList: index_const.data.activityTypList,
detailInfo: {},
isloading: false,
materialTypeArr: [], // 素材类型
userStorage: {},
wechatShare: [],
jumpUrl: 'packageStoreAssistant/packageActivity/pages/customer/index',
showMidBtn: true,
showMask: false,
isSingleText: false,
currentMask: 1,
inType: 0,
tabType: 0
},
// 埋点模块
handlerTrackMod(tabType) {
tabType = tabType || 0
const OBJ = {
0: '售后众筹',
2: '定保招揽',
5: '续保招揽',
6: '节假日关怀',
1: '事故车救援',
3: '次新车转化',
}
this.toTrackClick(OBJ[Number(tabType)])
},
// 埋点
toTrackClick(operateMethod) {
let _para = {
operateModule: '工作台',
operateMethod,
operateTime: new Date().format('yyyy-MM-dd hh:mm:ss'),
}
ActivityApi.operationTrack(_para).then(res => {
})
},
onLoad(options) {
this.handlerOptions(options)
},
handlerOptions(options) {
wx.nextTick(() => {
if (!options) return wx.$api.showToast('缺少页面参数options')
if (options.inType == 2) {
this.noLoginToCheck(options.missionId)
wx.$storage.set('activity_options', options)
const query = {
id: options.id,
name: options.shareStaffName,
avatar: options.shareStaffImageUrl || '',
missionId: options.missionId
}
//跳转客户页面
wx.$router.reLaunch('/packageStoreAssistant/packageActivity/pages/customer/index', query)
} else if (options.inType == 1) {
// this.noLoginToCheck(options.missionId)
// 走注册流程
const sessionId = wx.$storage.get('sessionId')
if (!sessionId) {
let para = {
merchantId: options.merchantId,
type: 1,
missionId: options.missionId,
tabType: options.tabType
}
let temp = encodeURIComponent(JSON.stringify(para))
wx.navigateTo({
url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
});
} else {
const USERINFO = wx.$storage.get('userInfo')
if (USERINFO.merchantId == options.merchantId) {
USERAPI.checkSession().then(({
code
}) => {
if (code == '0') {
this.toGetPageData(options)
// 添加埋点
if(this.already)return
this.already = true
this.handlerTrackMod(options.tabType)
} else {
// wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/loading/loading?missionId='+options.missionId+'&expire=1')
wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/login/login', options)
}
})
} else {
let para = {
merchantId: options.merchantId,
type: 1,
missionId: options.missionId,
tabType: options.tabType
}
let temp = encodeURIComponent(JSON.stringify(para))
wx.navigateTo({
url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
});
}
}
}
})
},
toChineseStr(unicodeStr) {
if (unicodeStr == '') {
return 'Please input hexadecimal Unicode';
}
unicodeStr = unicodeStr.split('@');
let chineseStr = '';
for (let i = 0, iLength = unicodeStr.length; i < iLength; i++) {
chineseStr += String.fromCharCode(parseInt(unicodeStr[i], 16));
}
return chineseStr;
},
onRoute(options) {
if (!options) return wx.$api.showToast('缺少options参数')
if (options.inType == 1 || !options.missionId) {
this.handlerOptions(options || this.options)
return
}
this.toGetPageData(options)
if (options.isCard) {
this.handlerTrackMod(options.tabType)
}
// wx.nextTick(() => {
// let id = options.missionId || this.options.missionId
// this.getActiveTaskDetail(id)
// this.setData({
// userStorage,
// showMask: !showMask
// })
// })
},
toGetPageData(options) {
const userStorage = wx.$storage.get('userInfo')
const showMask = wx.$storage.get('closeMask')
let id = options.missionId || this.options.missionId
this.getActiveTaskDetail(id, options)
this.setData({
userStorage,
showMask: !showMask
})
},
toNext(e) {
const index = e.currentTarget.dataset.index
wx.$storage.set('closeMask', index == 4)
this.setData({
currentMask: index,
showMask: index != 4
})
},
toClick(e) {
const { index, item } = e.currentTarget.dataset
let { activityId, textType } = this.data.detailInfo
const userStorage = wx.$storage.get('userInfo')
if (!item.open) return
let temp = this.judgeType()
switch (index) {
case 1:
if (temp.isSingleText && textType != 1) {
this.finishTask(true, '文案已复制到剪切板,纯文案内容请前往朋友圈发送')
} else if (temp.isHaveLink) {
this.jumpZC(userStorage, activityId, '文案已复制到剪切板,纯文案内容请前往朋友圈发送')
} else {
this.finishTask(true, '文案已复制到剪切板,纯文案内容请前往朋友圈发送')
// this.setData({
// showpyqTip: true
// })
let { activityId, id } = this.data.detailInfo
const userStorage = wx.$storage.get('userInfo')
const query = {
id: activityId,
name: userStorage.name,
avatar: userStorage.sta_avatarUrl || userStorage.weChatAvatarUrl || '',
missionId: id,
showTip: 1,
merchantName: userStorage.merchantName,
merchantId: userStorage.merchantId,
shareStaffUuid: userStorage.uuid,
tabType: this.data.tabType
}
console.log(query);
if (textType == 1) {
wx.$router.go('/packageStoreAssistant/packageActivity/pages/customer_rw/index', query)
} else {
wx.$router.go('/packageStoreAssistant/packageActivity/pages/customer/index', query)
}
}
break;
case 2:
if (temp.isSingleText) {
this.finishTask(true, '文案已复制到剪切板。纯文案内容请直接通过微信发送给客户')
} else if (temp.isHaveLink) {
this.jumpZC(userStorage, activityId, '文案已复制到剪切板。纯文案内容请直接通过微信发送给客户')
} else {
this.finishTask(true, '文案已复制到剪切板。纯文案内容请直接通过微信发送给客户')
}
break;
default:
let toast = this.judgeType()
this.finishTask(true, toast.qftoast)
this.tracker()
break;
}
},
// 不需要登录查看任务详情
noLoginToCheck(missionId) {
ActivityApi.getTaskShareDetail({ missionId: Number(missionId) }).then(res => {
res.imgUrlList = []
let typeArr = []
res.platformMerchantMissionMaterialResponseList &&
res.platformMerchantMissionMaterialResponseList.forEach(val => {
typeArr.push(val.materialType)
// materialType 素材类型1文案 2图片 3视频 4专属链接
if (val.materialType == 1) {
// 文案
res.textContent = val.materialContent
res.filterTextContent = `<view>${showEmoji(val.materialContent)}</view>`
}
if (val.materialType == 2 || val.materialType == 3) {
// 图片视频
res.imgUrlList.push({
url: val.materialContent,
type: val.materialType == 2 ? 'image' : 'video',
firstFrameUrl: val.firstFrameUrl
})
}
if (val.materialType == 4) {
// 链接
// res.linkUrl = this.filterJumpUrl(res.activityId)
// 获取活动专属短链接
shopmallApi.getActivityDetail(res.activityId).then(e => {
res.posterImg = e.data.activityImg
this.setData({
detailInfo: res,
materialTypeArr: typeArr,
})
})
} else {
this.setShareInfo(res)
}
})
this.setData({
detailInfo: res,
materialTypeArr: typeArr,
showMidBtn: false,
inType: 1
})
})
},
// 跳转众筹活动页面
jumpZC(userStorage, activityId, toast) {
this.finishTask(true, toast)
let query = {
id: activityId,
exclusiveUuid: userStorage.uuid,
merchantId: userStorage.merchantId,
isExclusive: 1,
shareStaffUuid: userStorage.uuid,
form: 'task',
shareStaffType: 3
}
if (!this.data.tabType) {
wx.$router.go('/pages/crowdfunding/index/index', query)
} else {
query.notIntercept = true
wx.$router.go('/packageShopmall/packageExpandedGold/pages/activity/index/index', query)
}
},
toDescPage(e) {
const { index } = e.currentTarget.dataset
wx.$router.go('/packageStoreAssistant/packageActivity/pages/descprition/index', { index })
},
// 判断属于哪种素材结合类型
judgeType() {
// materialType (integer, optional): 素材类型 1.文本 2.图片 3.视频 4.链接
const { platformMerchantMissionMaterialResponseList } = this.data.detailInfo
let materialTypeList = []
let isSingleText = false
let isHaveLink = false
let qftoast = '文案已复制到剪切板。请使用群发助手分享活动信息'
if (platformMerchantMissionMaterialResponseList) {
platformMerchantMissionMaterialResponseList.forEach(el => {
materialTypeList.push(el.materialType)
})
}
let tempString = materialTypeList.toString()
let type1 = [1].toString() //纯文本
if (tempString == type1) {
isSingleText = true
} else if (materialTypeList.includes(4)) {//纯文本+链接
isHaveLink = true
qftoast = `文案已复制到剪切板。请使用群发助手分享活动信息`
} else {//纯文本++图片或视频
isHaveLink = false
qftoast = `文案已复制到剪切板,素材已经保存到相册。请使用群发助手分享活动信息`
}
if (isSingleText) {
this.setData({
isSingleText: true
})
}
return { isSingleText, isHaveLink, qftoast }
},
// 拼接活动专属链接
filterJumpUrl(id) {
const userStorage = wx.$storage.get('userInfo')
return `${domain}/scrm-wx-merchant-activity/#/?id=${id}&merchantId=${userStorage.merchantId}&shareStaffUuid=${userStorage.uuid}&shareStaffName=${toUnicode(userStorage.name)}&isExclusive=1&exclusiveUuid=${userStorage.uuid}&shareStaffType=2&sharedTime=${Date.now()}`
},
// 获取任务详情
getActiveTaskDetail(missionId, options) {
ActivityApi.getActiveTaskDetail({ missionId: Number(missionId) }).then(res => {
res.imgUrlList = []
// missonType 任务类型1注册 2分享 3浏览 4访客 5下单
// if (res.missonType != 2) { // 非分享任务 显示活动专属链接
// res.linkUrl = this.filterJumpUrl(res.activityId)
// }
let typeArr = []
let wechatShare = []
res.platformMerchantMissionMaterialResponseList &&
res.platformMerchantMissionMaterialResponseList.forEach(val => {
typeArr.push(val.materialType)
// materialType 素材类型1文案 2图片 3视频 4专属链接
if (val.materialType == 1) {
// 文案
res.textContent = val.materialContent
res.filterTextContent = `<view>${showEmoji(val.materialContent)}</view>`
}
if (val.materialType == 2 || val.materialType == 3) {
// 图片视频
res.imgUrlList.push({
url: val.materialContent,
type: val.materialType == 2 ? 'image' : 'video',
firstFrameUrl: val.firstFrameUrl
})
}
if (val.materialType == 4) {
// 链接
// res.linkUrl = this.filterJumpUrl(res.activityId)
// 获取活动专属短链接
if (options.tabType == 0) {
ActivityApi.getActivityUrl({ activityId: res.activityId }).then(e => {
res.linkUrl = e.activityUrl
res.posterImg = e.posterImg
this.setShareInfo(res)
this.setData({
detailInfo: res,
materialTypeArr: typeArr,
tabType: 0
})
})
} else {
shopmallApi.getActivityDetail(res.activityId).then(e => {
res.posterImg = e.data.activityBigImg
this.setShareInfo(res)
this.setData({
detailInfo: res,
materialTypeArr: typeArr,
tabType: 1
})
})
}
} else {
this.setShareInfo(res)
}
})
if (res && res.sharingMethod) {
let shareMethod = res.sharingMethod.split(',')
wechatShare = [
{
title: '微信群发',
icon: 'task_qf',
active: 'task_qf_active',
open: shareMethod.includes('1')
},
{
title: '分享朋友圈',
icon: 'task_pyq',
active: 'task_pyq_active',
open: shareMethod.includes('3')
},
{
title: '分享好友',
icon: 'task_hy',
active: 'task_hy_active',
open: shareMethod.includes('2')
},
]
}
console.log(options.tabType);
this.setData({
detailInfo: res,
materialTypeArr: typeArr,
wechatShare,
inType: 1,
tabType: Number(options.tabType)
}, () => {
this.judgeType()
})
// wx.$api.getViewInfo('.user-box', res => {
// if (res)
// this.setData({
// boxImageHeight: res.height
// })
// })
})
},
// 跳转链接
goShareLink(e) {
let { detailInfo } = this.data
// 跳转拼接的链接
let linkUrl = this.filterJumpUrl(detailInfo.activityId)
wx.$router.jumpH5(linkUrl)
},
// 预览图片/视频
previewMedia(e) {
let { imgUrlList } = this.data.detailInfo
let { current } = e.currentTarget.dataset
wx.previewMedia({
sources: imgUrlList,
current: current
})
},
toSave() {
let item = this.data.detailInfo
this.canCopyLink = true
Promise.all([this.copyText(item), this.saveWith(item)])
.then(() => {
wx.showToast({
title: this.data.isSingleText ? '内容已复制' : '图片及视频已保存到手机相册,文案已黏贴到剪切板。',
icon: 'none'
})
})
.catch(err => {
wx.showToast({
title: err,
icon: 'none'
})
})
},
finishTask(needToast, toast) {
let item = this.data.detailInfo
this.canCopyLink = false
// Promise.all([this.copyText(item), this.saveWith(item)])
Promise.all([this.copyText(item)])
.then(() => {
if (needToast) {
wx.showToast({
title: toast || '图片及视频已保存到手机相册,文案已黏贴到剪切板。',
icon: 'none'
})
}
})
.catch(err => {
wx.showToast({
title: err,
icon: 'none'
})
})
},
// 复制文案及专属链接
copyText(item) {
return new Promise((resolve, reject) => {
let { textContent, linkUrl } = item
let copyData = ''
if (textContent && linkUrl && this.canCopyLink) {
copyData = `${textContent}\n活动链接:${linkUrl}`
} else if (textContent && linkUrl) {
copyData = `${textContent}`
}
else if (!textContent && linkUrl) {
copyData = `活动链接:${linkUrl}`
} else if (textContent && !linkUrl) {
copyData = textContent
}
let _this = this
if (!copyData.length) {
// 复制内容为空 不做处理
return resolve()
}
wx.setClipboardData({
data: copyData,
success() {
if (!item.imgUrlList.length) return resolve()
resolve()
wx.showLoading({
title: '图片视频下载中',
icon: 'none',
mask: true
})
},
fail() {
reject('文案复制失败')
}
})
})
},
// 一键保存
saveWith(item) {
return new Promise((resolve, reject) => {
var _this = this
let thisPage = wx.$router.getPageInstance()
if (!item.imgUrlList.length) return resolve()
// 获取保存到相册权限
wx.getSetting({
success(res) {
if (res.authSetting['scope.writePhotosAlbum'] === false) {
wx.hideLoading();
thisPage.setData({
showAuth: true
})
} else {
_this
.queue(item.imgUrlList)
.then(() => {
resolve()
})
.catch(() => {
reject('图片下载失败')
})
}
}
})
})
},
queue(urls) {
let promise = Promise.resolve()
urls.forEach(item => {
promise = promise.then(() => {
return this.download(item.url, item.type)
})
})
return promise
},
// 下载
download(url, type) {
return new Promise((resolve, reject) => {
wx.downloadFile({
url: url,
success: function (res) {
var temp = res.tempFilePath
let fn = type == 'image' ? wx.saveImageToPhotosAlbum : wx.saveVideoToPhotosAlbum
fn({
filePath: temp,
success: function (res) {
resolve(res)
},
fail: function (err) {
reject(res)
}
})
},
fail: function (err) {
reject(err)
}
})
})
},
// 埋点
tracker() {
const USERINFO = wx.$storage.get('userInfo')
let data = {
action_type: 4, // 事件类型固定为4-分享
item_type: 3, // 商品类型,固定为3-众筹活动
merchant_id: USERINFO.merchantId, // 门店号
staff_uuid: USERINFO.uuid,
business_type: 1, // 业务类型,固定为1
add_way: 104, // 来源,固定为104
create_time: new Date().format('yyyy-MM-dd hh:mm:ss'), // 分享时间
item_id: this.data.detailInfo ? this.data.detailInfo.activityId : 0,
share_staff_type: 3
}
let jsonList = [JSON.stringify(data)]
ActivityApi.taskShareReport({ jsonList }).then(res => { })
},
setShareInfo(data) {
let name = '',
openId = '',
logo = '',
userPhone = '',
merchant = ''
const sharedTime = new Date().getTime()
const userInfo = wx.$storage.get('userInfo') || {},
params = {
shareStaffUuid: userInfo.uuid,
exclusiveUuid: userInfo.uuid,
merchantId: userInfo.merchantId,
isExclusive: 1,
},
{ activityId, posterImg, activityImage, activityName, imgUrlList, textType } = data
if (textType == 1) {
this.data.jumpUrl = 'packageStoreAssistant/packageActivity/pages/customer_rw/index'
}
if (userInfo) {
name = userInfo.name || ''
openId = userInfo.weChatOpenId || ''
logo = userInfo.sta_avatarUrl || userInfo.weChatAvatarUrl || ''
userPhone = userInfo.phone || ''
merchant = userInfo.merchantName || ''
}
let imagesurl = ''
if (imgUrlList && imgUrlList.length) {
imagesurl = imgUrlList[0].url
if (imgUrlList[0].type == 'video') {
imagesurl = imgUrlList[0].firstFrameUrl
}
}
let query = `id=${activityId}&shareStaffType=1&shareStaffName=${toUnicode(name)}&shareStaffImageUrl=${encodeURIComponent(logo)}&openId=${openId}&sharedTime=${sharedTime}&merchant=${toUnicode(merchant)}`
if (userPhone) query = `${query}&userPhone=${userPhone}`
if (params && params.shareStaffUuid) query = `${query}&shareStaffUuid=${params.shareStaffUuid}`
if (params && params.merchantId) query = `${query}&merchantId=${params.merchantId}`
if (params && params.isExclusive) query = `${query}&isExclusive=${params.isExclusive}`
if (params && params.exclusiveUuid) query = `${query}&exclusiveUuid=${params.exclusiveUuid}`
const title = `${name}邀请您参加${activityName}`
this.pyqTitle = title
this.shareAppMessage = {
title,
path: `/${this.route}?${query}`,
// imageUrl: imagesurl || posterImg || activityImage,
query
}
this.shareTemp = {
title,
path: `/${this.data.jumpUrl}?${query}`,
imageUrl: imagesurl || posterImg || activityImage,
query
}
},
onShareAppMessage(options) {
this.tracker()
let type = 2
let missionid = this.data.detailInfo.id
let url = ''
let tabType = this.data.tabType
console.log(tabType);
if (options.target) {
type = options.target.dataset.type
missionid = options.target.dataset.missionid
// tabType = options.target.dataset.tab
url = options.target.dataset.url
}
if (url || type == 2) {
this.shareTemp.path += '&shareChannel=1' + `&inType=2` + `&missionId=${missionid}` + `&tabType=${tabType}`
console.log('右上角转发好友', this.shareTemp)
return {
...this.shareTemp
}
}
this.shareAppMessage.path += '&shareChannel=1' + `&inType=1` + `&missionId=${missionid}` + `&tabType=${tabType}`
this.shareAppMessage.title = '点击查看活动任务'
console.log('右上角转发员工', this.shareAppMessage)
return {
...this.shareAppMessage
}
},
// onShareTimeline() {
// this.hideMask()
// this.tracker()
// let missionid = this.data.detailInfo.id
// this.shareAppMessage.query += '&shareChannel=2' + `&inType=2` + `&missionId=${missionid}` + '&task=1'
// this.shareAppMessage.title = this.pyqTitle
// console.log('右上角转发朋友圈', this.shareAppMessage)
// return {
// ...this.shareAppMessage
// }
// }
})