index.js
9.26 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
import {
showEmoji
} from '~/utils/emoji'
import ActivityApi from '~/api/activityApi/index'
import {
decimal,
toUnicode
} from '~/utils/format'
Page({
data: {
current: 0,
productList: [],
nextStep: 0,
},
onLoad(options) {
if (options && options.id) {
this.onRoute(options)
}
},
onRoute(options) {
if (this.isupdate) return
this.isupdate = true
this.setData({
staffAvator: options.avatar || (options.shareStaffImageUrl ? decodeURIComponent(options.shareStaffImageUrl) : ''),
staffName: options.name || (options.shareStaffName ? this.toChineseStr(options.shareStaffName) : ''),
merchantName: options.merchantName || (options.merchant ? this.toChineseStr(options.merchant) : ''),
nextStep: options.showTip && !(wx.$storage.get('closePYQTip')) ? 1 : 0,
options
// showToMiniTip:options.shareChannel&&wx.$storage.get('sessionId')
}, () => {
this.getTaskInfo(options.missionId)
})
},
toNext(e) {
const {
index
} = e.currentTarget.dataset
if (index == 2) {
wx.$storage.set('closePYQTip', true)
}
this.setData({
nextStep: index == 1 ? 2 : 0
})
},
jumpZC() {
let appEnter = wx.getEnterOptionsSync()
if (appEnter.scene === 1154) {
wx.$eventbus.emit('showTimeLineToast')
return
}
let query = {
id: this.data.options.id,
exclusiveUuid: this.data.options.shareStaffUuid,
merchantId: this.data.options.merchantId,
isExclusive: 1,
shareStaffUuid: this.data.options.shareStaffUuid,
form: 3
}
if (!this.data.options.tabType || this.data.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)
}
},
// 获取任务详情
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 = 1000
if(e.type == 'image'){
const img = await wx.getImageInfo({
src: e.url
})
height = img.height
}
if(e.type == 'video'){
try {
const video = await wx.getVideoInfo({
src: e.url
})
height = video?.height
} catch (error) {
height = 1000
}
}
e.height = height
if (index == 0) {
this.setData({
height
})
}
})
this.setData({
productList: materialList,
producktDots: (128 / materialList.length) + 'rpx',
taskText
})
}
this.setData({
textContent: res.textContent
})
this.setShareInfo(res)
})
},
onChange(e) {
const current = e.detail.current,
{
productList
} = this.data
this.setData({
current,
height: productList[current].height
})
},
previewMedia(e) {
wx.previewMedia({
sources: this.data.productList,
current: e.currentTarget.dataset.index
})
},
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();
},
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}&merchant=${toUnicode(this.data.merchantName)}`
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
}
this.activityName = activityName
console.log(this.shareAppMessage);
},
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.options ? this.data.options.id : 0,
share_staff_type: 3
}
let jsonList = [JSON.stringify(data)]
ActivityApi.taskShareReport({
jsonList
}).then(res => {})
},
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,
merchant
} = 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}`
if(merchant)query = `${query}&merchant=${merchant}`
const title = `${this.data.staffName}邀请您参加${this.activityName}`
this.shareAppMessage.title = title
this.shareAppMessage.path = `/${this.route}?${query}`
this.shareAppMessage.query = query
}
},
onShareAppMessage() {
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
}
}
})