index.js
14.7 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
// packageStoreAssistant/packageActivity/pages/customer/index.js
import {
shopmallApi
} from '~/api/api'
import ActivityApi from '~/api/activityApi/index'
import {
decimal,
toUnicode
} from '~/utils/format'
import { showEmoji } from '~/utils/emoji'
Page({
/**
* 页面的初始数据
*/
data: {
navBarHeight: 0,
newNavBarHeight: 0,
detail: {},
groupInfo: {},
navStyle: 'background-color: transparent;',
productList: [],
producktDots: 0,
endActivity: false,
days: '00', //天
hours: '00', //时
minutes: '00', //分
seconds: '00', //秒
milliseconds: '00',
taskText: '',
staffAvator: '',
staffName: '',
itemIndex: 0,
nextStep:0,
showToMiniTip:false
},
toBackMini(){
const sessionId = wx.$storage.get('sessionId')
if(!sessionId) return
wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/loading/loading')
},
getActivityDetail(id) {
wx.showLoading()
shopmallApi.getActivityDetail(id).then(res => {
// this.judgeIsPro(res)
if (this.noPro) {
return true
}
var data = res.data
if (res.code != 0) {
wx.hideLoading()
return true
}
wx.hideLoading()
this.setData({
title: data.activityName
})
// 处理活动结束时间
var today = new Date().getTime();
// var today_time = this.FormatDate(today);
// var endTime = data.endTime.slice(0,10)
var endTime = new Date(data.endTime).getTime()
if (today > endTime) {
this.setData({
endActivity: true
})
} else {
// 处理倒计时
this.countTime(data.endTime)
}
let flag = false
if(data&&data.goodsList&&data.goodsList.length){
data.goodsList = data.goodsList || []
let arr = []
data.goodsList.forEach(item=>{
arr.push(item.crowdFundingPrice)
})
arr.sort((a, b) => a - b)
data.retailPrice = arr[0]
flag = true
}
// 存储返回数据
this.setData({
detail: data,
isZC:flag
})
})
},
countTime(time) {
let days, hours, minutes, seconds, milliseconds;
let nowDate = time.replace(/(-)/g, '/');
// let that = this;
let now = new Date().getTime();
let end = new Date(nowDate).getTime(); //设置截止时间
let leftTime = parseInt((end - now) / 1000);; //时间差
if (leftTime >= 0) {
days = parseInt(leftTime / (24 * 60 * 60));
hours = parseInt((leftTime / (60 * 60)) % 24);
minutes = parseInt((leftTime / 60) % 60);
seconds = parseInt(leftTime % 60);
seconds = seconds < 10 ? "0" + seconds : seconds
minutes = minutes < 10 ? "0" + minutes : minutes
hours = hours < 10 ? "0" + hours : hours
days = days < 10 ? "0" + days : days
this.setData({
days,
hours,
minutes,
seconds
})
//递归每秒调用countTime方法,显示动态时间效果
this.inval = setTimeout(() => {
this.countTime(this.data.detail.endTime)
}, 1);
}
},
getActivityGroup(id) {
// if (!id) {
// this.dialog({
// message: '缺少活动ID',
// theme: 'round-button',
// confirmButtonText: '退出',
// confirmButtonColor: '#f13c3d',
// showCancelButton: false
// }).then(() => {
// wx.closeWindow()
// })
// return
// // }
// }
// this.id = id
shopmallApi.getActivityGroup(id).then(res => {
let {
data
} = res
const arr = []
let items = []
if (data) {
if (!data.fictitiousLadderQuantity) data.fictitiousLadderQuantity = 0
data.progress = data.fictitiousLadderQuantity != 0 ?
decimal((data.groupQuantity / data.fictitiousLadderQuantity) * 100, 2) :
decimal(data.groupQuantity * 100, 2)
data.groupList?.map(e => {
items.push(e)
if (items.length == 15) {
arr.push(items)
items = []
}
})
if (items.length) arr.push(items)
data.arr = arr
}
this.setData({
groupInfo: data || {}
})
if (data?.progress < 20) {
this.setData({
progress: data.progress,
count: decimal(data.progress, 2)
})
}
})
},
FormatDate(strTime) {
var date = new Date(strTime);
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
},
// 获取任务详情
getTaskInfo(missionId) {
ActivityApi.getTaskShareDetail({
missionId: missionId
}).then(res => {
if (!res) {
wx.showToast({
title: '获取任务详情失败',
icon: 'none'
})
return
}
// 处理轮播素材
let materialList = []
let taskText = ''
if (res.platformMerchantMissionMaterialResponseList.length) {
res.platformMerchantMissionMaterialResponseList.map(item => {
switch (item.materialType) {
case 1:
taskText = `<view>${showEmoji(item.materialContent)}</view>`
break;
case 2:
materialList.push({
type: 'image',
url: item.materialContent,
firstFrameUrl:item.firstFrameUrl
})
break;
case 3:
materialList.push({
type: 'video',
url: item.materialContent,
firstFrameUrl:item.firstFrameUrl
})
break;
default:
break
}
})
res.materialList = materialList
materialList.map(async (e, index) => {
let height = 638
if(e.type == 'image'){
const img = await wx.getImageInfo({
src: e.url
})
console.log(img);
// const proportion = img.width/img.height
const defaultW = 638
height = (defaultW*img.height)/img.width
console.log(height);
}
if(e.type == 'video'){
const video = await wx.getVideoInfo({
src: e.url
})
height = video.height
}
e.height = height
if (index == 0) {
this.setData({
height
})
}
})
this.setData({
productList: materialList,
producktDots: (128 / materialList.length)+ 'rpx',
taskText
})
}
this.setShareInfo(res)
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// this.getActivityDetail('10067')
// this.getActivityGroup('10068')
// this.getTaskInfo()
if (options && options.id) {
let optionFlag = wx.$storage.get('activity_options')
if (!optionFlag) {
wx.$storage.set('activity_options', options)
}
this.onRoute(options)
}
},
onRoute(options) {
console.log(options, 'options');
let optionFlag = wx.$storage.get('activity_options')
if (!optionFlag) {
wx.$storage.set('activity_options', options)
}
options = JSON.stringify(options) === '{}' ? optionFlag : options
this.getActivityDetail(options.id)
this.getActivityGroup(options.id)
this.getTaskInfo(options.missionId)
this.options = options
this.setData({
staffAvator: options.avatar || (options.shareStaffImageUrl ? decodeURIComponent(options.shareStaffImageUrl) : ''),
staffName: options.name || (options.shareStaffName ? this.toChineseStr(options.shareStaffName) : ''),
nextStep:options.showTip && !(wx.$storage.get('closePYQTip'))?1:0,
showToMiniTip:options.shareChannel&&wx.$storage.get('sessionId')
})
},
jumpZC() {
let appEnter = wx.getEnterOptionsSync()
if (appEnter.scene === 1154) {
wx.$eventbus.emit('showTimeLineToast')
return
}
let query = {
id: this.options.id,
exclusiveUuid: this.options.shareStaffUuid,
merchantId: this.options.merchantId,
isExclusive: 1,
shareStaffUuid: this.options.shareStaffUuid,
form: 3
}
if(!this.options.tabType || this.options.tabType==0){
wx.$router.go('/pages/crowdfunding/index/index', query)
}else{
query.notIntercept =true
wx.$router.go('/packageShopmall/packageExpandedGold/pages/activity/index/index', query)
}
},
navbarReady(e) {
this.setData({
navBarHeight: e.detail.height
})
},
onPageScroll(e) {
this.setData({
navStyle: e.scrollTop >= this.data.navBarHeight ? 'background-color: #fff;' : 'background-color: transparent;',
newNavBarHeight: e.scrollTop >= this.data.navBarHeight ? e.scrollTop : 0
})
},
// 监听swiper滑动
onChange(e) {
const {
productList
} = this.data
this.setData({
itemIndex: e.detail.current,
height: productList[e.detail.current].height
})
},
// 预览图片/视频
previewMedia(e) {
wx.previewMedia({
sources: this.data.productList,
current: e.currentTarget.dataset.index
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
clearInterval(this.inval)
// wx.$storage.rm('activity_options')
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
clearInterval(this.inval)
wx.$storage.rm('activity_options')
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
setShareInfo(data) {
let name = '',
openId = '',
logo = '',
userPhone = ''
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,
materialList
} = data
if (userInfo) {
name = userInfo.name || ''
openId = userInfo.weChatOpenId || ''
logo = userInfo.sta_avatarUrl || userInfo.weChatAvatarUrl || ''
userPhone = userInfo.phone || ''
}
let imagesurl = ''
if (materialList && materialList.length) {
imagesurl = materialList[0].url
if(materialList[0].type=='video'){
imagesurl = materialList[0].firstFrameUrl
}
}
let query = `id=${activityId}&shareStaffType=1&shareStaffName=${toUnicode(name)}&shareStaffImageUrl=${encodeURIComponent(logo)}&openId=${openId}&sharedTime=${sharedTime}`
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.shareAppMessage = {
title,
path: `/${this.route}?${query}`,
imageUrl: imagesurl || posterImg || activityImage,
query
}
},
toChineseStr(unicodeStr) {
console.log(unicodeStr, 'unicodeStr');
if (unicodeStr == '') {
return 'Please input hexadecimal Unicode';
}
if(unicodeStr.indexOf('@')==-1){
return unicodeStr
}
unicodeStr = unicodeStr.split('@');
console.log(unicodeStr, 'unicodeStr');
let chineseStr = '';
for (let i = 1, iLength = unicodeStr.length; i < iLength; i++) {
chineseStr += String.fromCharCode(parseInt(unicodeStr[i], 16));
}
return chineseStr.trim();
},
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.options?this.options.id:0,
share_staff_type: 3
}
let jsonList = [JSON.stringify(data)]
ActivityApi.taskShareReport({ jsonList }).then(res => { })
},
toNext(e){
const {index} = e.currentTarget.dataset
if(index==2){
wx.$storage.set('closePYQTip',true)
}
this.setData({
nextStep:index==1?2:0
})
},
judgeCustomer(){
const userInfo = wx.$util.getUserInfo()
const sharedTime = new Date().getTime()
const staff = wx.$storage.get('userInfo')
if(userInfo || (!staff&&!userInfo)){
const {shareStaffUuid,merchantId, exclusiveUuid,isExclusive,id,shareStaffName,shareStaffImageUrl,openId,userPhone} = this.options
let query = `id=${id}&shareStaffType=1&shareStaffName=${shareStaffName}&shareStaffImageUrl=${shareStaffImageUrl}&openId=${openId}&sharedTime=${sharedTime}`
if (userPhone) query = `${query}&userPhone=${userPhone}`
if (shareStaffUuid) query = `${query}&shareStaffUuid=${shareStaffUuid}`
if (merchantId) query = `${query}&merchantId=${merchantId}`
if (isExclusive) query = `${query}&isExclusive=${isExclusive}`
if (exclusiveUuid) query = `${query}&exclusiveUuid=${exclusiveUuid}`
const title = `${this.data.staffName}邀请您参加${this.data.detail.activityName}`
this.shareAppMessage.title = title
this.shareAppMessage.path = `/${this.route}?${query}`
this.shareAppMessage.query = query
}
},
/**
* 用户点击右上角分享
*/
/**
* 用户点击右上角分享
*/
onShareAppMessage(options) {
this.tracker()
this.judgeCustomer()
let {shareAppMessage} = this,
path = `${shareAppMessage.path}&shareChannel=1&inType=2&missionId=${this.options.missionId}&tabType=${this.options.tabType}`
console.log('右上角转发', path)
return {
title: shareAppMessage.title,
path,
imageUrl: shareAppMessage.imageUrl
}
},
/**
* 用户点击右上角分享朋友圈
*/
onShareTimeline() {
this.tracker()
this.judgeCustomer()
let {shareAppMessage} = this,
query = `${shareAppMessage.query}&shareChannel=2&missionId=${this.options.missionId}&tabType=${this.options.tabType}`
console.log('右上角转发朋友圈', query)
return {
title:shareAppMessage.title,
query,
imageUrl: shareAppMessage.imageUrl
}
}
})