Action.vue
12.6 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
<template>
<div
:class="['action isFullSucreen flex', { bgBlack: videoFullscreen }, { liveBtn: isImAction }]"
v-if="show"
>
<div
class="btn-box flex"
v-show="!videoFullscreen"
>
<div
class="item"
@click="getPoster"
>
<div class="sprite-icon icon-poster"></div>
海报
</div>
</div>
<div class="price">
<span class="unit">¥</span>
{{ detail.price }}
<span>.{{ detail.decimal }}</span>
</div>
<div
:class="['btn text-center', { disabled: !detail.isStaffLoginLink && (iSMiniprogram || detail.activityStatus == 3 || detail.buyFlag == 2) }, { short: detail.buyFlag == 3 }]"
@click="submit"
@touchstart="touchstart"
@touchend="touchend"
>
<template v-if="detail.isStaffLoginLink">
员工注册
<wx-open-launch-weapp
class="mini"
:path="path"
:username="miniprogramInfo.username"
:env-version="miniprogramInfo.envVersion"
>
<script type="text/wxtag-template">
<div class="mini-btn">点击跳转</div>
</script>
</wx-open-launch-weapp>
</template>
<template v-else>
<template v-if="detail.activityStatus == 1 && detail.buyFlag != 2">预热下单</template>
<template v-else-if="detail.activityStatus == 3">活动已结束</template>
<template v-else>
<template v-if="detail.buyFlag == 3">继续参团</template>
<template v-else-if="detail.buyFlag == 2">已参团</template>
<template v-else>立即参团</template>
</template>
</template>
</div>
<pay-modal
v-model="showModal"
:list="formList"
@cancel="showModal = false"
@pay="checkOut"
:payStatus="payStatus"
:carInfo="carInfo"
/>
<van-overlay
:show="showPoster"
@click.self="showPoster = false"
>
<div
class="wrapper"
@click.stop
>
<van-image
:src="posterImg"
width="100%"
height="100%"
>
<template v-slot:loading>
<van-loading
type="spinner"
size="20"
/>
</template>
</van-image>
</div>
</van-overlay>
</div>
</template>
<script type="text/ecmascript-6">
import { shopmallApi, wxConfig } from '@/api'
import { util } from '@/utils'
export default {
name: 'Action',
watch: {
watchUpdataCarInfo: {
immediate: true,
handler (n) {
let {
activityInfo: { carInfo },
activityInfo }
= this.$store.state.app
if (carInfo) this.carInfo = carInfo
this.detail = activityInfo
}
},
watchInfo: {
immediate: true,
handler (n) {
if (n.id) {
this.init(n)
}
}
}
},
computed: {
watchInfo () {
return this.$store.state.app.activityInfo
},
watchUpdataCarInfo () {
return this.$store.state.app.updataCarInfo
}
},
data () {
return {
show: false,
showModal: false,
showPoster: false,
formList: [],
payStatus: Date.now(),
posterImg: '',
carInfo: {},
iSMiniprogram: true,
miniprogramInfo: {},
path: ''
}
},
props: {
videoFullscreen: {
type: Boolean,
default: false
},
isImAction: {
type: Boolean,
default: false
}
},
mounted () {
this.iSMiniprogram = window.__wxjs_environment === 'miniprogram'
},
methods: {
init (n) {
const { isStaffLoginLink } = this.getQuery(),
{ miniprogramInfo } = window.$fetchConfig,
params = this.getLocalStorage('wx_scrm_link_params'),
userInfo = this.getUserInfo(),
data = {
staffName: userInfo.nickName,
fileUrl: userInfo.logo,
merchantId: params.merchantId,
type: n.employeeRegistrationLinkFlag == 2 ? 1 : 0
}
this.miniprogramInfo = miniprogramInfo
this.path = `packageStoreAssistant/packageAuth/pages/authentication/register/register.html?data=${encodeURIComponent(JSON.stringify(data))}`
let expressFee = n.expressFee || 0
let [price, decimal] = this.centsToyuan(n.retailPrice + expressFee).toString().split('.')
if (!decimal) decimal = '00'
n.price = price
n.decimal = decimal
n.isStaffLoginLink = isStaffLoginLink
// limitPurchaseFlag 是否限购标志:1 否;2 是;
//buyFlag 1是未购买或者未限购,2是已购买且达到购买上限,3是已购买且未达到购买上限
let formList = []
if (n.selectPhoneNumberFlag && n.selectPhoneNumberFlag == 2) {
formList.push({
key: 'userPhone',
type: 'tel',
maxlength: 11,
name: '手机号'
})
}
if (n.selectCarNumberFlag && n.selectCarNumberFlag == 2) formList.push({
key: 'plateNo',
name: '车牌号',
type: 'plate'
})
if (n.selectVehicleTypeFlag && n.selectVehicleTypeFlag == 2) {
formList.push(...[{
route: 'carBrands',
name: '品牌',
key: 'carBrandsText'
}, {
route: 'carSeries',
name: '车型',
key: 'carTypeText'
}])
}
let list = [{
key: 'formDescribeFirst',
maxlength: 40,
name: n.formDescribeFirst
}, {
key: 'formDescribeSecond',
maxlength: 40,
name: n.formDescribeSecond
}, {
key: 'formDescribeThird',
maxlength: 40,
name: n.formDescribeThird
}]
this.formList = [...formList, ...list]
this.show = true
},
submit () {
let { detail, iSMiniprogram } = this
if (detail.isStaffLoginLink) {
return
}
if (iSMiniprogram) {
this.showToast('参团请拨打短信中咨询热线')
return
}
if (detail.buyFlag == 2 || detail.activityStatus == 3) return
this.showModal = true
},
checkOut: util.debounce(({ obj, that }) => {
let { detail } = that
let { nickName, logo } = util.getUserInfo()
let linkParams = util.getLocalStorage('wx_scrm_link_params') || {}
let params = {
...obj,
contactAddress: ' ',
contactName: ' ',
contactPhone: ' ',
activityId: detail.id,
orderSource: 4,
imageUrl: logo,
nickName,
orderGoodsList: [{
goodsId: detail.goodsId,
activityPrice: detail.retailPrice * 100,
goodsNumber: 1
}],
shareStaffUuid: linkParams.shareStaffUuid || '',
shareStaffType: linkParams.shareStaffType || '',
shareStaffPhone: linkParams.userPhone || '',
shareStaffName: linkParams.shareStaffName || '',
shareStaffImageUrl: linkParams.shareStaffImageUrl || '',
shareOpenId: linkParams.openId || '',// 个微分享然后下单的时候,用来记录分享人的openId
shareChannel: linkParams.shareChannel || '', //分享类型
exclusiveUuid: linkParams.exclusiveUuid || '',//专属链接参数
isExclusive: linkParams.isExclusive || ''//专属链接参数
}
shopmallApi.createOrder(params).then(({ data, code, message }) => {
if (detail.liveBroadcastRoomId) data.liveBroadcastRoomId = detail.liveBroadcastRoomId
if (code == '0') that.pay(data)
else {
that.payStatus = Date.now()
that.showToast(message)
}
})
}, 1e3),
pay (orderInfo) {
this.showLoading('结算中')
this.payStatus = Date.now()
console.log(orderInfo)
shopmallApi.payOrder({
orderCode: orderInfo.orderCode,
paymentSource: 2 //1128版本 支付来源(1:小程序,2:公众号)
}).then(async ({ code, data, message }) => {
this.hideLoading()
let [url] = window.location.href.split('?')
let redirectUrl = `${url}/success`
if (code == '0') {
this.showModal = false
let { needPay, payParams, order } = data,
{ videoFullscreen } = this
if(order.orderGoodsDTOS && order.orderGoodsDTOS.length) orderInfo.orderNumber = order.orderGoodsDTOS[0].orderCode
if (needPay) {
let params = {
nonceStr: payParams.nonceStr,
paySign: payParams.paySign,
signType: payParams.signType,
timestamp: payParams.timeStamp,
packages: payParams.packages
}
if (window.$ISMiniprogram) {
wx.miniProgram.navigateTo({
url: `/pages/h5Pay/h5Pay?payData=${encodeURIComponent(JSON.stringify({
nonceStr: payParams.nonceStr,
paySign: payParams.paySign,
signType: payParams.signType,
timeStamp: payParams.timeStamp,
package: payParams.packages
}))}&redirectUrl=${redirectUrl}`//
})
}
else wxConfig.chooseWXPay(params).then(() => this.to('crowdfunding.success', { orderInfo }))
} else {
if (window.$ISMiniprogram) wx.miniProgram.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(redirectUrl)}`
})
else this.to('crowdfunding.success', { orderInfo })
}
if (videoFullscreen) {
console.log('直播间下单', orderInfo)
const res = await shopmallApi.liveRoomReport({
bizDataCode: orderInfo.orderCode,
liveBroadcastRoomId: orderInfo.liveBroadcastRoomId,
})
console.log(res)
}
} else this.showToast(message)
})
},
getPoster () {
let { id } = this.detail
let userInfo = this.getUserInfo()
let { phone, nickName, logo } = userInfo
let shareStaffType = 1
if (this.ISWXWORK) {
nickName = userInfo.userName
logo = userInfo.staffAvatar
shareStaffType = 2
if (userInfo.loginList.length && userInfo.loginList[0].phone) phone = userInfo.loginList[0].phone
}
this.showLoading()
shopmallApi.getPoster({
id,
nickName: this.toUnicode(nickName),
phone,
imageUrl: encodeURIComponent(logo),
shareStaffType
}).then(res => {
console.log(res)
this.hideLoading()
this.posterImg = res
this.showPoster = true
})
}
}
}
</script>
<style scoped lang="scss">
.action {
position: fixed;
left: 0;
width: calc(100% - 32px);
height: 50px;
background: #ffffff;
z-index: 3;
padding: 0 16px;
animation: show-goods-action 0.5s forwards;
.btn-box {
font-size: 13px;
font-weight: bold;
color: #656566;
.item {
margin-right: 8px;
width: 28px;
height: 35px;
position: relative;
overflow: hidden;
}
}
.price {
font-weight: 600;
color: #f13c3d;
font-size: 24px;
display: flex;
align-items: baseline;
margin-left: 10px;
.unit {
font-size: 12px;
}
span {
font-size: 14px;
}
}
.btn {
width: 200px;
height: 40px;
background: #f13c3d;
box-shadow: 0px 2px 6px 2px rgba(241, 60, 61, 0.1);
border-radius: 4px;
border: 1px solid #f13c3d;
margin-left: auto;
font-size: 14px;
font-weight: 500;
color: #ffffff;
box-sizing: border-box;
line-height: 40px;
position: relative;
.mini {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 2;
opacity: 0;
&-btn {
width: 100%;
height: 100%;
}
}
.sprite-icon {
margin: 0 auto;
}
}
.disabled {
background: #b1b1b1;
border-color: #b1b1b1;
box-shadow: none;
}
.short {
width: 150px;
}
}
.bgBlack {
background: rgba(#000000, 0.6);
z-index: 9;
}
.action.liveBtn {
position: relative;
padding: 0 0 !important;
width: 100%;
height: 40px;
background: url('../assets/images/live-btn.png') no-repeat;
background-size: 100% 40px;
.price {
color: #ffffff;
width: calc(100% - 96px);
}
.btn {
background: transparent;
width: 96px;
text-align: center;
border-width: 0;
}
}
@keyframes show-goods-action {
0% {
bottom: -100%;
}
100% {
bottom: 0;
}
}
.isFullSucreen {
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
}
.wrapper {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 270px;
height: 555px;
background: #ffffff;
box-shadow: 0px 2px 8px 0px rgba(201, 202, 204, 0.5);
border-radius: 4px;
}
</style>