xiaoe_mp_npm 1.0.19-test01 → 1.0.20-test01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/miniprogram_dist/GoodsItem/index.js +1057 -1008
  2. package/miniprogram_dist/GoodsItem/index.json +6 -6
  3. package/miniprogram_dist/GoodsItem/index.scss +558 -548
  4. package/miniprogram_dist/GoodsItem/index.wxml +208 -201
  5. package/miniprogram_dist/GoodsItem/index.wxs +18 -18
  6. package/miniprogram_dist/GoodsItem/index.wxss +64 -41
  7. package/miniprogram_dist/LiveGoodsList/Header/index.js +54 -54
  8. package/miniprogram_dist/LiveGoodsList/Header/index.json +6 -6
  9. package/miniprogram_dist/LiveGoodsList/Header/index.less +45 -45
  10. package/miniprogram_dist/LiveGoodsList/Header/index.scss +105 -105
  11. package/miniprogram_dist/LiveGoodsList/Header/index.wxml +32 -32
  12. package/miniprogram_dist/LiveGoodsList/README.md +9 -9
  13. package/miniprogram_dist/LiveGoodsList/index.js +889 -875
  14. package/miniprogram_dist/LiveGoodsList/index.json +8 -8
  15. package/miniprogram_dist/LiveGoodsList/index.less +53 -53
  16. package/miniprogram_dist/LiveGoodsList/index.scss +92 -92
  17. package/miniprogram_dist/LiveGoodsList/index.wxml +103 -101
  18. package/package.json +1 -1
  19. package/src/GoodsItem/index.js +1057 -1008
  20. package/src/GoodsItem/index.json +6 -6
  21. package/src/GoodsItem/index.scss +558 -548
  22. package/src/GoodsItem/index.wxml +208 -201
  23. package/src/GoodsItem/index.wxs +18 -18
  24. package/src/GoodsItem/index.wxss +1 -2026
  25. package/src/LiveGoodsList/Header/index.js +54 -54
  26. package/src/LiveGoodsList/Header/index.json +6 -6
  27. package/src/LiveGoodsList/Header/index.less +45 -45
  28. package/src/LiveGoodsList/Header/index.scss +105 -105
  29. package/src/LiveGoodsList/Header/index.wxml +32 -32
  30. package/src/LiveGoodsList/README.md +9 -9
  31. package/src/LiveGoodsList/index.js +889 -875
  32. package/src/LiveGoodsList/index.json +8 -8
  33. package/src/LiveGoodsList/index.less +53 -53
  34. package/src/LiveGoodsList/index.scss +92 -92
  35. package/src/LiveGoodsList/index.wxml +103 -101
  36. package/src/LiveGoodsList/index.wxss +218 -218
