shareMixin.js
9.21 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
import { wxConfig, bigdatautilApi } from '@/api'
export default {
data () {
return {
entry: 'normal'
}
},
mounted () {
if (this.$route.meta.isTab || this.$route.meta.isIndex) this.wxInit()
// wxConfig
// .createMiniprogramUrlLink({
// path: 'packageEquity/pages/active/active',
// appId: 'wxfe82b8d65d07808f',
// query: '?ss=ss',
// envVersion: 'release'
// })
// .then(url => {
// console.log(url)
// })
},
methods: {
wxInit () {
let _this = this
wxConfig.init(['shareAppMessage', 'sendChatMessage', 'getCurExternalContact', 'getContext']).then(() => {
wxConfig.getContext().then(({ entry }) => {
_this.$parent.entry = entry
_this.entry = entry
})
})
},
iosTimeFormat (time) {
return time.replace(/\-/g, '/')
},
showShareModel (i = {}) {
let {
tabIndex,
$route: { name }
} = this
if (name != 'merchant') {
if (tabIndex == 0 && i.remainAmount < 1) return
if (tabIndex == 1 && i.residueAmount < 1) return
}
wxConfig
.getCurExternalContact()
.then(res => {
console.log('当前外部联系人', res)
i.is_contact = res
this.sendMessage(i)
})
.catch(() => {
this.sendMessage(i)
})
},
sendMessage (i) {
const {
shopmall_appid,
request: { baseURL }
} = window.$fetchConfig
let { merchantId, merchantName, userName, sapCode, uuid, channelType } = this.getLocalStorage('dj_scrm_userInfo')
let { tabIndex, entry } = this
let { name } = this.$route
let { userId, id, couponName, activityName, packageName, goodsName, goodsImage, discountType, shareType, marketingType } = i
let query = `merchantId=${merchantId}&shareTime=${Date.now()}`
if (sapCode) query = `${query}&storeCode=${sapCode}`
const entryType = entry != 'normal'
this.showLoading()
let params = {
coupon: {
path: channelType == 2 ? 'packageMine/pages/boutique/gift/gift' : 'packageShopmall/packageMine/pages/boutique/gift/gift',
desc: '您的专属服务顾问为您发来了优惠券,请点击领取~',
imgUrl: 'http://img01.glsx.com.cn/upload/biz/dracMini-yh-10004.png'
},
activity: {
path: channelType == 2 ? 'packageMall/pages/detail/detail' : 'packageShopmall/packageMall/pages/detail/detail',
desc: '您有一个秒杀活动可参加',
imgUrl: 'http://img01.glsx.com.cn/upload/biz/dracMini-ms-10004.png'
},
merchant: {
path: channelType == 2 ? 'pages/tab/index/index' : 'pages/tab/shopMall/index',
desc: '',
imgUrl: 'https://img01.glsx.com.cn/weapp/resource/scrm-mobile/activity/miniprogram-cover.jpg'
}
}[name],
title = {
coupon: couponName,
activity: activityName,
merchant: merchantName
}[name],
h5Params = {}
if (name === 'coupon') {
/**卡券 */
if (tabIndex == 0) {
query = `id=${id}&userId=${userId}&employName=${this.toUnicode(i.employeeName)}&${query}`
} else {
params.path = channelType == 2 ? 'packageMall/pages/coupon/coupon' : 'packageShopmall/packageMall/pages/coupon/coupon'
query = `couponId=${id}&${query}&issueName=${this.toUnicode(userName)}&issueDate=${new Date().getTime()}&shareSource=1&shareStaffName=${this.toUnicode(userName)}&shareStaffUuid=${uuid}`
title = `${couponName}(${window.$discountType[discountType]}券)`
this.couponShare(i)
}
}
if (name === 'activity') {
/**活动 */
// if (tabIndex == 0) {
// 1-普通秒杀;2-直播间秒杀;3-众筹
switch (marketingType) {
case 1:
query = `isActivity=true&id=${id}&${query}&shareStaffName=${this.toUnicode(userName)}&shareStaffUuid=${uuid}`
break
case 2:
/** 直播 */
break
case 3:
shareType = 'h5'
let { corpId, agentId } = this.getLocalStorage('dj_scrm_corpId')
let link = `${baseURL}/scrm-wx-merchant-activity/#/`
link = `${link}?${query}&id=${i.id}&shareStaffUuid=${uuid}&shareStaffName=${this.toUnicode(userName)}&shareStaffType=2&corpId=${corpId}&sharedTime=${Date.now()}`
if (agentId) link = `${link}&agentId=${agentId}`
h5Params = {
imgUrl: i.posterImg || i.activityImg,
desc: i.activitySharingWords || `限时大型众筹,活动时间${new Date(this.iosTimeFormat(i.startTime)).format('yyyy/M/d')}-${new Date(this.iosTimeFormat(i.endTime)).format('yyyy/M/d')}`,
title: i.forwardTitle || i.activityName,
link
}
break
default:
break
}
// } else {
// /**直播 */
// }
}
if (name === 'merchant') {
/**店铺 */
switch (+tabIndex) {
case 1:
let isjt = i.packageType == 2
const STORE_PATH = channelType == 2 ? 'packageEquity/pages/package/package' : 'packageShopmall/packageEquity/pages/package/package'
const JT_PATH = channelType == 2 ? 'packageEquity/pages/open/open' : 'packageShopmall/packageEquity/pages/open/open'
params.path = isjt ? JT_PATH : STORE_PATH
params.imgUrl = 'http://img01.glsx.com.cn/upload/biz/dracMini-qy-10004.png'
params.desc = '您的专属客服顾问为您发来了会员套餐,点击查看哦'
query = `id=${id}&${query}&shareStaffName=${this.toUnicode(userName)}&shareStaffUuid=${uuid}&packageType=${i.packageType}`
title = packageName
break
case 2:
params.path = channelType == 2 ? 'packageMall/pages/detail/detail' : 'packageShopmall/packageMall/pages/detail/detail'
params.imgUrl = goodsImage
params.desc = ''
query = `id=${id}&${query}&shareStaffName=${this.toUnicode(userName)}&shareStaffUuid=${uuid}`
title = goodsName
break
case 3:
/**众筹 */
let { corpId, agentId } = this.getLocalStorage('dj_scrm_corpId')
let link = `${baseURL}/scrm-wx-merchant-activity/#/`
link = `${link}?${query}&id=${i.id}&shareStaffUuid=${uuid}&shareStaffName=${this.toUnicode(userName)}&shareStaffType=2&corpId=${corpId}&sharedTime=${Date.now()}`
if (agentId) link = `${link}&agentId=${agentId}`
h5Params = {
imgUrl: i.posterImg || i.activityImg,
desc: i.activitySharingWords || `限时大型众筹,活动时间${new Date(this.iosTimeFormat(i.startTime)).format('yyyy/M/d')}-${new Date(this.iosTimeFormat(i.endTime)).format('yyyy/M/d')}`,
title: i.forwardTitle || i.activityName,
link
}
break
default:
break
}
}
if (shareType == 'h5') {
console.log(h5Params)
if (entryType)
this.sendChatMessage(h5Params, 'news', () => {
bigdatautilApi.reportTrack(i.id)
})
else
wxConfig
.shareAppMessage(h5Params)
.then(() => {
this.hideLoading()
bigdatautilApi.reportTrack(i.id)
})
.catch(() => {
this.hideLoading()
})
} else {
if (entryType)
this.sendChatMessage({
appid: shopmall_appid,
title,
imgUrl: params.imgUrl,
page: `/${params.path}.html?${query}`
})
else
this.shareAppMessage(
{
path: params.path,
query,
appId: shopmall_appid
},
{
desc: params.desc,
title,
imgUrl: params.imgUrl
}
)
}
},
sendChatMessage (params, msgtype = 'miniprogram', callBack) {
wxConfig
.sendChatMessage({
msgtype,
[msgtype]: params,
enterChat: false
})
.then(() => {
this.hideLoading()
if (callBack) callBack()
})
.catch(err => {
console.log('当前会话', err)
this.hideLoading()
})
},
shareAppMessage (linkParams, messageParams) {
wxConfig.createMiniprogramUrlLink(linkParams).then(link => {
wxConfig
.shareAppMessage({
link,
...messageParams
})
.then(() => {
this.hideLoading()
})
.catch(() => {
this.hideLoading()
})
})
},
toUnicode (chineseStr = '') {
let unicodeStr = ''
for (let i = 0, iLength = chineseStr.length; i < iLength; i++) {
unicodeStr += '@' + chineseStr.charCodeAt(i).toString(16)
}
return unicodeStr
},
couponShare (item) {
let { is_contact, id } = item
let obj = {
couponId: id,
shareType: 1
}
if (is_contact)
obj.userList = [
{
userId: is_contact
}
]
else obj.shareType = 0
}
}
}