@@ -1,1008 +1,1057 @@
1
- /*
2
- * @Descripttion:
3
- * @version:
4
- * @Author: conlinchen
5
- * @Date: 2021-10-28 18:17:48
6
- * @LastEditors: conlinchen
7
- * @LastEditTime: 2021-11-18 19:49:11
8
- */
9
- import { debounce, rpxToVmin } from "../common/utils/index"
10
- import {
11
- getUserPermission,
12
- getUserPermissionNew,
13
- snapCheck,
14
- snapCheckNew,
15
- showGoods,
16
- requestChangeShow,
17
- setGoodsSellOut,
18
- getGoodValue
19
- } from "../common/api/liveGoodsList"
20
- import {
21
- ASSOCIATION,
22
- PUNCH_CARD
23
- } from "../common/utils/constants.js";
24
-
25
- const { utils, sensorLog } = require("live-mp-tools");
26
-
27
- const computedBehavior = require('miniprogram-computed').behavior
28
-
29
- Component({
30
- behaviors: [computedBehavior],
31
- options: {
32
- addGlobalClass: true,
33
- },
34
- /**
35
- * 组件的属性列表
36
- */
37
- properties: {
38
- goodsInfo: {
39
- type: Object,
40
- value: {},
41
- observer(newVal) {
42
- // 商品没有的话,不处理
43
- if (!newVal.id) return
44
- //超级会员全免权益
45
- let svipAllFree = newVal.resource_rights_type === 1
46
- let currentActive = ''
47
- if (svipAllFree) {
48
- currentActive = '超级会员'
49
- } else {
50
- currentActive = newVal.currentActive
51
- }
52
- //IOS小程序端 ios小程序商品列表 直播、线下课、班课、实物商品可买,其他知识商品不可买,需不显示价格 点击去抢购后按现网逻辑跳转至小程序的商品详情
53
- let info = wx.getSystemInfoSync()
54
- let IOSMiniProgramCanBuy = [4, 29, 35, 21, 69].indexOf(newVal.resource_type) > -1 //true-能买 false-不能买
55
- let isIOS = info.platform === 'ios'
56
- console.log("platform", info.platform, isIOS)
57
- const pages = getCurrentPages();
58
- const currentPage = pages[pages.length - 1];
59
- const url = `/${currentPage.route}`;
60
- //预热开始时间
61
- let startTime = newVal.start_at && new Date(newVal.start_at.replace(/-/g, "/")) || new Date()
62
- let time = startTime.getTime() - newVal.sec_kill_preheat_time * 1000
63
- let preHeatTime = new Date(time) || new Date()
64
-
65
- let hasPreheat = newVal.sec_kill_is_preheat === 1
66
-
67
- let startTime2 = newVal.start_at && new Date(newVal.start_at.replace(/-/g, "/")) || new Date()
68
- let nowTime = new Date().getTime()
69
- let preheating = hasPreheat && nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
70
- let isSeckill = currentActive === '秒杀'
71
- let checked = newVal.is_display_package === 1
72
-
73
-
74
- this.setData({
75
- goodsItem: newVal,
76
- currentActive,
77
- IOSMiniProgramCanBuy,
78
- isIOS,
79
- page_path: url,
80
- preHeatTime,
81
- preheating,
82
- isSeckill,
83
- checked
84
- }, () => {
85
- const isSoldOut = +newVal.is_sell_out === 1;
86
- const isRealOver = newVal.stock === 0 ||
87
- (newVal.is_activity &&
88
- (newVal.activity_type === 8 || newVal.activity_type === 3) &&
89
- newVal.activity_stock - newVal.activity_order_num === 0);
90
- const isOver = isSoldOut || isRealOver;
91
-
92
- this.setData({
93
- isOver,
94
- isSoldOut,
95
- isRealOver,
96
- })
97
- this.countTime()
98
- })
99
- }
100
- },
101
- sending: {
102
- type: Boolean,
103
- value: false
104
- },
105
- explainingGoods: {
106
- type: Object,
107
- value: {}
108
- },
109
- isInElive: {
110
- type: Boolean,
111
- value: false
112
- },
113
- aliveInfo: {
114
- type: Object,
115
- value: {},
116
- },
117
- // 是否去客服内支付
118
- allContactPay: {
119
- type: Boolean,
120
- value: false
121
- },
122
- //店铺设置是否展示券后价
123
- coupon_switch: {
124
- type: Boolean,
125
- value: false
126
- },
127
- envName: {
128
- type: String,
129
- value: ""
130
- },
131
- sensorReportParams: {
132
- type: Object,
133
- value: {}
134
- },
135
- current_role: {
136
- type: String,
137
- value: 'student'
138
- },
139
- isFullScreen: {
140
- type: Boolean,
141
- value: false
142
- },
143
- style: {
144
- type: String,
145
- value: ''
146
- },
147
- index: {
148
- type: Number,
149
- value: -1
150
- },
151
- // 是否是新带货接口灰度
152
- isGrayMarketing: {
153
- type: Boolean,
154
- value: false
155
- },
156
- isManage: {
157
- type: Boolean,
158
- value: false
159
- },
160
- visibleSwitchStatusBtn: {
161
- type: Boolean,
162
- value: false
163
- },
164
- sendingGoodId: {
165
- type: String,
166
- value: '',
167
- },
168
- },
169
-
170
- lifetimes: {
171
- // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
172
- attached: function () {
173
-
174
- },
175
- moved: function () { },
176
- detached: function () { },
177
- },
178
-
179
- /**
180
- * 组件的初始数据
181
- */
182
- data: {
183
- time: '',
184
- goodsItem: {},
185
- currentActive: '',
186
- IOSMiniProgramCanBuy: false,
187
- isIOS: false,
188
- page_path: '',
189
- preHeatTime: '',
190
- isSeckill: false,
191
- checked: false,
192
- switchLoading: false,
193
- imageRadius: rpxToVmin(16),
194
- isOver: false, //是否已抢光
195
- isSoldOut: false, //商品是否设置已售罄
196
- isRealOver: false, //商品是否为非手动售罄下的,真实抢光
197
- changeStateLoading: false, // 修改状态 loading(如售罄状态、显示状态)
198
- },
199
- computed: {
200
- showPreferentialPrice(properties) {
201
- // 券后价小于展示价格的时候展示券后价; coupon_switch B端店铺设置 是否展示券后价,err_code === 0 是正常,非0表示券后价相关接口报错了,去抢购按钮展示为查看详情
202
- //超级会员全免权益
203
- let svipAllFree = properties.goodsInfo.resource_rights_type === 1
204
- //免费的情况下不展示券后价
205
- let isFree = svipAllFree || properties.goodsInfo.priceShow === 0
206
- let showPreferentialPrice = properties.coupon_switch && properties.goodsInfo.preferential_price < properties.goodsInfo.priceShow && !properties.goodsInfo.err_code && !isFree
207
- return showPreferentialPrice
208
- },
209
- params_url(data) {
210
- if (!Object.keys(data.goodsItem).length) {
211
- return ''
212
- } else {
213
- // 后端规则拼接参数规则:$ => ?、@ => &
214
- // 商品带货链接需拼接多一个aliveId
215
- const aliveId = data.aliveInfo.alive_id
216
- const url = data.goodsItem.target_url.replaceAll('&', "@")
217
- const link = url.replaceAll('?', "$")
218
- // 判断后端返回链接是否已拼接(如:?type= )参数,兼容 aliveId 拼接符
219
- const symbol = url.indexOf('?') !== -1 ? '@' : '$'
220
- return `${data.page_path}?type=1&link=${link}${symbol}aliveId=${aliveId}&title=${data.goodsItem.title}`
221
- }
222
- },
223
- isStudent(properties) {
224
- return properties.current_role === 'student'
225
- },
226
- //超过99999不够位置展示划线价,只能不要孩子了
227
- showPriceLine(data) {
228
- return data.goodsItem.priceLine > 0 && (data.goodsItem.priceShow < 100000 || !data.showPreferentialPrice)
229
- },
230
- showPrice(data) {
231
- return data.isIOS && data.IOSMiniProgramCanBuy && data.goodsItem.priceShow !== 0 || !data.isIOS && data.goodsItem.priceShow !== 0
232
- },
233
- // 是否为安卓设备
234
- isAndroid() {
235
- let info = wx.getSystemInfoSync()
236
- return info.platform === 'android'
237
- },
238
- //讲解中的商品
239
- isShowExamplaining(properties) {
240
- return properties.explainingGoods && properties.explainingGoods.resource_id === properties.goodsItem.resource_id;
241
- },
242
- //销量/订阅。只有 实物商品 21 、专栏 6、大专栏 8、会员 5 展示,受B端店铺设置(hide_sub_count):隐藏商品销量控制 0-显示 1-隐藏
243
- hasSaleNum(data) {
244
- return !data.goodsItem.hide_sub_count && data.goodsItem.order_num > 0
245
- },
246
- //销量/订阅。只有 实物商品 21 、专栏 6、大专栏 8、会员 5 展示
247
- saleNum(data) {
248
- //实物商品
249
- if (data.goodsItem.resource_type === 21 || data.goodsItem.resource_type === 41 || data.goodsItem.resource_type === 68) {
250
- return ' 已售 ' + (data.goodsItem.order_num || 0)
251
- } else if (data.goodsItem.resource_type === 6 || data.goodsItem.resource_type === 8 || data.goodsItem.resource_type === 5) {
252
- return ' 订阅 ' + (data.goodsItem.order_num || 0)
253
- } else {
254
- return ''
255
- }
256
- },
257
- // 点击去查看
258
- isNeedToContact(data) {
259
- return Boolean(data.allContactPay || (data.isIOS && !data.IOSMiniProgramCanBuy))
260
- },
261
- btnTxt(data) {
262
- // 以下各种情况,按去查看 -> 已抢光 -> 查看详情 -> 免费领取 -> 券后 -> 去抢购 优先级展示
263
- // 超级会员全免权益
264
- let svipAllFree = data.goodsItem.resource_rights_type === 1
265
- if (data.isSoldOut && !data.isStudent) {
266
- return "已售罄"
267
- } else if (data.isOver) {
268
- // 库存为0,已售罄
269
- return "已抢光"
270
- } else if (data.allContactPay || (data.isIOS && !data.IOSMiniProgramCanBuy)) {
271
- // IOS小程序中不能买的展示去查看,跳转到小程序客服
272
- return "去查看"
273
- } else if (data.goodsItem.err_code) {
274
- // 券后价接口报错,领取不了优惠券的情况
275
- return "查看详情"
276
- } else if (svipAllFree || data.goodsItem.priceShow === 0) {
277
- // 超级会员全免或者0元商品
278
- return "免费领取"
279
- } else if (data.showPreferentialPrice) {
280
- // 展示券后价
281
- return "购买"
282
- } else {
283
- return "购买"
284
- }
285
- },
286
- //当前适用的活动或者超级会员,活动价低就是活动,会员价低就是超级会员,超级会员全免,肯定最低,适用超级会员
287
- // "限时折扣",
288
- // "好友助力",
289
- // "裂变海报",
290
- // "拼团",
291
- // "涨粉神器",
292
- // "秒杀",
293
- // "超级会员",
294
- //是否开启了预热 1-开启 0-未开启
295
- hasPreheat(data) {
296
- return data.goodsItem.sec_kill_is_preheat === 1
297
- },
298
- //秒杀开始时间
299
- startTime(data) {
300
- return data.goodsItem.start_at && new Date(data.goodsItem.start_at.replace(/-/g, "/")) || new Date()
301
- },
302
- //超级会员
303
- isSupperVip(data) {
304
- return data.currentActive === '超级会员'
305
- },
306
- //秒杀活动需要预约
307
- isAppointment(data) {
308
- data.goodsItem.appointment = 1 //mock
309
- return data.goodsItem.appointment === 1
310
- },
311
- secText(data) {
312
- if (data.isSeckill && data.preheating) {
313
- return `秒杀活动将在 ${data.time} 后开始`
314
- } else {
315
- return ''
316
- }
317
- },
318
- filterSrc(data) {
319
- return utils.replaceCDN(data.goodsItem.img_url, '?imageMogr2/thumbnail/400x400>/ignore-error/1')
320
- },
321
- // 是否展示已抢完
322
- // 学员端:已设置售罄、或者已抢完
323
- // 讲师端:已抢完,且未设置已售罄
324
- isSellOut({ isStudent, isOver, isRealOver }) {
325
- return isStudent ? isOver : isRealOver;
326
- },
327
- // 已售百分比
328
- percentage(data) {
329
- if (data.isSellOut) return 100
330
- // 无库存 拼团、限时抢购
331
- if (!data.goodsItem.activity_stock) return 28
332
- let num = 0
333
- num = (data.goodsItem.activity_order_num / data.goodsItem.activity_stock) * 100
334
- // 有库存时,最低占40%
335
- return num <= 40 ? 40 : num
336
- },
337
- // 商品剩余数量
338
- residueQuantity(data) {
339
- let formatNum = (num) => {
340
- if (!num || isNaN(num)) return num
341
- num = Number(num)
342
- if (Math.abs(num) >= 100000000) {
343
- num = num / 100000000
344
- return this.isDecimals(Math.floor(num * 100) / 100) ? Math.floor(num * 100) / 100 + '亿' : num + '亿'
345
- } else if (Math.abs(num) >= 10000) {
346
- num = num / 10000
347
- return this.isDecimals(Math.floor(num * 100) / 100) ? Math.floor(num * 100) / 100 + '万' : num + '万'
348
- } else {
349
- return num
350
- }
351
- }
352
-
353
- // "已抢光"
354
- if (data.isSellOut) return '已抢光'
355
-
356
- // 没有库存 - 已开抢
357
- if (!data.goodsItem.activity_stock) return '已开抢'
358
-
359
- return `仅剩${formatNum(data.goodsItem.activity_stock - data.goodsItem.activity_order_num)}件`
360
- },
361
- // 配送方式(-1:全部 1:快递配送 2:自提)
362
- distributionWay(data) {
363
- let text = ''
364
- switch (data.goodsItem.distribution_pattern) {
365
- case -1:
366
- text = '自提·快递'
367
- break
368
- case 1:
369
- text = '快递'
370
- break
371
- case 2:
372
- text = '自提'
373
- break
374
- default:
375
- text = ''
376
- break
377
- }
378
- return text
379
- },
380
- distributionPattern(data) {
381
- return [-1,1,2].indexOf(data.goodsItem.distribution_pattern) !== -1
382
- }
383
- },
384
- /**
385
- * 组件的方法列表
386
- */
387
- methods: {
388
- async checkSellOut() {
389
- // 非真实抢光,需要拿最新状态判断下
390
- if (this.data.isRealOver) return;
391
-
392
- if (this.data.isNeedToContact) {
393
- const goodsStatusRes = await this.getGoodsStatus()
394
-
395
- if (!goodsStatusRes) return
396
-
397
- // 更新售罄状态
398
- const is_sell_out = +goodsStatusRes.is_sell_out
399
- this.triggerEvent('changeGoodsState', {
400
- index: this.properties.index,
401
- type: 'is_sell_out',
402
- state: is_sell_out,
403
- });
404
-
405
- if (is_sell_out) {
406
- return wx.showToast({
407
- title: '很遗憾, 手慢抢光了',
408
- icon: 'none',
409
- duration: 3000,
410
- })
411
- }
412
-
413
- this.toDetails()
414
- } else {
415
- this.snapUpCheck()
416
- }
417
- },
418
- snapUpCheck: debounce(async function () {
419
- !this.data.isOver && this.showToast('努力加载中')
420
-
421
- const goodsStatusRes = await this.getGoodsStatus()
422
-
423
- if (!goodsStatusRes) return
424
-
425
- // 更新售罄状态
426
- const is_sell_out = +goodsStatusRes.is_sell_out
427
- this.triggerEvent('changeGoodsState', {
428
- index: this.properties.index,
429
- type: 'is_sell_out',
430
- state: is_sell_out,
431
- });
432
-
433
- if (is_sell_out) {
434
- return wx.showToast({
435
- title: '很遗憾, 手慢抢光了',
436
- icon: 'none',
437
- duration: 3000,
438
- })
439
- }
440
-
441
- this.triggerEvent('sendNewMsg')
442
- let { aliveInfo, sensorReportParams, goodsInfo, isFullScreen } = this.properties
443
- sensorLog.sensors.track('click_butt', {
444
- page_id: 'e_alive#mini#first#alive_room',
445
- page_name: '直播间页面',
446
- l_program: '鹅直播',
447
- page_path: '鹅直播#小程序#首页#直播间页面',
448
- page_button: "列表去抢购",
449
- client: "小程序",
450
- goods_id: goodsInfo.id,
451
- app_id: aliveInfo.app_id,
452
- c_user_id: aliveInfo.user_id,
453
- union_id: wx.getStorageSync('userInfo').universal_union_id,
454
- current_role: sensorReportParams.current_role,
455
- resource_id: aliveInfo.alive_id,
456
- $url_path: `alive/${aliveInfo.alive_id}`,
457
- type: sensorReportParams.type,
458
- cmm1: sensorReportParams.alive_type,
459
- cmm2: sensorReportParams.version_type,
460
- comm2: sensorReportParams.pay_type,
461
- cmm3: isFullScreen ? '全屏' : '非全屏'
462
- })
463
- // 线下课29课时包42/拼团 --判断权益
464
- if ([29, 42].indexOf(this.data.goodsItem.resource_type) > -1 || this.data.goodsItem.activity_type === 6) {
465
- this.judgePermission()
466
- return
467
- }
468
- let params = {
469
- id: this.data.goodsItem.id,
470
- resource_id: this.data.goodsItem.resource_id,
471
- resource_type: this.data.goodsItem.resource_type,
472
- price: this.data.goodsItem.price,
473
- app_id: this.data.aliveInfo.app_id,
474
- user_id: this.data.aliveInfo.user_id,
475
- coupon_id: this.data.goodsItem.coupon_id,
476
- alive_id: this.data.aliveInfo.alive_id
477
- }
478
- const url = this.properties.isGrayMarketing ? snapCheckNew : snapCheck
479
- url(params).then(res => {
480
- this.hideToast()
481
- let { code, data } = res.data
482
- if (code === 0) {
483
- if (data.err_msg) {
484
- this.showToast(data.err_msg)
485
- }
486
- if (data.is_sec_kill_toast) {
487
- this.showToast("秒杀活动开始,您未预约,需以原价购买!")
488
- }
489
- if (data.is_goods_detail === 1) {
490
- this.judgePermission(data.is_has_permission)
491
- } else if (data.is_more_sku === 1) {
492
- this.showSku()
493
- } else {
494
- this.showConfirmOrder(data.sku)
495
- }
496
- } else {
497
- this.showToast("网络繁忙,请稍后再试")
498
- }
499
- })
500
- }, 1000, true),
501
- getGoodsStatus() {
502
- if (this.data.isRealOver) {
503
- wx.showToast({
504
- title: '很遗憾, 手慢抢光了',
505
- icon: 'none',
506
- duration: 3000,
507
- })
508
-
509
- return Promise.resolve(null)
510
- }
511
-
512
- const { id, spu_id, resource_id } = this.data.goodsItem
513
- const { user_id, app_id, alive_id } = this.properties.aliveInfo
514
-
515
- return getGoodValue({
516
- spu_id: spu_id || id,
517
- user_id,
518
- app_id,
519
- alive_id,
520
- resource_id: id || resource_id,
521
- }, true)
522
- .then((res) => {
523
- res = res.data || {}
524
-
525
- if (res.code === 0 && res.data) {
526
- return res.data
527
- } else {
528
- this.showToast(res?.msg || res?.data?.msg || '获取商品状态失败')
529
- return null
530
- }
531
- })
532
- .catch(() => {
533
- this.showToast('获取商品状态失败')
534
- return null
535
- })
536
- },
537
- cardToDetails() {
538
- if (!this.data.isStudent) { return }
539
- let { aliveInfo, sensorReportParams, goodsInfo, isFullScreen } = this.properties
540
- sensorLog.sensors.track('click_butt', {
541
- page_id: 'e_alive#mini#first#alive_room',
542
- page_name: '直播间页面',
543
- l_program: '鹅直播',
544
- page_path: '鹅直播#小程序#首页#直播间页面',
545
- page_button: "列表空白热区",
546
- client: "小程序",
547
- goods_id: goodsInfo.id,
548
- product_name: goodsInfo.title,
549
- app_id: aliveInfo.app_id,
550
- c_user_id: aliveInfo.user_id,
551
- union_id: wx.getStorageSync('userInfo').universal_union_id,
552
- current_role: sensorReportParams.current_role,
553
- resource_id: aliveInfo.alive_id,
554
- $url_path: `alive/${aliveInfo.alive_id}`,
555
- type: sensorReportParams.type,
556
- cmm1: sensorReportParams.alive_type,
557
- cmm2: sensorReportParams.version_type,
558
- comm2: sensorReportParams.pay_type,
559
- cmm3: isFullScreen ? '全屏' : '非全屏'
560
- })
561
- this.judgePermission()
562
- },
563
- // 点击空白热区进来判断权益,或者接口返回有权益的时候进来判断跳转路径
564
- judgePermission: debounce(async function (permission) {
565
- const goodsStatusRes = await this.getGoodsStatus()
566
-
567
- if (!goodsStatusRes) return
568
-
569
- // 更新售罄状态
570
- const is_sell_out = +goodsStatusRes.is_sell_out
571
- this.triggerEvent('changeGoodsState', {
572
- index: this.properties.index,
573
- type: 'is_sell_out',
574
- state: is_sell_out,
575
- });
576
-
577
- if (is_sell_out) {
578
- return wx.showToast({
579
- title: '很遗憾, 手慢抢光了',
580
- icon: 'none',
581
- duration: 3000,
582
- })
583
- }
584
-
585
- // 实物21 有价优惠券41 超级会员23 可多次购买,没有权益说法,直接拉起客服;直播商品有没有权益都是去详情页。
586
- if ([41, 21, 23, 4].indexOf(Number(this.data.goodsItem.resource_type)) > -1) {
587
- this.toDetails()
588
- return
589
- }
590
-
591
- if (permission !== 0 && permission !== 1) {
592
- permission = await this.getUserPermission()
593
- }
594
-
595
- // 有权益的情况下
596
- if (permission) {
597
- // 电子书20/班课35 鹅学习不支持,无权益的情况下,内嵌h5, 有权益TOAST提示
598
- if ([20, 35].indexOf(this.data.goodsItem.resource_type) > -1) {
599
- this.showToast('您已拥有该课程,小程序内暂不支持学习此课程')
600
- } else {
601
- // 弹出提示去小程序学习 有三种可能 -圈子小程序 -小鹅通小程序 -打卡小程序
602
- this.showdialog(this.data.goodsItem)
603
- }
604
- } else {
605
- // 没有权益的情况下 直播商品去直播详情页,其他拉起客服
606
- this.toDetails()
607
- }
608
- }, 1000, true),
609
- getUserPermission() {
610
- return new Promise((resolve, reject) => {
611
- let params = {
612
- id: this.data.goodsItem.id,
613
- app_id: this.data.aliveInfo.app_id,
614
- user_id: this.data.aliveInfo.user_id,
615
- }
616
- const url = this.properties.isGrayMarketing ? getUserPermissionNew : getUserPermission
617
- url(params).then((res) => {
618
- let { code, data } = res.data
619
- if (code === 0) {
620
- resolve(!!data.auth_state)
621
- }
622
- })
623
- })
624
- },
625
- async showConfirmOrder(sku) {
626
- //带货列表返回的 resource_id就是业务侧的spu_id
627
- // 返回的id,就是业务侧的resource_id
628
- const params = {
629
- id: this.data.goodsItem.resource_id,
630
- spu_id: this.data.goodsItem.resource_id,
631
- resource_type: this.data.goodsItem.resource_type,
632
- resource_id: this.data.goodsItem.id,
633
- spu_type: this.data.goodsItem.spu_type,
634
- sku,
635
- count: 1,
636
- isAlive: 1,
637
- aliveId: this.data.aliveInfo.alive_id,
638
- isCollectCoupons: this.data.showPreferentialPrice
639
- }
640
-
641
- this.triggerEvent("showConfirmOrder", params)
642
- },
643
- showSku() {
644
- let params = {
645
- spuId: this.data.goodsItem.resource_id,
646
- isCollectCoupons: this.data.showPreferentialPrice
647
- }
648
- this.triggerEvent("showSku", params)
649
- },
650
- showdialog() {
651
- this.triggerEvent('showDialog', this.data.goodsItem)
652
- },
653
- sendNewMsg() {
654
- this.triggerEvent('sendNewMsg')
655
- },
656
- showToast(title = '') {
657
- wx.showToast({
658
- title,
659
- icon: "none",
660
- duration: 1000
661
- })
662
- },
663
- hideToast() {
664
- wx.hideToast()
665
- },
666
- countTime() {
667
- if (!this.data.isSeckill || !this.data.preheating) { //不是秒杀活动 或者不在预热中不倒计时
668
- return
669
- }
670
- //获取当前时间
671
- let date = new Date();
672
- let now = date.getTime();
673
- //截止时间
674
- let deadline = new Date(this.data.startTime);
675
- let end = deadline.getTime();
676
- //剩余时间
677
- let time = end - now;
678
- //定义变量 d,h,m,s保存倒计时的时间
679
- let d = 0, h = 0, m = 0, s = 0;
680
- if (time >= 0) {
681
- d = Math.floor(time / 1000 / 60 / 60 / 24);
682
- h = Math.floor(time / 1000 / 60 / 60 % 24);
683
- m = Math.floor(time / 1000 / 60 % 60);
684
- s = Math.floor(time / 1000 % 60);
685
- h = d > 0 ? h + 24 * d : h
686
- h = h < 10 ? '0' + h : h
687
- m = m < 10 ? '0' + m : m
688
- s = s < 10 ? '0' + s : s
689
- this.setData({
690
- time: h + ":" + m + ":" + s
691
- })
692
- }
693
- //递归每秒调用countTime方法,显示动态时间效果
694
- let that = this
695
- if (!(d === 0 && h === 0 && m === 0 && s === 0)) { //秒杀活动还未到时间
696
- setTimeout(() => that.countTime(), 1000)
697
- }
698
- },
699
- handleContact(e) {
700
- console.log("点击了去查看")
701
- },
702
- formatUrl(goodsInfo) {
703
- var url = ''
704
- var jumpUrl = ''
705
- if (typeof goodsInfo == 'object' && Object.keys(goodsInfo).length > 0) {
706
- url = goodsInfo.target_url
707
- jumpUrl = goodsInfo.target_url
708
- } else {
709
- url = this.data.goodsItem.target_url
710
- jumpUrl = this.data.goodsItem.target_url //跳转链接
711
- }
712
- //跳转链接 带上参数
713
- let queryIndex = url.indexOf("?"); //查询索引位置
714
- if (queryIndex === -1) {
715
- jumpUrl += "?"; //问号不存在,则拼接问号
716
- } else {
717
- url.length - 1 !== queryIndex ? (jumpUrl += "&") : ""; //问号是否不在末尾位置? 进行&拼接 :不处理
718
- }
719
- jumpUrl = `${jumpUrl}live_room=1&success=1&aliveId=${this.data.aliveInfo.alive_id}`;
720
- if (![0, 2, 3].includes(this.data.aliveInfo.alive_state)) {
721
- jumpUrl += `&is_living=1&unique_type=elive`;
722
- }
723
- return encodeURIComponent(jumpUrl)
724
- },
725
- toDetails() {
726
- // 直播商品-去详情页,其他商品-拉起客服
727
- let { title, img_url, target_url } = this.data.goodsItem
728
- let params = encodeURIComponent(`img_url=${img_url}&title=${title}&params_url=${this.data.params_url}`)
729
- console.log("urlurlurl", `/page/customerService/customerService?params=${params}`)
730
- if (this.data.goodsItem.resource_type === 4) {
731
- wx && wx.redirectTo({
732
- url: `/pages/webView/webView?appId=${this.properties.aliveInfo.app_id}&aliveId=${this.data.goodsItem.id}&refreshAliveId=${this.properties.aliveInfo.alive_id}`,
733
- })
734
-
735
- } else {
736
- // PC 复制链接
737
- const { isPC, isDevtools } = getApp().globalData.system
738
- if (isPC || isDevtools) {
739
- this.copyLink(target_url)
740
- return
741
- }
742
- // 暂时屏蔽内嵌H5详情页,拉起客服
743
- wx && wx.navigateTo({
744
- url: '/page/customerService/customerService' + `?params=${params}`
745
- })
746
- }
747
- },
748
- //judgePermission里面 showDialog 外部弹窗调用
749
- toMiniProgram(goodsInfo) {
750
- let { aliveInfo, sensorReportParams } = this.properties
751
- sensorLog.sensors.track('click_butt', {
752
- page_id: 'e_alive#mini#first#alive_room',
753
- page_name: '直播间页面',
754
- l_program: '鹅直播',
755
- page_path: '鹅直播#小程序#首页#直播间页面',
756
- page_button: "前往",
757
- app_id: aliveInfo.app_id,
758
- c_user_id: aliveInfo.user_id,
759
- union_id: wx.getStorageSync('userInfo').universal_union_id,
760
- current_role: sensorReportParams.current_role,
761
- resource_id: aliveInfo.alive_id,
762
- $url_path: `alive/${aliveInfo.alive_id}`,
763
- type: sensorReportParams.type,
764
- cmm1: sensorReportParams.alive_type,
765
- cmm2: sensorReportParams.version_type,
766
- comm2: sensorReportParams.pay_type
767
- })
768
- let spu_type = goodsInfo.spu_type
769
- switch (spu_type) {
770
- case ASSOCIATION:
771
- this.toAssociation(goodsInfo);
772
- break;
773
- case PUNCH_CARD:
774
- this.toPunchCard(goodsInfo);
775
- break;
776
- default:
777
- this.toXiaoeLearn(goodsInfo);
778
- break;
779
- }
780
- },
781
- toXiaoeLearn(goodsInfo) {
782
- let { aliveInfo } = this.properties
783
- let h5_url = this.formatUrl(goodsInfo)
784
- var path
785
- // 音频 视频
786
- if (goodsInfo.resource_type === 2 || goodsInfo.resource_type === 3) {
787
- path = `/pages/index/authorizePage?user_id=${aliveInfo.user_id}&app_id=${aliveInfo.app_id}&resource_id=${goodsInfo.id}&unique_type=elive`
788
- } else {
789
- // 其他
790
- path = `/pages/index/authorizePage?user_id=${aliveInfo.user_id}&app_id=${aliveInfo.app_id}&h5_url=${h5_url}`
791
- }
792
- let params = {
793
- appId: "wxa3589f1193170aa3",
794
- path,
795
- }
796
- if (this.properties.envName == 'inside' || this.properties.envName == 'test') { //开发环境 测试环境 加上这个参数可以跳转去鹅学习体验版
797
- params.appId = 'wx9eb4d7b3f2a3e003'
798
- params.envVersion = 'trial'
799
- }
800
- wx.navigateToMiniProgram(params)
801
- },
802
- toPunchCard(goodsInfo) {
803
- let { aliveInfo } = this.properties
804
- let path = `/pages-participate-progress/pages/participate/participate?app_id=${aliveInfo.app_id}&&activity_id=${goodsInfo.resource_id}`
805
- let params = {
806
- appId: "wx839728854b1e23ad", //现网
807
- path,
808
- }
809
- if (this.properties.envName == 'inside') { //开发环境
810
- params.appId = 'wx802f346b1c7dcdd9'
811
- } else if (this.properties.envName == 'test') { // 测试环境
812
- params.appId = 'wx778bc88236be97d9'
813
- }
814
- wx.navigateToMiniProgram(params)
815
- },
816
- toAssociation(goodsInfo) {
817
- let { aliveInfo } = this.properties
818
- let path = `/pages-community/pages/home/index?appId=${aliveInfo.app_id}&&communityId=${goodsInfo.resource_id}`
819
- let params = {
820
- appId: "wxd0ad7e76d51ae4cc",
821
- path,
822
- }
823
- if (this.properties.envName == 'inside') {
824
- params.appId = 'wx52419e90dc6dd535' //开发环境
825
- } else if (this.properties.envName == 'test') { //测试环境
826
- params.appId = 'wxb245d452213c48c9' //测试环境
827
- }
828
- wx.navigateToMiniProgram(params)
829
- },
830
- // 商品设置售罄/取消售罄
831
- async changeSoldOut() {
832
- if (this.data.changeStateLoading) return this.showToast('状态更改中,请稍后');
833
-
834
- const confirmPromise = () => new Promise(resolve => {
835
- wx.showModal({
836
- title: '确认售罄?',
837
- content: '标记售罄后不影响实际库存,仅在用户端展示商品已抢光,无法购买',
838
- confirmText: '确认',
839
- cancelText: '取消',
840
- confirmColor: '#1472FF',
841
- success: (res) => {
842
- if (res.confirm) {
843
- return resolve(true);
844
- } else if (res.cancel) {
845
- return resolve(false);
846
- }
847
- },
848
- fail: () => resolve(false),
849
- });
850
- });
851
-
852
- const isConfirmOperation = this.data.isSoldOut || await confirmPromise();
853
-
854
- if (!isConfirmOperation) return;
855
-
856
- const { alive_id, app_id, user_id } = this.properties.aliveInfo;
857
- const {
858
- goodsItem,
859
- isSoldOut,
860
- } = this.data;
861
- const params = {
862
- alive_id,
863
- app_id,
864
- resource_id: goodsItem.id,
865
- is_sell_out: isSoldOut ? 0 : 1, // 该商品是否售罄 1-已售罄 0-未售罄
866
- user_id,
867
- token: wx.getStorageSync('login_data').token,
868
- };
869
-
870
- this.setData({
871
- changeStateLoading: true,
872
- });
873
-
874
- const res = await setGoodsSellOut(params, false).catch(error => ({ data: { code: -1, msg: error?.message || error || '操作失败' } }));
875
-
876
- this.setData({
877
- changeStateLoading: false,
878
- });
879
-
880
- const { data: { code, msg } } = res;
881
-
882
- if (code !== 0) {
883
- return this.showToast(msg);
884
- }
885
-
886
- // 更新售罄状态
887
- this.triggerEvent('changeGoodsState', {
888
- index: this.properties.index,
889
- type: 'is_sell_out',
890
- state: params.is_sell_out,
891
- });
892
- this.showToast('操作成功');
893
- },
894
- // 商品设置显示/隐藏
895
- async changeVisible() {
896
- if (this.data.changeStateLoading) return this.showToast('状态更改中,请稍后');
897
-
898
- // 确认隐藏商品弹窗
899
- const confirmPromise = () => new Promise(resolve => {
900
- wx.showModal({
901
- title: '确认隐藏吗',
902
- content: '用户端商品列表不展示已隐藏商品,讲师仍可通过讲解发送商品',
903
- confirmText: '确认',
904
- cancelText: '取消',
905
- confirmColor: '#1472FF',
906
- success: (res) => {
907
- if (res.confirm) {
908
- return resolve(true);
909
- } else if (res.cancel) {
910
- return resolve(false);
911
- }
912
- },
913
- fail: () => resolve(false),
914
- });
915
- });
916
-
917
- // 已隐藏的商品可以直接调用接口显示,已显示的需要弹窗提示
918
- const isConfirmOperation = !this.data.goodsItem.is_display_package || await confirmPromise();
919
-
920
- if (!isConfirmOperation) return;
921
-
922
- // 确认隐藏/显示,格式化参数、调用接口处理
923
- const { alive_id, app_id } = this.properties.aliveInfo;
924
- const { id, true_type, is_display_package } = this.data.goodsItem;
925
- const params = {
926
- alive_id,
927
- app_id,
928
- resource_ids: [{ id, type: true_type }],
929
- is_display_package: +is_display_package ? 0 : 1,
930
- token: wx.getStorageSync('login_data').token,
931
- };
932
-
933
- this.setData({
934
- changeStateLoading: true,
935
- });
936
-
937
- const res = await requestChangeShow(params, false).catch(error => ({ data: { code: -1, msg: error?.message || error || '操作失败' } }));
938
-
939
- this.setData({
940
- changeStateLoading: false,
941
- });
942
-
943
- const { data: { code, msg } } = res;
944
-
945
- if (code !== 0) {
946
- return this.showToast(msg);
947
- }
948
-
949
- // 更新商品显示、隐藏状态
950
- this.triggerEvent('changeGoodsState', {
951
- index: this.properties.index,
952
- type: 'is_display_package',
953
- state: params.is_display_package,
954
- });
955
- this.showToast('操作成功');
956
- },
957
- sendGoodsCard(e) {
958
- let dataset = e.currentTarget.dataset;
959
- // 触发父组件的send
960
- this.triggerEvent('sendGoodsCard', {
961
- datas: dataset
962
- });
963
- },
964
- changeShowType() {
965
- if (this.data.goodsItem.teacher_auth != 2) {
966
- this.showToast('暂无权限')
967
- return
968
- }
969
- this.setData({
970
- switchLoading: true
971
- })
972
- let params = {
973
- alive_id: this.properties.aliveInfo.alive_id,
974
- app_id: this.properties.aliveInfo.app_id,
975
- resource_id: this.data.goodsItem.id,
976
- is_display_package: this.data.checked ? 0 : 1
977
- };
978
- showGoods(params).then((res) => {
979
- let { code } = res.data
980
- if (code === 0) {
981
- this.setData({
982
- switchLoading: false,
983
- checked: !this.data.checked
984
- })
985
- this.showToast('操作成功')
986
- } else {
987
- this.setData({
988
- switchLoading: false
989
- })
990
- }
991
- })
992
- },
993
- stopEvent() {
994
- return
995
- },
996
- copyLink(link) {
997
- wx.setClipboardData({
998
- data: link,
999
- success() {
1000
- wx.showToast({
1001
- title: '商品链接已复制,请用浏览器打开',
1002
- icon: 'none',
1003
- })
1004
- },
1005
- })
1006
- }
1007
- }
1008
- })
1
+ /*
2
+ * @Descripttion:
3
+ * @version:
4
+ * @Author: conlinchen
5
+ * @Date: 2021-10-28 18:17:48
6
+ * @LastEditors: conlinchen
7
+ * @LastEditTime: 2021-11-18 19:49:11
8
+ */
9
+ import { debounce, rpxToVmin } from "../common/utils/index"
10
+ import {
11
+ getUserPermission,
12
+ getUserPermissionNew,
13
+ snapCheck,
14
+ snapCheckNew,
15
+ showGoods,
16
+ requestChangeShow,
17
+ setGoodsSellOut,
18
+ getGoodValue
19
+ } from "../common/api/liveGoodsList"
20
+ import {
21
+ ASSOCIATION,
22
+ PUNCH_CARD
23
+ } from "../common/utils/constants.js";
24
+
25
+ const { utils, sensorLog } = require("live-mp-tools");
26
+
27
+ const computedBehavior = require('miniprogram-computed').behavior
28
+
29
+ const formatNum = (num) => {
30
+ if (!num || isNaN(num)) return num
31
+
32
+ num = Number(num)
33
+ const isDecimals = (num) => {
34
+ num = num.toString()
35
+ if(num.split('.')[1] != '00'){
36
+ return true
37
+ }else{
38
+ return false
39
+ }
40
+ }
41
+
42
+ if (Math.abs(num) >= 100000000) {
43
+ num = num / 100000000
44
+ return isDecimals(Math.floor(num * 100) / 100) ? Math.floor(num * 100) / 100 + '亿' : num + '亿'
45
+ } else if (Math.abs(num) >= 10000) {
46
+ num = num / 10000
47
+ return isDecimals(Math.floor(num * 100) / 100) ? Math.floor(num * 100) / 100 + '万' : num + '万'
48
+ } else {
49
+ return num
50
+ }
51
+ }
52
+
53
+ Component({
54
+ behaviors: [computedBehavior],
55
+ options: {
56
+ addGlobalClass: true,
57
+ },
58
+ /**
59
+ * 组件的属性列表
60
+ */
61
+ properties: {
62
+ goodsInfo: {
63
+ type: Object,
64
+ value: {},
65
+ observer(newVal) {
66
+ // 商品没有的话,不处理
67
+ if (!newVal.id) return
68
+ //超级会员全免权益
69
+ let svipAllFree = newVal.resource_rights_type === 1
70
+ let currentActive = ''
71
+ if (svipAllFree) {
72
+ currentActive = '超级会员'
73
+ } else {
74
+ currentActive = newVal.currentActive
75
+ }
76
+ //IOS小程序端 ios小程序商品列表 直播、线下课、班课、实物商品可买,其他知识商品不可买,需不显示价格 点击去抢购后按现网逻辑跳转至小程序的商品详情
77
+ let info = wx.getSystemInfoSync()
78
+ let IOSMiniProgramCanBuy = [4, 29, 35, 21, 69].indexOf(newVal.resource_type) > -1 //true-能买 false-不能买
79
+ let isIOS = info.platform === 'ios'
80
+ console.log("platform", info.platform, isIOS)
81
+ const pages = getCurrentPages();
82
+ const currentPage = pages[pages.length - 1];
83
+ const url = `/${currentPage.route}`;
84
+ //预热开始时间
85
+ let startTime = newVal.start_at && new Date(newVal.start_at.replace(/-/g, "/")) || new Date()
86
+ let time = startTime.getTime() - newVal.sec_kill_preheat_time * 1000
87
+ let preHeatTime = new Date(time) || new Date()
88
+
89
+ let hasPreheat = newVal.sec_kill_is_preheat === 1
90
+
91
+ let startTime2 = newVal.start_at && new Date(newVal.start_at.replace(/-/g, "/")) || new Date()
92
+ let nowTime = new Date().getTime()
93
+ let preheating = hasPreheat && nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
94
+ let isSeckill = currentActive === '秒杀'
95
+ let checked = newVal.is_display_package === 1
96
+
97
+
98
+ this.setData({
99
+ goodsItem: newVal,
100
+ currentActive,
101
+ IOSMiniProgramCanBuy,
102
+ isIOS,
103
+ page_path: url,
104
+ preHeatTime,
105
+ preheating,
106
+ isSeckill,
107
+ checked
108
+ }, () => {
109
+ const isSoldOut = +newVal.is_sell_out === 1;
110
+ const isRealOver = newVal.stock === 0 ||
111
+ (newVal.is_activity &&
112
+ (newVal.activity_type === 8 || newVal.activity_type === 3) &&
113
+ newVal.activity_stock - newVal.activity_order_num === 0);
114
+ const isOver = isSoldOut || isRealOver;
115
+
116
+ this.setData({
117
+ isOver,
118
+ isSoldOut,
119
+ isRealOver,
120
+ })
121
+ this.countTime()
122
+ })
123
+ }
124
+ },
125
+ sending: {
126
+ type: Boolean,
127
+ value: false
128
+ },
129
+ explainingGoods: {
130
+ type: Object,
131
+ value: {}
132
+ },
133
+ isInElive: {
134
+ type: Boolean,
135
+ value: false
136
+ },
137
+ aliveInfo: {
138
+ type: Object,
139
+ value: {},
140
+ },
141
+ // 是否去客服内支付
142
+ allContactPay: {
143
+ type: Boolean,
144
+ value: false
145
+ },
146
+ //店铺设置是否展示券后价
147
+ coupon_switch: {
148
+ type: Boolean,
149
+ value: false
150
+ },
151
+ envName: {
152
+ type: String,
153
+ value: ""
154
+ },
155
+ sensorReportParams: {
156
+ type: Object,
157
+ value: {}
158
+ },
159
+ current_role: {
160
+ type: String,
161
+ value: 'student'
162
+ },
163
+ isFullScreen: {
164
+ type: Boolean,
165
+ value: false
166
+ },
167
+ style: {
168
+ type: String,
169
+ value: ''
170
+ },
171
+ index: {
172
+ type: Number,
173
+ value: -1
174
+ },
175
+ // 是否是新带货接口灰度
176
+ isGrayMarketing: {
177
+ type: Boolean,
178
+ value: false
179
+ },
180
+ isManage: {
181
+ type: Boolean,
182
+ value: false
183
+ },
184
+ visibleSwitchStatusBtn: {
185
+ type: Boolean,
186
+ value: false
187
+ },
188
+ sendingGoodId: {
189
+ type: String,
190
+ value: '',
191
+ },
192
+ // 是否展示库存
193
+ stockSwitch: {
194
+ type: Number,
195
+ value: 0
196
+ }
197
+ },
198
+
199
+ lifetimes: {
200
+ // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
201
+ attached: function () {
202
+
203
+ },
204
+ moved: function () { },
205
+ detached: function () { },
206
+ },
207
+
208
+ /**
209
+ * 组件的初始数据
210
+ */
211
+ data: {
212
+ time: '',
213
+ goodsItem: {},
214
+ currentActive: '',
215
+ IOSMiniProgramCanBuy: false,
216
+ isIOS: false,
217
+ page_path: '',
218
+ preHeatTime: '',
219
+ isSeckill: false,
220
+ checked: false,
221
+ switchLoading: false,
222
+ imageRadius: rpxToVmin(16),
223
+ isOver: false, //是否已抢光
224
+ isSoldOut: false, //商品是否设置已售罄
225
+ isRealOver: false, //商品是否为非手动售罄下的,真实抢光
226
+ changeStateLoading: false, // 修改状态 loading(如售罄状态、显示状态)
227
+ skillNowTime: 0 // 秒杀活动对比的当前时间
228
+ },
229
+ computed: {
230
+ // 是否显示库存
231
+ showStock(data) {
232
+ const { current_role, goodsInfo, stockSwitch, skillNowTime } = data
233
+ // 只涉及实物商品,线下课,班课,有价优惠券,课时包,服务类商品
234
+ if (![21, 29, 35, 41, 42, 68].includes(goodsInfo.resource_type)) return false
235
+ // 讲师必定展示
236
+ if (current_role === 'teacher') return true
237
+ // 学员的话,参与营销活动有活动库存,并且开始了,就不展示了
238
+ const activityTime = new Date(goodsInfo.start_at?.replace(/-/g, "/")).getTime() || 0
239
+ const nowTime = skillNowTime || new Date().getTime()
240
+ if (+goodsInfo.is_activity === 1 && (nowTime > activityTime) && goodsInfo.activity_stock) return false
241
+ // 学员其余情况下,根据b端显示库存开关
242
+ return stockSwitch === 1
243
+ },
244
+ goodsStock(data) {
245
+ const { current_role, goodsInfo, skillNowTime } = data
246
+ // 讲师显示原库存
247
+ if (current_role === 'teacher') return formatNum(goodsInfo.stock)
248
+ // 售罄了
249
+ if (+goodsInfo.is_sell_out === 1) return 0
250
+ // 原库存为0
251
+ if (+goodsInfo.stock === 0) return 0
252
+ // 如果参与了营销活动开始后且有活动呢库存, 展示活动库存
253
+ const activityTime = new Date(goodsInfo.start_at?.replace(/-/g, "/")).getTime() || 0
254
+ const nowTime = skillNowTime || new Date().getTime()
255
+ if (+goodsInfo.is_activity === 1 && (nowTime > activityTime)) {
256
+ return goodsInfo.activity_stock ? formatNum(goodsInfo.activity_stock - goodsInfo.activity_order_num) : formatNum(goodsInfo.stock)
257
+ }
258
+ return formatNum(goodsInfo.stock)
259
+ },
260
+ showPreferentialPrice(properties) {
261
+ // 券后价小于展示价格的时候展示券后价; coupon_switch B端店铺设置 是否展示券后价,err_code === 0 是正常,非0表示券后价相关接口报错了,去抢购按钮展示为查看详情
262
+ //超级会员全免权益
263
+ let svipAllFree = properties.goodsInfo.resource_rights_type === 1
264
+ //免费的情况下不展示券后价
265
+ let isFree = svipAllFree || properties.goodsInfo.priceShow === 0
266
+ let showPreferentialPrice = properties.coupon_switch && properties.goodsInfo.preferential_price < properties.goodsInfo.priceShow && !properties.goodsInfo.err_code && !isFree
267
+ return showPreferentialPrice
268
+ },
269
+ params_url(data) {
270
+ if (!Object.keys(data.goodsItem).length) {
271
+ return ''
272
+ } else {
273
+ // 后端规则拼接参数规则:$ => ?、@ => &
274
+ // 商品带货链接需拼接多一个aliveId
275
+ const aliveId = data.aliveInfo.alive_id
276
+ const url = data.goodsItem.target_url.replaceAll('&', "@")
277
+ const link = url.replaceAll('?', "$")
278
+ // 判断后端返回链接是否已拼接(如:?type= )参数,兼容 aliveId 拼接符
279
+ const symbol = url.indexOf('?') !== -1 ? '@' : '$'
280
+ return `${data.page_path}?type=1&link=${link}${symbol}aliveId=${aliveId}&title=${data.goodsItem.title}`
281
+ }
282
+ },
283
+ isStudent(properties) {
284
+ return properties.current_role === 'student'
285
+ },
286
+ //超过99999不够位置展示划线价,只能不要孩子了
287
+ showPriceLine(data) {
288
+ return data.goodsItem.priceLine > 0 && (data.goodsItem.priceShow < 100000 || !data.showPreferentialPrice)
289
+ },
290
+ showPrice(data) {
291
+ return data.isIOS && data.IOSMiniProgramCanBuy && data.goodsItem.priceShow !== 0 || !data.isIOS && data.goodsItem.priceShow !== 0
292
+ },
293
+ // 是否为安卓设备
294
+ isAndroid() {
295
+ let info = wx.getSystemInfoSync()
296
+ return info.platform === 'android'
297
+ },
298
+ //讲解中的商品
299
+ isShowExamplaining(properties) {
300
+ return properties.explainingGoods && properties.explainingGoods.resource_id === properties.goodsItem.resource_id;
301
+ },
302
+ //销量/订阅。只有 实物商品 21 、专栏 6、大专栏 8、会员 5 展示,受B端店铺设置(hide_sub_count):隐藏商品销量控制 0-显示 1-隐藏
303
+ hasSaleNum(data) {
304
+ return !data.goodsItem.hide_sub_count && data.goodsItem.order_num > 0
305
+ },
306
+ //销量/订阅。只有 实物商品 21 、专栏 6、大专栏 8、会员 5 展示
307
+ saleNum(data) {
308
+ //实物商品
309
+ if (data.goodsItem.resource_type === 21 || data.goodsItem.resource_type === 41 || data.goodsItem.resource_type === 68) {
310
+ return ' 已售 ' + (data.goodsItem.order_num || 0)
311
+ } else if (data.goodsItem.resource_type === 6 || data.goodsItem.resource_type === 8 || data.goodsItem.resource_type === 5) {
312
+ return ' 订阅 ' + (data.goodsItem.order_num || 0)
313
+ } else {
314
+ return ''
315
+ }
316
+ },
317
+ // 点击去查看
318
+ isNeedToContact(data) {
319
+ return Boolean(data.allContactPay || (data.isIOS && !data.IOSMiniProgramCanBuy))
320
+ },
321
+ btnTxt(data) {
322
+ // 以下各种情况,按去查看 -> 已抢光 -> 查看详情 -> 免费领取 -> 券后 -> 去抢购 优先级展示
323
+ // 超级会员全免权益
324
+ let svipAllFree = data.goodsItem.resource_rights_type === 1
325
+ if (data.isSoldOut && !data.isStudent) {
326
+ return "已售罄"
327
+ } else if (data.isOver) {
328
+ // 库存为0,已售罄
329
+ return "已抢光"
330
+ } else if (data.allContactPay || (data.isIOS && !data.IOSMiniProgramCanBuy)) {
331
+ // IOS小程序中不能买的展示去查看,跳转到小程序客服
332
+ return "去查看"
333
+ } else if (data.goodsItem.err_code) {
334
+ // 券后价接口报错,领取不了优惠券的情况
335
+ return "查看详情"
336
+ } else if (svipAllFree || data.goodsItem.priceShow === 0) {
337
+ // 超级会员全免或者0元商品
338
+ return "免费领取"
339
+ } else if (data.showPreferentialPrice) {
340
+ // 展示券后价
341
+ return "购买"
342
+ } else {
343
+ return "购买"
344
+ }
345
+ },
346
+ //当前适用的活动或者超级会员,活动价低就是活动,会员价低就是超级会员,超级会员全免,肯定最低,适用超级会员
347
+ // "限时折扣",
348
+ // "好友助力",
349
+ // "裂变海报",
350
+ // "拼团",
351
+ // "涨粉神器",
352
+ // "秒杀",
353
+ // "超级会员",
354
+ //是否开启了预热 1-开启 0-未开启
355
+ hasPreheat(data) {
356
+ return data.goodsItem.sec_kill_is_preheat === 1
357
+ },
358
+ //秒杀开始时间
359
+ startTime(data) {
360
+ return data.goodsItem.start_at && new Date(data.goodsItem.start_at.replace(/-/g, "/")) || new Date()
361
+ },
362
+ //超级会员
363
+ isSupperVip(data) {
364
+ return data.currentActive === '超级会员'
365
+ },
366
+ //秒杀活动需要预约
367
+ isAppointment(data) {
368
+ data.goodsItem.appointment = 1 //mock
369
+ return data.goodsItem.appointment === 1
370
+ },
371
+ secText(data) {
372
+ if (data.isSeckill && data.preheating) {
373
+ return `秒杀活动将在 ${data.time} 后开始`
374
+ } else {
375
+ return ''
376
+ }
377
+ },
378
+ filterSrc(data) {
379
+ return utils.replaceCDN(data.goodsItem.img_url, '?imageMogr2/thumbnail/400x400>/ignore-error/1')
380
+ },
381
+ // 是否展示已抢完
382
+ // 学员端:已设置售罄、或者已抢完
383
+ // 讲师端:已抢完,且未设置已售罄
384
+ isSellOut({ isStudent, isOver, isRealOver }) {
385
+ return isStudent ? isOver : isRealOver;
386
+ },
387
+ // 已售百分比
388
+ percentage(data) {
389
+ if (data.isSellOut) return 100
390
+ // 无库存 拼团、限时抢购
391
+ if (!data.goodsItem.activity_stock) return 28
392
+ let num = 0
393
+ num = (data.goodsItem.activity_order_num / data.goodsItem.activity_stock) * 100
394
+ // 有库存时,最低占40%
395
+ return num <= 40 ? 40 : num
396
+ },
397
+ // 商品剩余数量
398
+ residueQuantity(data) {
399
+ // "已抢光"
400
+ if (data.isSellOut) return '已抢光'
401
+
402
+ // 没有库存 - 已开抢
403
+ if (!data.goodsItem.activity_stock) return '已开抢'
404
+
405
+ return `仅剩${formatNum(data.goodsItem.activity_stock - data.goodsItem.activity_order_num)}件`
406
+ },
407
+ // 配送方式(-1:全部 1:快递配送 2:自提)
408
+ distributionWay(data) {
409
+ let text = ''
410
+ switch (data.goodsItem.distribution_pattern) {
411
+ case -1:
412
+ text = '自提·快递'
413
+ break
414
+ case 1:
415
+ text = '快递'
416
+ break
417
+ case 2:
418
+ text = '自提'
419
+ break
420
+ default:
421
+ text = ''
422
+ break
423
+ }
424
+ return text
425
+ },
426
+ distributionPattern(data) {
427
+ return [-1,1,2].indexOf(data.goodsItem.distribution_pattern) !== -1
428
+ }
429
+ },
430
+ /**
431
+ * 组件的方法列表
432
+ */
433
+ methods: {
434
+ async checkSellOut() {
435
+ // 非真实抢光,需要拿最新状态判断下
436
+ if (this.data.isRealOver) return;
437
+
438
+ if (this.data.isNeedToContact) {
439
+ const goodsStatusRes = await this.getGoodsStatus()
440
+
441
+ if (!goodsStatusRes) return
442
+
443
+ // 更新售罄状态
444
+ const is_sell_out = +goodsStatusRes.is_sell_out
445
+ this.triggerEvent('changeGoodsState', {
446
+ index: this.properties.index,
447
+ type: 'is_sell_out',
448
+ state: is_sell_out,
449
+ });
450
+
451
+ if (is_sell_out) {
452
+ return wx.showToast({
453
+ title: '很遗憾, 手慢抢光了',
454
+ icon: 'none',
455
+ duration: 3000,
456
+ })
457
+ }
458
+
459
+ this.toDetails()
460
+ } else {
461
+ this.snapUpCheck()
462
+ }
463
+ },
464
+ snapUpCheck: debounce(async function () {
465
+ !this.data.isOver && this.showToast('努力加载中')
466
+
467
+ const goodsStatusRes = await this.getGoodsStatus()
468
+
469
+ if (!goodsStatusRes) return
470
+
471
+ // 更新售罄状态
472
+ const is_sell_out = +goodsStatusRes.is_sell_out
473
+ this.triggerEvent('changeGoodsState', {
474
+ index: this.properties.index,
475
+ type: 'is_sell_out',
476
+ state: is_sell_out,
477
+ });
478
+
479
+ if (is_sell_out) {
480
+ return wx.showToast({
481
+ title: '很遗憾, 手慢抢光了',
482
+ icon: 'none',
483
+ duration: 3000,
484
+ })
485
+ }
486
+
487
+ this.triggerEvent('sendNewMsg')
488
+ let { aliveInfo, sensorReportParams, goodsInfo, isFullScreen } = this.properties
489
+ sensorLog.sensors.track('click_butt', {
490
+ page_id: 'e_alive#mini#first#alive_room',
491
+ page_name: '直播间页面',
492
+ l_program: '鹅直播',
493
+ page_path: '鹅直播#小程序#首页#直播间页面',
494
+ page_button: "列表去抢购",
495
+ client: "小程序",
496
+ goods_id: goodsInfo.id,
497
+ app_id: aliveInfo.app_id,
498
+ c_user_id: aliveInfo.user_id,
499
+ union_id: wx.getStorageSync('userInfo').universal_union_id,
500
+ current_role: sensorReportParams.current_role,
501
+ resource_id: aliveInfo.alive_id,
502
+ $url_path: `alive/${aliveInfo.alive_id}`,
503
+ type: sensorReportParams.type,
504
+ cmm1: sensorReportParams.alive_type,
505
+ cmm2: sensorReportParams.version_type,
506
+ comm2: sensorReportParams.pay_type,
507
+ cmm3: isFullScreen ? '全屏' : '非全屏'
508
+ })
509
+ // 线下课29课时包42/拼团 --判断权益
510
+ if ([29, 42].indexOf(this.data.goodsItem.resource_type) > -1 || this.data.goodsItem.activity_type === 6) {
511
+ this.judgePermission()
512
+ return
513
+ }
514
+ let params = {
515
+ id: this.data.goodsItem.id,
516
+ resource_id: this.data.goodsItem.resource_id,
517
+ resource_type: this.data.goodsItem.resource_type,
518
+ price: this.data.goodsItem.price,
519
+ app_id: this.data.aliveInfo.app_id,
520
+ user_id: this.data.aliveInfo.user_id,
521
+ coupon_id: this.data.goodsItem.coupon_id,
522
+ alive_id: this.data.aliveInfo.alive_id
523
+ }
524
+ const url = this.properties.isGrayMarketing ? snapCheckNew : snapCheck
525
+ url(params).then(res => {
526
+ this.hideToast()
527
+ let { code, data } = res.data
528
+ if (code === 0) {
529
+ if (data.err_msg) {
530
+ this.showToast(data.err_msg)
531
+ }
532
+ if (data.is_sec_kill_toast) {
533
+ this.showToast("秒杀活动开始,您未预约,需以原价购买!")
534
+ }
535
+ if (data.is_goods_detail === 1) {
536
+ this.judgePermission(data.is_has_permission)
537
+ } else if (data.is_more_sku === 1) {
538
+ this.showSku()
539
+ } else {
540
+ this.showConfirmOrder(data.sku)
541
+ }
542
+ } else {
543
+ this.showToast("网络繁忙,请稍后再试")
544
+ }
545
+ })
546
+ }, 1000, true),
547
+ getGoodsStatus() {
548
+ if (this.data.isRealOver) {
549
+ wx.showToast({
550
+ title: '很遗憾, 手慢抢光了',
551
+ icon: 'none',
552
+ duration: 3000,
553
+ })
554
+
555
+ return Promise.resolve(null)
556
+ }
557
+
558
+ const { id, spu_id, resource_id } = this.data.goodsItem
559
+ const { user_id, app_id, alive_id } = this.properties.aliveInfo
560
+
561
+ return getGoodValue({
562
+ spu_id: spu_id || id,
563
+ user_id,
564
+ app_id,
565
+ alive_id,
566
+ resource_id: id || resource_id,
567
+ }, true)
568
+ .then((res) => {
569
+ res = res.data || {}
570
+
571
+ if (res.code === 0 && res.data) {
572
+ return res.data
573
+ } else {
574
+ this.showToast(res?.msg || res?.data?.msg || '获取商品状态失败')
575
+ return null
576
+ }
577
+ })
578
+ .catch(() => {
579
+ this.showToast('获取商品状态失败')
580
+ return null
581
+ })
582
+ },
583
+ cardToDetails() {
584
+ if (!this.data.isStudent) { return }
585
+ let { aliveInfo, sensorReportParams, goodsInfo, isFullScreen } = this.properties
586
+ sensorLog.sensors.track('click_butt', {
587
+ page_id: 'e_alive#mini#first#alive_room',
588
+ page_name: '直播间页面',
589
+ l_program: '鹅直播',
590
+ page_path: '鹅直播#小程序#首页#直播间页面',
591
+ page_button: "列表空白热区",
592
+ client: "小程序",
593
+ goods_id: goodsInfo.id,
594
+ product_name: goodsInfo.title,
595
+ app_id: aliveInfo.app_id,
596
+ c_user_id: aliveInfo.user_id,
597
+ union_id: wx.getStorageSync('userInfo').universal_union_id,
598
+ current_role: sensorReportParams.current_role,
599
+ resource_id: aliveInfo.alive_id,
600
+ $url_path: `alive/${aliveInfo.alive_id}`,
601
+ type: sensorReportParams.type,
602
+ cmm1: sensorReportParams.alive_type,
603
+ cmm2: sensorReportParams.version_type,
604
+ comm2: sensorReportParams.pay_type,
605
+ cmm3: isFullScreen ? '全屏' : '非全屏'
606
+ })
607
+ this.judgePermission()
608
+ },
609
+ // 点击空白热区进来判断权益,或者接口返回有权益的时候进来判断跳转路径
610
+ judgePermission: debounce(async function (permission) {
611
+ const goodsStatusRes = await this.getGoodsStatus()
612
+
613
+ if (!goodsStatusRes) return
614
+
615
+ // 更新售罄状态
616
+ const is_sell_out = +goodsStatusRes.is_sell_out
617
+ this.triggerEvent('changeGoodsState', {
618
+ index: this.properties.index,
619
+ type: 'is_sell_out',
620
+ state: is_sell_out,
621
+ });
622
+
623
+ if (is_sell_out) {
624
+ return wx.showToast({
625
+ title: '很遗憾, 手慢抢光了',
626
+ icon: 'none',
627
+ duration: 3000,
628
+ })
629
+ }
630
+
631
+ // 实物21 有价优惠券41 超级会员23 可多次购买,没有权益说法,直接拉起客服;直播商品有没有权益都是去详情页。
632
+ if ([41, 21, 23, 4].indexOf(Number(this.data.goodsItem.resource_type)) > -1) {
633
+ this.toDetails()
634
+ return
635
+ }
636
+
637
+ if (permission !== 0 && permission !== 1) {
638
+ permission = await this.getUserPermission()
639
+ }
640
+
641
+ // 有权益的情况下
642
+ if (permission) {
643
+ // 电子书20/班课35 鹅学习不支持,无权益的情况下,内嵌h5, 有权益TOAST提示
644
+ if ([20, 35].indexOf(this.data.goodsItem.resource_type) > -1) {
645
+ this.showToast('您已拥有该课程,小程序内暂不支持学习此课程')
646
+ } else {
647
+ // 弹出提示去小程序学习 有三种可能 -圈子小程序 -小鹅通小程序 -打卡小程序
648
+ this.showdialog(this.data.goodsItem)
649
+ }
650
+ } else {
651
+ // 没有权益的情况下 直播商品去直播详情页,其他拉起客服
652
+ this.toDetails()
653
+ }
654
+ }, 1000, true),
655
+ getUserPermission() {
656
+ return new Promise((resolve, reject) => {
657
+ let params = {
658
+ id: this.data.goodsItem.id,
659
+ app_id: this.data.aliveInfo.app_id,
660
+ user_id: this.data.aliveInfo.user_id,
661
+ }
662
+ const url = this.properties.isGrayMarketing ? getUserPermissionNew : getUserPermission
663
+ url(params).then((res) => {
664
+ let { code, data } = res.data
665
+ if (code === 0) {
666
+ resolve(!!data.auth_state)
667
+ }
668
+ })
669
+ })
670
+ },
671
+ async showConfirmOrder(sku) {
672
+ //带货列表返回的 resource_id就是业务侧的spu_id
673
+ // 返回的id,就是业务侧的resource_id
674
+ const params = {
675
+ id: this.data.goodsItem.resource_id,
676
+ spu_id: this.data.goodsItem.resource_id,
677
+ resource_type: this.data.goodsItem.resource_type,
678
+ resource_id: this.data.goodsItem.id,
679
+ spu_type: this.data.goodsItem.spu_type,
680
+ sku,
681
+ count: 1,
682
+ isAlive: 1,
683
+ aliveId: this.data.aliveInfo.alive_id,
684
+ isCollectCoupons: this.data.showPreferentialPrice
685
+ }
686
+
687
+ this.triggerEvent("showConfirmOrder", params)
688
+ },
689
+ showSku() {
690
+ let params = {
691
+ spuId: this.data.goodsItem.resource_id,
692
+ isCollectCoupons: this.data.showPreferentialPrice
693
+ }
694
+ this.triggerEvent("showSku", params)
695
+ },
696
+ showdialog() {
697
+ this.triggerEvent('showDialog', this.data.goodsItem)
698
+ },
699
+ sendNewMsg() {
700
+ this.triggerEvent('sendNewMsg')
701
+ },
702
+ showToast(title = '') {
703
+ wx.showToast({
704
+ title,
705
+ icon: "none",
706
+ duration: 1000
707
+ })
708
+ },
709
+ hideToast() {
710
+ wx.hideToast()
711
+ },
712
+ countTime() {
713
+ if (!this.data.isSeckill || !this.data.preheating) { //不是秒杀活动 或者不在预热中不倒计时
714
+ return
715
+ }
716
+ //获取当前时间
717
+ let date = new Date();
718
+ let now = date.getTime();
719
+ //截止时间
720
+ let deadline = new Date(this.data.startTime);
721
+ let end = deadline.getTime();
722
+ //剩余时间
723
+ let time = end - now;
724
+ this.setData({ skillNowTime: now })
725
+ //定义变量 d,h,m,s保存倒计时的时间
726
+ let d = 0, h = 0, m = 0, s = 0;
727
+ if (time >= 0) {
728
+ d = Math.floor(time / 1000 / 60 / 60 / 24);
729
+ h = Math.floor(time / 1000 / 60 / 60 % 24);
730
+ m = Math.floor(time / 1000 / 60 % 60);
731
+ s = Math.floor(time / 1000 % 60);
732
+ h = d > 0 ? h + 24 * d : h
733
+ h = h < 10 ? '0' + h : h
734
+ m = m < 10 ? '0' + m : m
735
+ s = s < 10 ? '0' + s : s
736
+ this.setData({
737
+ time: h + ":" + m + ":" + s
738
+ })
739
+ }
740
+ //递归每秒调用countTime方法,显示动态时间效果
741
+ let that = this
742
+ if (!(d === 0 && h === 0 && m === 0 && s === 0)) { //秒杀活动还未到时间
743
+ setTimeout(() => that.countTime(), 1000)
744
+ } else {
745
+ this.setData({ skillNowTime: 0 })
746
+ }
747
+ },
748
+ handleContact(e) {
749
+ console.log("点击了去查看")
750
+ },
751
+ formatUrl(goodsInfo) {
752
+ var url = ''
753
+ var jumpUrl = ''
754
+ if (typeof goodsInfo == 'object' && Object.keys(goodsInfo).length > 0) {
755
+ url = goodsInfo.target_url
756
+ jumpUrl = goodsInfo.target_url
757
+ } else {
758
+ url = this.data.goodsItem.target_url
759
+ jumpUrl = this.data.goodsItem.target_url //跳转链接
760
+ }
761
+ //跳转链接 带上参数
762
+ let queryIndex = url.indexOf("?"); //查询索引位置
763
+ if (queryIndex === -1) {
764
+ jumpUrl += "?"; //问号不存在,则拼接问号
765
+ } else {
766
+ url.length - 1 !== queryIndex ? (jumpUrl += "&") : ""; //问号是否不在末尾位置? 进行&拼接 :不处理
767
+ }
768
+ jumpUrl = `${jumpUrl}live_room=1&success=1&aliveId=${this.data.aliveInfo.alive_id}`;
769
+ if (![0, 2, 3].includes(this.data.aliveInfo.alive_state)) {
770
+ jumpUrl += `&is_living=1&unique_type=elive`;
771
+ }
772
+ return encodeURIComponent(jumpUrl)
773
+ },
774
+ toDetails() {
775
+ // 直播商品-去详情页,其他商品-拉起客服
776
+ let { title, img_url, target_url } = this.data.goodsItem
777
+ let params = encodeURIComponent(`img_url=${img_url}&title=${title}&params_url=${this.data.params_url}`)
778
+ console.log("urlurlurl", `/page/customerService/customerService?params=${params}`)
779
+ if (this.data.goodsItem.resource_type === 4) {
780
+ wx && wx.redirectTo({
781
+ url: `/pages/webView/webView?appId=${this.properties.aliveInfo.app_id}&aliveId=${this.data.goodsItem.id}&refreshAliveId=${this.properties.aliveInfo.alive_id}`,
782
+ })
783
+
784
+ } else {
785
+ // PC 复制链接
786
+ const { isPC, isDevtools } = getApp().globalData.system
787
+ if (isPC || isDevtools) {
788
+ this.copyLink(target_url)
789
+ return
790
+ }
791
+ // 暂时屏蔽内嵌H5详情页,拉起客服
792
+ wx && wx.navigateTo({
793
+ url: '/page/customerService/customerService' + `?params=${params}`
794
+ })
795
+ }
796
+ },
797
+ //judgePermission里面 showDialog 外部弹窗调用
798
+ toMiniProgram(goodsInfo) {
799
+ let { aliveInfo, sensorReportParams } = this.properties
800
+ sensorLog.sensors.track('click_butt', {
801
+ page_id: 'e_alive#mini#first#alive_room',
802
+ page_name: '直播间页面',
803
+ l_program: '鹅直播',
804
+ page_path: '鹅直播#小程序#首页#直播间页面',
805
+ page_button: "前往",
806
+ app_id: aliveInfo.app_id,
807
+ c_user_id: aliveInfo.user_id,
808
+ union_id: wx.getStorageSync('userInfo').universal_union_id,
809
+ current_role: sensorReportParams.current_role,
810
+ resource_id: aliveInfo.alive_id,
811
+ $url_path: `alive/${aliveInfo.alive_id}`,
812
+ type: sensorReportParams.type,
813
+ cmm1: sensorReportParams.alive_type,
814
+ cmm2: sensorReportParams.version_type,
815
+ comm2: sensorReportParams.pay_type
816
+ })
817
+ let spu_type = goodsInfo.spu_type
818
+ switch (spu_type) {
819
+ case ASSOCIATION:
820
+ this.toAssociation(goodsInfo);
821
+ break;
822
+ case PUNCH_CARD:
823
+ this.toPunchCard(goodsInfo);
824
+ break;
825
+ default:
826
+ this.toXiaoeLearn(goodsInfo);
827
+ break;
828
+ }
829
+ },
830
+ toXiaoeLearn(goodsInfo) {
831
+ let { aliveInfo } = this.properties
832
+ let h5_url = this.formatUrl(goodsInfo)
833
+ var path
834
+ // 音频 视频
835
+ if (goodsInfo.resource_type === 2 || goodsInfo.resource_type === 3) {
836
+ path = `/pages/index/authorizePage?user_id=${aliveInfo.user_id}&app_id=${aliveInfo.app_id}&resource_id=${goodsInfo.id}&unique_type=elive`
837
+ } else {
838
+ // 其他
839
+ path = `/pages/index/authorizePage?user_id=${aliveInfo.user_id}&app_id=${aliveInfo.app_id}&h5_url=${h5_url}`
840
+ }
841
+ let params = {
842
+ appId: "wxa3589f1193170aa3",
843
+ path,
844
+ }
845
+ if (this.properties.envName == 'inside' || this.properties.envName == 'test') { //开发环境 测试环境 加上这个参数可以跳转去鹅学习体验版
846
+ params.appId = 'wx9eb4d7b3f2a3e003'
847
+ params.envVersion = 'trial'
848
+ }
849
+ wx.navigateToMiniProgram(params)
850
+ },
851
+ toPunchCard(goodsInfo) {
852
+ let { aliveInfo } = this.properties
853
+ let path = `/pages-participate-progress/pages/participate/participate?app_id=${aliveInfo.app_id}&&activity_id=${goodsInfo.resource_id}`
854
+ let params = {
855
+ appId: "wx839728854b1e23ad", //现网
856
+ path,
857
+ }
858
+ if (this.properties.envName == 'inside') { //开发环境
859
+ params.appId = 'wx802f346b1c7dcdd9'
860
+ } else if (this.properties.envName == 'test') { // 测试环境
861
+ params.appId = 'wx778bc88236be97d9'
862
+ }
863
+ wx.navigateToMiniProgram(params)
864
+ },
865
+ toAssociation(goodsInfo) {
866
+ let { aliveInfo } = this.properties
867
+ let path = `/pages-community/pages/home/index?appId=${aliveInfo.app_id}&&communityId=${goodsInfo.resource_id}`
868
+ let params = {
869
+ appId: "wxd0ad7e76d51ae4cc",
870
+ path,
871
+ }
872
+ if (this.properties.envName == 'inside') {
873
+ params.appId = 'wx52419e90dc6dd535' //开发环境
874
+ } else if (this.properties.envName == 'test') { //测试环境
875
+ params.appId = 'wxb245d452213c48c9' //测试环境
876
+ }
877
+ wx.navigateToMiniProgram(params)
878
+ },
879
+ // 商品设置售罄/取消售罄
880
+ async changeSoldOut() {
881
+ if (this.data.changeStateLoading) return this.showToast('状态更改中,请稍后');
882
+
883
+ const confirmPromise = () => new Promise(resolve => {
884
+ wx.showModal({
885
+ title: '确认售罄?',
886
+ content: '标记售罄后不影响实际库存,仅在用户端展示商品已抢光,无法购买',
887
+ confirmText: '确认',
888
+ cancelText: '取消',
889
+ confirmColor: '#1472FF',
890
+ success: (res) => {
891
+ if (res.confirm) {
892
+ return resolve(true);
893
+ } else if (res.cancel) {
894
+ return resolve(false);
895
+ }
896
+ },
897
+ fail: () => resolve(false),
898
+ });
899
+ });
900
+
901
+ const isConfirmOperation = this.data.isSoldOut || await confirmPromise();
902
+
903
+ if (!isConfirmOperation) return;
904
+
905
+ const { alive_id, app_id, user_id } = this.properties.aliveInfo;
906
+ const {
907
+ goodsItem,
908
+ isSoldOut,
909
+ } = this.data;
910
+ const params = {
911
+ alive_id,
912
+ app_id,
913
+ resource_id: goodsItem.id,
914
+ is_sell_out: isSoldOut ? 0 : 1, // 该商品是否售罄 1-已售罄 0-未售罄
915
+ user_id,
916
+ token: wx.getStorageSync('login_data').token,
917
+ };
918
+
919
+ this.setData({
920
+ changeStateLoading: true,
921
+ });
922
+
923
+ const res = await setGoodsSellOut(params, false).catch(error => ({ data: { code: -1, msg: error?.message || error || '操作失败' } }));
924
+
925
+ this.setData({
926
+ changeStateLoading: false,
927
+ });
928
+
929
+ const { data: { code, msg } } = res;
930
+
931
+ if (code !== 0) {
932
+ return this.showToast(msg);
933
+ }
934
+
935
+ // 更新售罄状态
936
+ this.triggerEvent('changeGoodsState', {
937
+ index: this.properties.index,
938
+ type: 'is_sell_out',
939
+ state: params.is_sell_out,
940
+ });
941
+ this.showToast('操作成功');
942
+ },
943
+ // 商品设置显示/隐藏
944
+ async changeVisible() {
945
+ if (this.data.changeStateLoading) return this.showToast('状态更改中,请稍后');
946
+
947
+ // 确认隐藏商品弹窗
948
+ const confirmPromise = () => new Promise(resolve => {
949
+ wx.showModal({
950
+ title: '确认隐藏吗',
951
+ content: '用户端商品列表不展示已隐藏商品,讲师仍可通过讲解发送商品',
952
+ confirmText: '确认',
953
+ cancelText: '取消',
954
+ confirmColor: '#1472FF',
955
+ success: (res) => {
956
+ if (res.confirm) {
957
+ return resolve(true);
958
+ } else if (res.cancel) {
959
+ return resolve(false);
960
+ }
961
+ },
962
+ fail: () => resolve(false),
963
+ });
964
+ });
965
+
966
+ // 已隐藏的商品可以直接调用接口显示,已显示的需要弹窗提示
967
+ const isConfirmOperation = !this.data.goodsItem.is_display_package || await confirmPromise();
968
+
969
+ if (!isConfirmOperation) return;
970
+
971
+ // 确认隐藏/显示,格式化参数、调用接口处理
972
+ const { alive_id, app_id } = this.properties.aliveInfo;
973
+ const { id, true_type, is_display_package } = this.data.goodsItem;
974
+ const params = {
975
+ alive_id,
976
+ app_id,
977
+ resource_ids: [{ id, type: true_type }],
978
+ is_display_package: +is_display_package ? 0 : 1,
979
+ token: wx.getStorageSync('login_data').token,
980
+ };
981
+
982
+ this.setData({
983
+ changeStateLoading: true,
984
+ });
985
+
986
+ const res = await requestChangeShow(params, false).catch(error => ({ data: { code: -1, msg: error?.message || error || '操作失败' } }));
987
+
988
+ this.setData({
989
+ changeStateLoading: false,
990
+ });
991
+
992
+ const { data: { code, msg } } = res;
993
+
994
+ if (code !== 0) {
995
+ return this.showToast(msg);
996
+ }
997
+
998
+ // 更新商品显示、隐藏状态
999
+ this.triggerEvent('changeGoodsState', {
1000
+ index: this.properties.index,
1001
+ type: 'is_display_package',
1002
+ state: params.is_display_package,
1003
+ });
1004
+ this.showToast('操作成功');
1005
+ },
1006
+ sendGoodsCard(e) {
1007
+ let dataset = e.currentTarget.dataset;
1008
+ // 触发父组件的send
1009
+ this.triggerEvent('sendGoodsCard', {
1010
+ datas: dataset
1011
+ });
1012
+ },
1013
+ changeShowType() {
1014
+ if (this.data.goodsItem.teacher_auth != 2) {
1015
+ this.showToast('暂无权限')
1016
+ return
1017
+ }
1018
+ this.setData({
1019
+ switchLoading: true
1020
+ })
1021
+ let params = {
1022
+ alive_id: this.properties.aliveInfo.alive_id,
1023
+ app_id: this.properties.aliveInfo.app_id,
1024
+ resource_id: this.data.goodsItem.id,
1025
+ is_display_package: this.data.checked ? 0 : 1
1026
+ };
1027
+ showGoods(params).then((res) => {
1028
+ let { code } = res.data
1029
+ if (code === 0) {
1030
+ this.setData({
1031
+ switchLoading: false,
1032
+ checked: !this.data.checked
1033
+ })
1034
+ this.showToast('操作成功')
1035
+ } else {
1036
+ this.setData({
1037
+ switchLoading: false
1038
+ })
1039
+ }
1040
+ })
1041
+ },
1042
+ stopEvent() {
1043
+ return
1044
+ },
1045
+ copyLink(link) {
1046
+ wx.setClipboardData({
1047
+ data: link,
1048
+ success() {
1049
+ wx.showToast({
1050
+ title: '商品链接已复制,请用浏览器打开',
1051
+ icon: 'none',
1052
+ })
1053
+ },
1054
+ })
1055
+ }
1056
+ }
1057
+ })