xiaoe_mp_npm 0.5.42-test2 → 0.5.42-test21

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 (123) hide show
  1. package/miniprogram_dist/ConfirmOrder/components/ConfirmOrderContent/index.scss +45 -0
  2. package/miniprogram_dist/ConfirmOrder/components/ConfirmOrderContent/index.wxss +37 -1
  3. package/miniprogram_dist/ConfirmOrder/components/GoodsInfo/index.scss +223 -0
  4. package/miniprogram_dist/ConfirmOrder/components/GoodsInfo/index.wxss +522 -36
  5. package/miniprogram_dist/ConfirmOrder/components/IntegralSelect/index.scss +91 -0
  6. package/miniprogram_dist/ConfirmOrder/components/IntegralSelect/index.wxss +170 -14
  7. package/miniprogram_dist/ConfirmOrder/components/Invoice/index.scss +61 -0
  8. package/miniprogram_dist/ConfirmOrder/components/Invoice/index.wxss +68 -2
  9. package/miniprogram_dist/ConfirmOrder/components/LeaveWord/index.scss +40 -0
  10. package/miniprogram_dist/ConfirmOrder/components/LeaveWord/index.wxss +26 -2
  11. package/miniprogram_dist/ConfirmOrder/components/PayBar/index.scss +62 -0
  12. package/miniprogram_dist/ConfirmOrder/components/PayBar/index.wxss +81 -3
  13. package/miniprogram_dist/ConfirmOrder/components/PayDetail/index.scss +41 -0
  14. package/miniprogram_dist/ConfirmOrder/components/PayDetail/index.wxss +35 -3
  15. package/miniprogram_dist/CouponList/components/CouponItem/index.css +1715 -1715
  16. package/miniprogram_dist/CouponList/components/CouponItem/index.js +31 -22
  17. package/miniprogram_dist/CouponList/components/CouponItem/index.min.css +1 -1
  18. package/miniprogram_dist/CouponList/components/CouponItem/index.wxml +6 -2
  19. package/miniprogram_dist/CouponList/components/CouponItem/index.wxss +1037 -79
  20. package/miniprogram_dist/CouponList/couponColumn/index.js +5 -1
  21. package/miniprogram_dist/CouponList/couponColumn/index.scss +118 -0
  22. package/miniprogram_dist/CouponList/couponColumn/index.wxml +1 -0
  23. package/miniprogram_dist/CouponList/couponColumn/index.wxss +221 -32
  24. package/miniprogram_dist/CouponReceivePopup/index.js +75 -0
  25. package/miniprogram_dist/CouponReceivePopup/index.json +6 -0
  26. package/miniprogram_dist/CouponReceivePopup/index.scss +99 -0
  27. package/miniprogram_dist/CouponReceivePopup/index.wxml +85 -0
  28. package/miniprogram_dist/CouponReceivePopup/index.wxss +75 -0
  29. package/miniprogram_dist/GoodsItem/index.js +7 -5
  30. package/miniprogram_dist/GoodsItem/index.scss +45 -22
  31. package/miniprogram_dist/GoodsItem/index.wxml +11 -11
  32. package/miniprogram_dist/GoodsItem/index.wxs +18 -18
  33. package/miniprogram_dist/GoodsItem/index.wxss +1273 -116
  34. package/miniprogram_dist/GoodsRecommend/index.scss +162 -0
  35. package/miniprogram_dist/GoodsRecommend/index.wxss +418 -33
  36. package/miniprogram_dist/LiveGoodsList/Header/index.scss +79 -0
  37. package/miniprogram_dist/LiveGoodsList/Header/index.wxss +148 -10
  38. package/miniprogram_dist/LiveGoodsList/index.js +167 -25
  39. package/miniprogram_dist/LiveGoodsList/index.scss +93 -0
  40. package/miniprogram_dist/LiveGoodsList/index.wxml +41 -19
  41. package/miniprogram_dist/LiveGoodsList/index.wxss +187 -19
  42. package/miniprogram_dist/PayModule/button/index.scss +45 -0
  43. package/miniprogram_dist/PayModule/button/index.wxss +46 -4
  44. package/miniprogram_dist/TeacherGoodsList/index.js +778 -585
  45. package/miniprogram_dist/TeacherGoodsList/index.scss +5 -2
  46. package/miniprogram_dist/TeacherGoodsList/index.wxml +42 -24
  47. package/miniprogram_dist/TeacherGoodsList/index.wxss +132 -14
  48. package/miniprogram_dist/common/api/liveGoodsList.js +10 -2
  49. package/miniprogram_dist/common/utils/index.js +14 -0
  50. package/miniprogram_dist/coupon/components/CouponItem/index.less +1 -0
  51. package/miniprogram_dist/coupon/components/CouponItem/index.scss +247 -0
  52. package/miniprogram_dist/coupon/components/CouponItem/index.wxss +677 -86
  53. package/miniprogram_dist/coupon/components/CouponSelect/index.scss +331 -0
  54. package/miniprogram_dist/coupon/components/CouponSelect/index.wxss +861 -59
  55. package/miniprogram_dist/coupon/index.scss +83 -0
  56. package/miniprogram_dist/coupon/index.wxss +171 -15
  57. package/package.json +2 -2
  58. package/src/ConfirmOrder/components/ConfirmOrderContent/index.scss +45 -0
  59. package/src/ConfirmOrder/components/ConfirmOrderContent/index.wxss +42 -1
  60. package/src/ConfirmOrder/components/GoodsInfo/index.scss +223 -0
  61. package/src/ConfirmOrder/components/GoodsInfo/index.wxss +552 -39
  62. package/src/ConfirmOrder/components/IntegralSelect/index.scss +91 -0
  63. package/src/ConfirmOrder/components/IntegralSelect/index.wxss +182 -14
  64. package/src/ConfirmOrder/components/Invoice/index.scss +61 -0
  65. package/src/ConfirmOrder/components/Invoice/index.wxss +75 -2
  66. package/src/ConfirmOrder/components/LeaveWord/index.scss +40 -0
  67. package/src/ConfirmOrder/components/LeaveWord/index.wxss +30 -2
  68. package/src/ConfirmOrder/components/PayBar/index.scss +62 -0
  69. package/src/ConfirmOrder/components/PayBar/index.wxss +87 -3
  70. package/src/ConfirmOrder/components/PayDetail/index.scss +41 -0
  71. package/src/ConfirmOrder/components/PayDetail/index.wxss +39 -3
  72. package/src/CouponList/components/CouponItem/index.css +1715 -1715
  73. package/src/CouponList/components/CouponItem/index.js +31 -22
  74. package/src/CouponList/components/CouponItem/index.min.css +1 -1
  75. package/src/CouponList/components/CouponItem/index.wxml +6 -2
  76. package/src/CouponList/components/CouponItem/index.wxss +1039 -85
  77. package/src/CouponList/couponColumn/index.js +5 -1
  78. package/src/CouponList/couponColumn/index.scss +118 -0
  79. package/src/CouponList/couponColumn/index.wxml +1 -0
  80. package/src/CouponList/couponColumn/index.wxss +236 -32
  81. package/src/CouponReceivePopup/index.js +75 -0
  82. package/src/CouponReceivePopup/index.json +6 -0
  83. package/src/CouponReceivePopup/index.scss +99 -0
  84. package/src/CouponReceivePopup/index.wxml +85 -0
  85. package/src/CouponReceivePopup/index.wxss +1 -0
  86. package/src/GoodsItem/index.js +7 -5
  87. package/src/GoodsItem/index.scss +45 -22
  88. package/src/GoodsItem/index.wxml +11 -11
  89. package/src/GoodsItem/index.wxs +18 -18
  90. package/src/GoodsItem/index.wxss +1331 -116
  91. package/src/GoodsRecommend/index.scss +162 -0
  92. package/src/GoodsRecommend/index.wxss +441 -33
  93. package/src/LiveGoodsList/Header/index.scss +79 -0
  94. package/src/LiveGoodsList/Header/index.wxss +156 -10
  95. package/src/LiveGoodsList/index.js +167 -25
  96. package/src/LiveGoodsList/index.scss +93 -0
  97. package/src/LiveGoodsList/index.wxml +41 -19
  98. package/src/LiveGoodsList/index.wxss +230 -50
  99. package/src/PayModule/button/index.scss +45 -0
  100. package/src/PayModule/button/index.wxss +50 -4
  101. package/src/TeacherGoodsList/index.js +778 -585
  102. package/src/TeacherGoodsList/index.scss +5 -2
  103. package/src/TeacherGoodsList/index.wxml +42 -24
  104. package/src/TeacherGoodsList/index.wxss +151 -14
  105. package/src/common/api/liveGoodsList.js +10 -2
  106. package/src/common/utils/index.js +14 -0
  107. package/src/coupon/components/CouponItem/index.less +1 -0
  108. package/src/coupon/components/CouponItem/index.scss +247 -0
  109. package/src/coupon/components/CouponItem/index.wxss +712 -86
  110. package/src/coupon/components/CouponSelect/index.scss +331 -0
  111. package/src/coupon/components/CouponSelect/index.wxss +910 -59
  112. package/src/coupon/index.scss +83 -0
  113. package/src/coupon/index.wxss +181 -15
  114. package/miniprogram_dist/GoodsItem/index.css +0 -1364
  115. package/miniprogram_dist/GoodsItem/index.less +0 -299
  116. package/miniprogram_dist/GoodsItem/index.min.css +0 -1
  117. package/miniprogram_dist/TeacherGoodsList/index.css +0 -187
  118. package/miniprogram_dist/TeacherGoodsList/index.min.css +0 -1
  119. package/src/GoodsItem/index.css +0 -1364
  120. package/src/GoodsItem/index.less +0 -299
  121. package/src/GoodsItem/index.min.css +0 -1
  122. package/src/TeacherGoodsList/index.css +0 -187
  123. package/src/TeacherGoodsList/index.min.css +0 -1
@@ -1,585 +1,778 @@
1
- /*
2
- * @Descripttion:
3
- * @version:
4
- * @Author: conlinchen
5
- * @Date: 2021-10-28 15:32:24
6
- * @LastEditors: conlinchen
7
- * @LastEditTime: 2021-11-18 19:52:02
8
- */
9
-
10
- import { getGoodsList } from "../common/api/liveGoodsList"
11
- const computedBehavior = require('miniprogram-computed').behavior
12
-
13
- let activityCountdownTimer = null // 活动倒计时计时器
14
- let hadActivity = false
15
- let activityList = [] // 参与活动的商品
16
-
17
- // 预热模块
18
- let preheatTimer = null // 预热倒计时计时器
19
- let hadPreheat = false
20
- let preheatList = [] // 参与活动的商品
21
-
22
- let hasActivity = false // 是否有参与活动的商品
23
- let hasPreheat = false // 是否有参与预热的商品
24
-
25
- const SPU_TYPE = {
26
- 1: "图文",
27
- 2: "音频",
28
- 3: "视频",
29
- 4: "直播",
30
- 35: "班课",
31
- 20: "电子书",
32
- 6: "专栏",
33
- 8: "大专栏",
34
- 5: "会员",
35
- 25: "训练营",
36
- 21: "实物商品",
37
- 29: "线下课", //体验课也是29
38
- 22: "分销商品",
39
- 12: "分销商品", //暂时不做
40
- 41: "有价优惠券",
41
- 45: "AI互动课",
42
- 23: "超级会员"
43
- }
44
- const MARKET_ACTIVITY_MAP = {
45
- 3: "限时折扣",
46
- 4: "好友助力",
47
- 5: "裂变海报",
48
- 6: "拼团",
49
- 7: "涨粉神器",
50
- 8: "秒杀",
51
- }
52
-
53
- Component({
54
- behaviors: [computedBehavior],
55
- properties: {
56
- sensorReportParams: {
57
- type: Object,
58
- value: {}
59
- },
60
- aliveInfo: {
61
- type: Object,
62
- value: {
63
- alive_id: 'l_61c2a4dae4b0ad9a9d6887dc',
64
- alive_state: 2
65
- },
66
- },
67
- ENV_NAME: {
68
- type: String,
69
- value: ""
70
- },
71
- showList: {
72
- type: Boolean,
73
- value: false,
74
- observer(newVal) {
75
- this.setData({
76
- refreshing: newVal
77
- })
78
- console.log(newVal)
79
-
80
- newVal && this.onLoad()
81
- }
82
- },
83
- changState: {
84
- type: Object,
85
- value: {}
86
- },
87
- aliveConf: { //is_takegoods: 是否开启直播带货,0-关闭 1-开启
88
- type: Object,
89
- value: {}
90
- },
91
- isFullScreen: {
92
- type: Boolean,
93
- value: false,
94
- },
95
- // im实时同步的带货消息
96
- msgGoodsData: {
97
- type: Object,
98
- value: {},
99
- observer(newVal) {
100
- newVal.switch && this.handlerListInfo(newVal)
101
- },
102
- },
103
- isManage: {
104
- type: Boolean,
105
- value: false,
106
- }
107
- },
108
- data: {
109
- goodsInfo: [],
110
- page_size: 5,
111
- page_index: 1,
112
- total: 0,
113
- refreshing: false,
114
- finishedTxt: '加载中',
115
- finished: false,
116
- sendingIndex: -1,
117
- sending: false,
118
- selectList: [], // 多选列表
119
- is_jurisdiction: false, // 操作权限
120
- },
121
- lifetimes: {
122
- // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
123
- attached: function () {
124
-
125
- },
126
- moved: function () { },
127
- detached: function () { },
128
- },
129
- methods: {
130
- // "sync_goods":{
131
- // "switch":0,//开关:0关1开
132
- // //带货配置列表-最多六条
133
- // "conf_list":[],
134
- // "update_list":[],
135
- // //移除资源id
136
- // "batch_del":["p_63845d8be4b07b05581ebf47"],
137
- // //批量显示隐藏
138
- // "batch_switch":[]
139
- // }
140
- /**
141
- * 带货/优惠券实时同步
142
- * @param {object} msgData im消息体
143
- * @param {string} type 消息类型:带货goods、优惠券coupon
144
- */
145
- handlerListInfo(msgData) {
146
- let type = '',
147
- marketInfo = []
148
- // jer todo 还有im接受的相关逻辑需要补充
149
- // 遍历获取操作类型
150
- for (let key in msgData) {
151
- switch (key) {
152
- // 新增操作
153
- case 'conf_list':
154
- type = 'goodsConfList'
155
- marketInfo = msgData[key]
156
- break
157
- // 修改操作
158
- case 'update_list':
159
- type = 'goodsUpdateList'
160
- marketInfo = msgData[key]
161
- break
162
- // 删除操作
163
- case 'batch_del':
164
- type = 'goodsDelList'
165
- marketInfo = msgData[key]
166
- break
167
- // jer todo 可能字段需要更改
168
- // 显隐操作
169
- case 'batch_switch':
170
- type = 'goodsBatchSwitchList'
171
- marketInfo = msgData[key]
172
- break
173
- default:
174
- break
175
- }
176
- console.log('jer=========', type, marketInfo)
177
- if (marketInfo?.length > 0) {
178
- this.changeGoodsList(type, marketInfo)
179
- type = ''
180
- marketInfo = []
181
- }
182
- }
183
- },
184
- // 处理实时同步的带货逻辑
185
- changeGoodsList(type, marketInfo) {
186
- let goodsInfo = this.data.goodsInfo,
187
- delIndex = -1 // 删除数据的当前下标
188
- // jer todo 添加批量显隐的数组
189
- // selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏id数组
190
- // selectGoods = this.data.selectGoods // 批量隐藏数据数组
191
- switch (type) {
192
- case 'goodsConfList':
193
- // 如果已经加载完了,可以拼接数据
194
- if (this.data.finished) this.formatData(marketInfo);
195
- // 管理商品需要增加
196
- // jer todo 添加批量显隐的总数逻辑
197
- // this.data.marketResource.courseList[0].total += marketInfo.length
198
- break
199
- case 'goodsUpdateList':
200
- case 'goodsBatchSwitchList':
201
- marketInfo.map((item) => {
202
- for (let index = 0; index < goodsInfo.length; index++) {
203
- if (item.id === goodsInfo[index].id) {
204
- // 遍历插入相应的修改值
205
- for (let key in item) {
206
- goodsInfo[index][key] = item[key]
207
- }
208
- break
209
- }
210
- }
211
- })
212
- break
213
- case 'goodsDelList':
214
- marketInfo.map((id) => {
215
- for (let index = 0; index < goodsInfo.length; index++) {
216
- if (id === goodsInfo[index].id) {
217
- // 删除操作,获取下标
218
- goodsInfo.splice(index, 1)
219
- delIndex = index
220
- index--
221
- }
222
- // 删除后,后面的数据都要权重+1显示
223
- if (delIndex > -1 && index >= delIndex) {
224
- goodsInfo[index].order_weight--
225
- }
226
- }
227
- // 重置删除下标
228
- delIndex = -1
229
-
230
- // jer todo 此处处理批量显隐的,删掉了,需要把选择的也删掉
231
- // if (selectGoodsIndexArr.length > 0) {
232
- // for (let index = 0; index < selectGoodsIndexArr.length; index++) {
233
- // if (id === selectGoodsIndexArr[index]) {
234
- // // 删除操作,获取下标
235
- // selectGoodsIndexArr.splice(index, 1)
236
- // selectGoods.splice(index, 1)
237
- // index--
238
- // }
239
- // }
240
- // }
241
- })
242
- // jer todo 管理商品需要减少
243
- // this.data.marketResource.courseList[0].total -= marketInfo.length
244
- break
245
- default:
246
- break
247
- }
248
- this.setData({
249
- goodsInfo,
250
- // selectGoodsIndexArr,
251
- // selectGoods,
252
- })
253
- },
254
- // 管理商品多选
255
- onChange(e){
256
- this.setData({
257
- selectList:e.detail
258
- })
259
- },
260
-
261
- // 显示隐藏
262
- changeShowType(){},
263
-
264
- // 商品总活动倒计时
265
- startActivityCountdown(list) {
266
-
267
- clearInterval(activityCountdownTimer)
268
- activityCountdownTimer = setInterval(() => {
269
- hadActivity = false
270
- list.forEach((i) => {
271
- let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
272
- if (targetDate <= 0) return
273
- hadActivity = true
274
- let temp = `goodsInfo[${i.index}].activityCountdown`
275
- this.setData({
276
- [temp]: targetDate,
277
- })
278
- })
279
- if (!hadActivity) {
280
- clearInterval(activityCountdownTimer)
281
- activityCountdownTimer = null
282
- }
283
- }, 1000)
284
- },
285
- // 预热倒计时
286
- startPreheatCountdown(list) {
287
- clearInterval(preheatTimer)
288
- preheatTimer = setInterval(() => {
289
- hadPreheat = false
290
- list.forEach((i) => {
291
- let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
292
- if (targetDate <= 0) {
293
- activityList.push({
294
- time: this.data.goodsInfo[i.index].end_at,
295
- index: i.index,
296
- })
297
- this.setData({
298
- [`goodsInfo[${i.index}].preheatTime`]: 0,
299
- })
300
- return
301
- }
302
- hadPreheat = true
303
- let temp = `goodsInfo[${i.index}].preheatTime`
304
- this.setData({
305
- [temp]: targetDate,
306
- })
307
- })
308
- if (!hadPreheat) {
309
- clearInterval(preheatTimer)
310
- preheatTimer = null
311
- }
312
- }, 1000)
313
- },
314
- onLoad() {
315
- if (!this.data.aliveConf.is_takegoods) {
316
- this.setData({
317
- refreshing: false
318
- })
319
- return
320
- }
321
- if (this._freshing) return
322
- this._freshing = true
323
- this.setData({
324
- finished: false,
325
- page_index: 1
326
- })
327
- this.getGoodsList()
328
- },
329
- onScrolltolower() {
330
- if (this.scrolling || this.data.finishedTxt === 'no-data' || !this.data.aliveConf.is_takegoods) { return }
331
- this.scrolling = true
332
- this.setData({
333
- finishedTxt: this.data.finished ? "没有更多了" : "加载中"
334
- })
335
- if (this.data.finished || this._freshing) {
336
- return
337
- }
338
- this.getGoodsList()
339
- },
340
- getGoodsList() {
341
- let params = {
342
- alive_id: this.data.aliveInfo.alive_id,
343
- type: 1,
344
- page_size: this.data.page_size,
345
- page: this.data.page_index,
346
- port: 2
347
- }
348
- getGoodsList(params).then(res => {
349
- let { data, code } = res.data
350
- if (code === 0) {
351
- var total = data[0] ? data[0].total : this.data.total
352
- var finishedTxt = "加载中"
353
- var finished = false
354
- let is_jurisdiction = data[0] ? data[0].teacher_auth == 2 : false
355
-
356
- if (this._freshing) {
357
- //下拉加载直接赋值
358
- this.formatData(data, true)
359
- } else {
360
- this.formatData(data)
361
- }
362
- // 下拉加载,且数据返回空
363
- if (this._freshing && data.length === 0) {
364
- finishedTxt = "no-data"
365
- } else if (this.data.goodsInfo.length >= total || data.length === 0) {
366
- // 获取到所有数据
367
- finished = true// 没有更多了
368
- finishedTxt = "没有更多了"
369
- this.setData({ finishedTxt })
370
- } else {
371
- finishedTxt = "加载中"
372
- }
373
- this.setData({
374
- refreshing: false,
375
- page_index: this.data.page_index + 1,
376
- finishedTxt,
377
- finished,
378
- total,
379
- is_jurisdiction
380
- })
381
- this._freshing = false
382
- this.scrolling = false
383
- }
384
- })
385
- },
386
- formatData(data, refreshing = false) {
387
- let goodsInfo = this.data.goodsInfo
388
- data.forEach((item, index) => {
389
- this.formatItem(item)
390
- if (!refreshing) {
391
- goodsInfo.push(item)
392
- }
393
- })
394
- if (refreshing) {
395
- //下拉刷新的时候直接赋值
396
- goodsInfo = JSON.parse(JSON.stringify(data))
397
- }
398
- this.setData({
399
- goodsInfo
400
- },()=>{
401
- this.getActivityStatus(this.data.goodsInfo)
402
- })
403
- },
404
- getActivityStatus(data){
405
- activityList = []
406
- preheatList = []
407
- data.forEach((item, index) => {
408
- if (item.is_activity && item.end_at) {
409
- hasActivity = true
410
- item.activityCountdown = 0
411
- activityList.push({
412
- time: item.end_at,
413
- index,
414
- })
415
- }
416
- // this.data.isSeckill && this.data.preheating
417
- if (item.activity_type === 8 && item.sec_kill_is_preheat === 1) {
418
- //预热开始时间
419
- let startTime = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
420
- let times = startTime.getTime() - item.sec_kill_preheat_time * 1000
421
- let preHeatTime = new Date(times) || new Date()
422
-
423
- let startTime2 = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
424
- let nowTime = new Date().getTime()
425
- let preheating = nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
426
-
427
- if (preheating) {
428
- hasPreheat = true
429
- item.preheatTime = 0
430
- preheatList.push({
431
- time: item.start_at,
432
- index,
433
- })
434
- }
435
- }
436
- })
437
- if (hasActivity) this.startActivityCountdown(activityList) //活动倒计时
438
- if (hasPreheat) this.startPreheatCountdown(preheatList) // 预热倒计时
439
- },
440
- formatItem(e) {
441
- e.resourceTypeName = e.resource_type_name // 商品类型
442
- e.leftStock = e.is_activity && e.now_stock ? e.now_stock : e.stock // 商品库存,活动中且有活动库存就用活动库存
443
- // 处理未到活动时间的限时折扣
444
- if (e.activity_type === 3) {
445
- let nowTime = new Date().getTime()
446
- let startTime = new Date(e.start_at.replace(/-/g, "/")).getTime()
447
- let isStart = !!(nowTime - startTime > 0)
448
- if (!isStart) {
449
- e.is_activity = 0 // 未到活动时间的限时折扣 不参与比价
450
- }
451
- }
452
- // 预热前和活动结束后的秒杀不参与比价
453
- if (e.activity_type === 8) {
454
- let startTime = new Date(e.start_at.replace(/-/g, "/")).getTime()
455
- let preHeatTime = startTime - e.sec_kill_preheat_time * 1000 // 预热开始时间
456
- let nowTime = new Date().getTime()
457
- let isStartPreHeat = !!(nowTime - preHeatTime > 0) // 预热时间到了
458
- let endTime = new Date(e.end_at.replace(/-/g, "/")).getTime()
459
- let isEndSecKill = !!(nowTime - endTime > 0) // 秒杀活动结束了
460
- if (!isStartPreHeat || isEndSecKill) {
461
- e.is_activity = 0 // 预热前和活动结束后的秒杀 不参与比价
462
- }
463
- }
464
- //展示购买价处理;取原价、营销活动价、超级会员价到一个数组从小到大排序,最低为购买价。防止价格一样,所以加了权重比较
465
- let arr = []
466
- arr.push({
467
- active: "",
468
- price: e.price,
469
- weight: e.price + 0.0003,
470
- })
471
- // 活动管理、实物商品、有价优惠券、线下课和课时包不能设置活动库存,其他可以设置活动库存得需要判断是否还剩余活动库存;拼团也不能设置活动库存。
472
- let notExistNowStock = [9, 21, 41, 29, 42].indexOf(e.resource_type) > -1
473
- e.is_activity &&
474
- (notExistNowStock ||
475
- typeof e.now_stock === "number" ||
476
- e.activity_type === 6) &&
477
- arr.push({
478
- //参与营销活动且有活动库存的时候加入比较 now_stock -""空字符串的时候代表已经买完 -0代表不限量
479
- active: MARKET_ACTIVITY_MAP[e.activity_type],
480
- price: e.activity_price,
481
- weight: e.activity_price + 0.0001,
482
- })
483
- e.svip_price &&
484
- arr.push({
485
- //判断超级会员价
486
- active: "超级会员",
487
- price: e.svip_price,
488
- weight: e.svip_price + 0.0002,
489
- })
490
- arr.sort((a, b) => a.weight - b.weight)
491
- let svipAllFree = e.resource_rights_type === 1
492
- e.priceShow = arr[0].price //展示的购买价格
493
- e.priceShowInt = svipAllFree ? this.priceInt(e.price) : this.priceInt(e.priceShow) // 展示价格的整数部分
494
- e.priceShowFlow = svipAllFree ? this.priceFlow(e.price) : this.priceFlow(e.priceShow) // 展示是价格的小数部分
495
- e.preferentialShowInt = this.priceInt(e.preferential_price) // 展示券后价的整数部分
496
- e.preferentialShowFlow = this.priceFlow(e.preferential_price) // 展示券后价的小数部分
497
- e.currentActive = arr[0].active //当前适用得营销模式;有可能是原价,超级会员,营销活动
498
- //展示划线价处理;有营销活动、超级会员,划线价是原价;只有原价和原划线价,划线价是原划线价;
499
- if (e.currentActive !== "") {
500
- e.priceLine = e.price
501
- } else {
502
- e.priceLine = e.line_price || 0 //未设置原划线价的时候不展示划线价
503
- }
504
- e.priceLineShowInt = this.priceInt(e.priceLine) // 展示划线价的整数部分
505
- e.priceLineShowFlow = this.priceFlow(e.priceLine) // 展示划线的小数部分
506
- e.entityShowStock = (e.resource_type === 21 || e.resource_type === 41 || e.resource_type === 68) && e.show_stock // 实物商品库存依赖 B端店铺设置(show_stock):详情页展示不展示剩余件数
507
- e.hasStock = [29, 35].indexOf(e.resource_type) > -1 || e.entityShowStock || e.now_stock // 班课、线下课、实物商品、体验课、有活动库存,满足其一即展示库存
508
- },
509
- priceInt(val) {
510
- val = Number(val)
511
- return ((val / 100).toFixed(2) + '').split('.')[0]
512
- },
513
- priceFlow(val) {
514
- val = Number(val)
515
- return ((val / 100).toFixed(2) + '').split('.')[1] || '00'
516
- },
517
- closePop() {
518
- this.triggerEvent("closePop")
519
- },
520
- preventScroll() {
521
- return
522
- },
523
- sendGoodsCard(e) {
524
- console.log("npm", e)
525
- let dataset = e.detail.datas;
526
- this.setData({
527
- sending: true,
528
- sendingIndex: dataset['index']
529
- })
530
- // 触发父组件的send
531
- this.triggerEvent('sendGoodsCard', {
532
- datas: dataset
533
- });
534
- },
535
- clear() {
536
- this.setData({
537
- goodsInfo: [],
538
- finishedTxt: "no-data"
539
- })
540
- },
541
- setIsTakeGoods(value) {
542
- this.setData({
543
- ["aliveConf.is_takegoods"]: value
544
- })
545
- },
546
- deleteGood(id) {
547
- let deleteGoodIndex;
548
- if(!this.data.goodsInfo) return;
549
- this.data.goodsInfo.forEach((goods, index) => {
550
- if(goods.id === id) {
551
- deleteGoodIndex = index;
552
- }
553
- })
554
- deleteGoodIndex !== undefined && this.data.goodsInfo.splice(deleteGoodIndex, 1)
555
- this.setData({
556
- goodsInfo: this.data.goodsInfo
557
- })
558
- },
559
- },
560
- observers: {
561
- // 监听点击发送事件
562
- "changState.time": function (newVal) {
563
- // 处理成功回调,主要用于变更按钮发送状态
564
- console.log('changState', newVal, this.properties.changState)
565
- let state = this.properties.changState
566
- if (state && state.index != -1) {
567
- this.setData({
568
- sending: false,
569
- sendingIndex: state.index
570
- })
571
- }
572
- },
573
- "total": function(newVal){
574
- this.triggerEvent("totalChange",newVal)
575
- },
576
- "isManage": function(newVal){
577
- this.setData({
578
- selectList: []
579
- })
580
- },
581
- "is_jurisdiction": function(newVal){
582
- this.triggerEvent("jurisdictionChange",newVal)
583
- },
584
- },
585
- })
1
+ /*
2
+ * @Descripttion:
3
+ * @version:
4
+ * @Author: conlinchen
5
+ * @Date: 2021-10-28 15:32:24
6
+ * @LastEditors: conlinchen
7
+ * @LastEditTime: 2021-11-18 19:52:02
8
+ */
9
+
10
+ import { getGoodsList, requestChangeShow } from "../common/api/liveGoodsList"
11
+ const computedBehavior = require('miniprogram-computed').behavior
12
+
13
+ let activityCountdownTimer = null // 活动倒计时计时器
14
+ let hadActivity = false
15
+ let activityList = [] // 参与活动的商品
16
+
17
+ // 预热模块
18
+ let preheatTimer = null // 预热倒计时计时器
19
+ let hadPreheat = false
20
+ let preheatList = [] // 参与活动的商品
21
+
22
+ let hasActivity = false // 是否有参与活动的商品
23
+ let hasPreheat = false // 是否有参与预热的商品
24
+
25
+ const SPU_TYPE = {
26
+ 1: "图文",
27
+ 2: "音频",
28
+ 3: "视频",
29
+ 4: "直播",
30
+ 35: "班课",
31
+ 20: "电子书",
32
+ 6: "专栏",
33
+ 8: "大专栏",
34
+ 5: "会员",
35
+ 25: "训练营",
36
+ 21: "实物商品",
37
+ 29: "线下课", //体验课也是29
38
+ 22: "分销商品",
39
+ 12: "分销商品", //暂时不做
40
+ 41: "有价优惠券",
41
+ 45: "AI互动课",
42
+ 23: "超级会员"
43
+ }
44
+ const MARKET_ACTIVITY_MAP = {
45
+ 3: "限时折扣",
46
+ 4: "好友助力",
47
+ 5: "裂变海报",
48
+ 6: "拼团",
49
+ 7: "涨粉神器",
50
+ 8: "秒杀",
51
+ }
52
+
53
+ Component({
54
+ behaviors: [computedBehavior],
55
+ properties: {
56
+ sensorReportParams: {
57
+ type: Object,
58
+ value: {}
59
+ },
60
+ aliveInfo: {
61
+ type: Object,
62
+ value: {
63
+ alive_id: 'l_61c2a4dae4b0ad9a9d6887dc',
64
+ alive_state: 2
65
+ },
66
+ },
67
+ ENV_NAME: {
68
+ type: String,
69
+ value: ""
70
+ },
71
+ showList: {
72
+ type: Boolean,
73
+ value: false,
74
+ observer(newVal) {
75
+ this.setData({
76
+ refreshing: newVal
77
+ })
78
+ console.log(newVal)
79
+
80
+ newVal && this.onLoad()
81
+ if(!newVal){
82
+ clearInterval(activityCountdownTimer)
83
+ activityCountdownTimer = null
84
+ clearInterval(preheatTimer)
85
+ preheatTimer = null
86
+ }
87
+ }
88
+ },
89
+ changState: {
90
+ type: Object,
91
+ value: {}
92
+ },
93
+ aliveConf: { //is_takegoods: 是否开启直播带货,0-关闭 1-开启
94
+ type: Object,
95
+ value: {}
96
+ },
97
+ isFullScreen: {
98
+ type: Boolean,
99
+ value: false,
100
+ },
101
+ // im实时同步的带货消息
102
+ msgGoodsData: {
103
+ type: Object,
104
+ value: {},
105
+ observer(newVal) {
106
+ this.handlerListInfo(newVal)
107
+ },
108
+ },
109
+ isManage: {
110
+ type: Boolean,
111
+ value: false,
112
+ }
113
+ },
114
+ data: {
115
+ goodsInfo: [],
116
+ page_size: 5,
117
+ page_index: 1,
118
+ total: 0,
119
+ refreshing: false,
120
+ finishedTxt: '加载中',
121
+ finished: false,
122
+ sendingIndex: -1,
123
+ sending: false,
124
+ selectGoods: [], // 多选列表
125
+ is_jurisdiction: false, // 操作权限
126
+ isSplitSelect: false, // 当前是否是单独勾选
127
+ selectGoodsIndexArr: [], // 当前已经选中的商品索引数组
128
+ is_show_now: 0, //当前已展示的数量
129
+ is_hide_now: 0, // 当前已隐藏的数量
130
+ isDisabled: false, // 复选框是否禁用
131
+ selectId: '', // 当前点击那一项的goodsId
132
+
133
+ },
134
+ lifetimes: {
135
+ // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
136
+ attached: function () {
137
+
138
+ },
139
+ moved: function () { },
140
+ detached: function () { },
141
+ },
142
+ methods: {
143
+ // "sync_goods":{
144
+ // "switch":0,//开关:0关1开
145
+ // //带货配置列表-最多六条
146
+ // "conf_list":[],
147
+ // "update_list":[],
148
+ // //移除资源id
149
+ // "batch_del":["p_63845d8be4b07b05581ebf47"],
150
+ // //批量显示隐藏
151
+ // "batch_switch":[]
152
+ // }
153
+ /**
154
+ * 带货/优惠券实时同步
155
+ * @param {object} msgData im消息体
156
+ * @param {string} type 消息类型:带货goods、优惠券coupon
157
+ */
158
+ handlerListInfo(msgData) {
159
+ let type = '',
160
+ marketInfo = []
161
+ // jer todo 还有im接受的相关逻辑需要补充
162
+ // 遍历获取操作类型
163
+ for (let key in msgData) {
164
+ switch (key) {
165
+ // 带货开关操作
166
+ case "switch":
167
+ type = "goodsSwitch";
168
+ marketInfo = Number(msgData[key]);
169
+ break;
170
+ // 新增操作
171
+ case 'conf_list':
172
+ type = 'goodsConfList'
173
+ marketInfo = msgData[key]
174
+ break
175
+ // 修改操作
176
+ case 'update_list':
177
+ type = 'goodsUpdateList'
178
+ marketInfo = msgData[key]
179
+ break
180
+ // 删除操作
181
+ case 'batch_del':
182
+ type = 'goodsDelList'
183
+ marketInfo = msgData[key]
184
+ break
185
+ // jer todo 可能字段需要更改
186
+ // 显隐操作
187
+ case 'batch_switch':
188
+ type = 'goodsBatchSwitchList'
189
+ marketInfo = msgData[key]
190
+ break
191
+ default:
192
+ break
193
+ }
194
+ console.log('jer=========', type, marketInfo)
195
+ if (marketInfo?.length > 0) {
196
+ this.changeGoodsList(type, marketInfo)
197
+ type = ''
198
+ marketInfo = []
199
+ }
200
+ }
201
+ },
202
+ // 处理实时同步的带货逻辑
203
+ changeGoodsList(type, marketInfo) {
204
+ let goodsInfo = this.data.goodsInfo,
205
+ delIndex = -1, // 删除数据的当前下标
206
+ selectGoods = this.data.selectGoods, // 批量隐藏数组id
207
+ selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏数组索引
208
+ total = this.data.total, // 管理商品总数
209
+ isHasGoods = false // 是否已有这个商品
210
+ switch (type) {
211
+ // 带货和优惠券开关操作
212
+ case "goodsSwitch":
213
+ if (!marketInfo) {
214
+ this.triggerEvent("closePopup")
215
+ }
216
+ break;
217
+ case 'goodsConfList':
218
+ // 如果已经加载完了,可以拼接数据
219
+ // 由于看不出为何触发了两次,做id过滤
220
+ if (this.data.finished) {
221
+ marketInfo.map((item) => {
222
+ for (let index = 0; index < goodsInfo.length; index++) {
223
+ if (item.id === goodsInfo[index].id) {
224
+ isHasGoods = true;
225
+ break
226
+ }
227
+ }
228
+ if (!isHasGoods) {
229
+ // 管理商品需要增加
230
+ total += marketInfo.length
231
+ this.formatData([item]);
232
+ }
233
+ isHasGoods = false;
234
+ })
235
+ }
236
+ break
237
+ case 'goodsUpdateList':
238
+ case 'goodsBatchSwitchList':
239
+ marketInfo.map((item) => {
240
+ for (let index = 0; index < goodsInfo.length; index++) {
241
+ if (item.id === goodsInfo[index].id) {
242
+ // 遍历插入相应的修改值
243
+ for (let key in item) {
244
+ goodsInfo[index][key] = item[key]
245
+ }
246
+ break
247
+ }
248
+ }
249
+ })
250
+ this.formatData(goodsInfo, true);
251
+ break
252
+ case 'goodsDelList':
253
+ marketInfo.map((id) => {
254
+ for (let index = 0; index < goodsInfo.length; index++) {
255
+ if (id === goodsInfo[index].id) {
256
+ // 删除操作,获取下标
257
+ goodsInfo.splice(index, 1)
258
+ delIndex = index
259
+ index--
260
+ }
261
+ // 删除后,后面的数据都要权重+1显示
262
+ if (delIndex > -1 && index >= delIndex) {
263
+ goodsInfo[index].order_weight--
264
+ }
265
+ }
266
+ // 重置删除下标
267
+ delIndex = -1
268
+
269
+ // 此处处理批量显隐的,删掉了,需要把选择的也删掉
270
+ if (selectGoodsIndexArr.length > 0) {
271
+ for (let index = 0; index < selectGoodsIndexArr.length; index++) {
272
+ if (id === selectGoodsIndexArr[index]) {
273
+ console.log("jer==========???删了几次?", id, selectGoodsIndexArr[index]);
274
+ // 删除操作,获取下标
275
+ selectGoodsIndexArr.splice(index, 1)
276
+ selectGoods.splice(index, 1)
277
+ index--
278
+ // 管理商品需要减少
279
+ total--
280
+ }
281
+ }
282
+ }
283
+ })
284
+ this.formatData(goodsInfo, true);
285
+ break
286
+ default:
287
+ break
288
+ }
289
+ this.setData({
290
+ total,
291
+ selectGoods,
292
+ selectGoodsIndexArr,
293
+ })
294
+ },
295
+ // 管理商品多选
296
+ onChange(e){
297
+ // this.setData({
298
+ // selectGoods:e.detail
299
+ // })
300
+ console.log("sage-------onchange",e.detail);
301
+ let tempGoodsArr = []
302
+ e.detail.forEach((item) => {
303
+ for (let index = 0; index < this.data.goodsInfo.length; index++) {
304
+ if (item === this.data.goodsInfo[index].id) {
305
+ tempGoodsArr.push(this.data.goodsInfo[index])
306
+ break
307
+ }
308
+ }
309
+ })
310
+ this.setData({
311
+ selectGoods: tempGoodsArr,
312
+ selectGoodsIndexArr: e.detail,
313
+ })
314
+ },
315
+
316
+ // 显示隐藏
317
+ // 商品显隐操作
318
+ changeShowType(e) {
319
+ let { type } = e.target.dataset
320
+ // 未选择商品
321
+ if (!this.data.selectGoods.length) {
322
+ this.showToast('请先选择商品')
323
+ return
324
+ }
325
+
326
+ // 商品是否已是对应的显隐状态
327
+ this.data.selectGoods.forEach((item) => {
328
+ if (item.is_display_package && type === 'show') {
329
+ this.setData({
330
+ is_show_now: this.data.is_show_now + 1,
331
+ })
332
+ } else if (!item.is_display_package && type === 'hide') {
333
+ this.setData({
334
+ is_hide_now: this.data.is_hide_now + 1,
335
+ })
336
+ }
337
+ })
338
+ if (type === 'show') {
339
+ if (this.data.is_show_now === this.data.selectGoods.length) {
340
+ this.showToast('当前选择的商品已显示')
341
+ this.setData({
342
+ is_show_now: 0,
343
+ })
344
+ return
345
+ } else {
346
+ this.requestChangeShow(1)
347
+ return
348
+ }
349
+ }
350
+
351
+ // 隐藏商品确认弹窗
352
+ if (type === 'hide') {
353
+ console.log("sage----hide",this.data.is_hide_now,this.data.selectGoods);
354
+ if (this.data.is_hide_now === this.data.selectGoods.length) {
355
+ this.showToast('当前选择的商品已隐藏')
356
+ this.setData({
357
+ is_hide_now: 0,
358
+ })
359
+ return
360
+ } else {
361
+ wx.showModal({
362
+ title: `确认隐藏${
363
+ this.data.is_hide_now
364
+ ? this.data.selectGoods.length - this.data.is_hide_now
365
+ : this.data.selectGoods.length
366
+ }个商品吗`,
367
+ content: '用户端商品列表不展示已隐藏商品,讲师仍可通过讲解发送商品',
368
+ confirmText: '确认',
369
+ cancelText: '取消',
370
+ confirmColor: '#1472FF',
371
+ success: (res) => {
372
+ if (res.confirm) {
373
+ this.requestChangeShow(0)
374
+ } else if (res.cancel) {
375
+ this.setData({
376
+ is_hide_now: 0,
377
+ })
378
+ }
379
+ },
380
+ })
381
+ return
382
+ }
383
+ }
384
+
385
+ // 显示
386
+ this.requestChangeShow(1)
387
+ },
388
+
389
+ // 商品显隐请求
390
+ requestChangeShow(state) {
391
+ const tempSelectGoodsArr = this.data.selectGoods.map((item) => ({
392
+ id: item.id,
393
+ type: item.resource_type,
394
+ }))
395
+ let params = {
396
+ alive_id: this.data.aliveInfo.alive_id,
397
+ app_id: this.data.aliveInfo.app_id,
398
+ resource_ids: tempSelectGoodsArr,
399
+ is_display_package: state,
400
+ }
401
+ console.log('sage----调用接口传参数', tempSelectGoodsArr, params)
402
+
403
+ requestChangeShow(params,false,{isNeedToken: true}).then((res) => {
404
+ let { code } = res.data
405
+ if (code === 0) {
406
+ // let temp = `marketResource.courseList[${this.data.selectIndex}].is_display_package`
407
+ // 操作成功之后,要把当前选中的商品改变状态
408
+ let temp = ''
409
+ this.data.selectGoodsIndexArr.forEach((item) => {
410
+ for (let index = 0; index < this.data.goodsInfo.length; index++) {
411
+ if (item === this.data.goodsInfo[index].id) {
412
+ temp = `goodsInfo[${index}].is_display_package`
413
+ break
414
+ }
415
+ }
416
+ this.setData({
417
+ [temp]: state,
418
+ })
419
+ })
420
+ this.setData({
421
+ selectGoodsIndexArr: [],
422
+ selectGoods: [],
423
+ is_hide_now: 0,
424
+ is_show_now: 0,
425
+ })
426
+ this.showToast('操作成功')
427
+ } else {
428
+ this.setData({
429
+ is_hide_now: 0,
430
+ is_show_now: 0,
431
+ })
432
+ this.showToast('操作失败')
433
+ }
434
+ })
435
+ },
436
+
437
+ // 商品总活动倒计时
438
+ startActivityCountdown(list) {
439
+
440
+ clearInterval(activityCountdownTimer)
441
+ activityCountdownTimer = setInterval(() => {
442
+ hadActivity = false
443
+ list.forEach((i) => {
444
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
445
+ if (targetDate <= 0) return
446
+ hadActivity = true
447
+ let temp = `goodsInfo[${i.index}].activityCountdown`
448
+ this.setData({
449
+ [temp]: targetDate,
450
+ })
451
+ })
452
+ if (!hadActivity) {
453
+ clearInterval(activityCountdownTimer)
454
+ activityCountdownTimer = null
455
+ }
456
+ }, 1000)
457
+ },
458
+ // 预热倒计时
459
+ startPreheatCountdown(list) {
460
+ clearInterval(preheatTimer)
461
+ preheatTimer = setInterval(() => {
462
+ hadPreheat = false
463
+ list.forEach((i) => {
464
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
465
+ if (targetDate <= 0) {
466
+ activityList.push({
467
+ time: this.data.goodsInfo[i.index].end_at,
468
+ index: i.index,
469
+ })
470
+ this.setData({
471
+ [`goodsInfo[${i.index}].preheatTime`]: 0,
472
+ })
473
+ return
474
+ }
475
+ hadPreheat = true
476
+ let temp = `goodsInfo[${i.index}].preheatTime`
477
+ this.setData({
478
+ [temp]: targetDate,
479
+ })
480
+ })
481
+ if (!hadPreheat) {
482
+ clearInterval(preheatTimer)
483
+ preheatTimer = null
484
+ }
485
+ }, 1000)
486
+ },
487
+ onLoad() {
488
+ if (!this.data.aliveConf.is_takegoods) {
489
+ this.setData({
490
+ refreshing: false
491
+ })
492
+ return
493
+ }
494
+ if (this._freshing) return
495
+ this._freshing = true
496
+ this.setData({
497
+ finished: false,
498
+ page_index: 1
499
+ })
500
+ this.getGoodsList()
501
+ },
502
+ onScrolltolower() {
503
+ if (this.scrolling || this.data.finishedTxt === 'no-data' || !this.data.aliveConf.is_takegoods) { return }
504
+ this.scrolling = true
505
+ this.setData({
506
+ finishedTxt: this.data.finished ? "没有更多了" : "加载中"
507
+ })
508
+ if (this.data.finished || this._freshing) {
509
+ return
510
+ }
511
+ this.getGoodsList()
512
+ },
513
+ getGoodsList() {
514
+ let params = {
515
+ alive_id: this.data.aliveInfo.alive_id,
516
+ type: 1,
517
+ page_size: this.data.page_size,
518
+ page: this.data.page_index,
519
+ port: 2
520
+ }
521
+ getGoodsList(params).then(res => {
522
+ let { data, code } = res.data
523
+ if (code === 0) {
524
+ var total = data[0] ? data[0].total : this.data.total
525
+ var finishedTxt = "加载中"
526
+ var finished = false
527
+ let is_jurisdiction = data[0] ? data[0].teacher_auth == 2 : false
528
+
529
+ if (this._freshing) {
530
+ //下拉加载直接赋值
531
+ this.formatData(data, true)
532
+ } else {
533
+ this.formatData(data)
534
+ }
535
+ // 下拉加载,且数据返回空
536
+ if (this._freshing && data.length === 0) {
537
+ finishedTxt = "no-data"
538
+ } else if (this.data.goodsInfo.length >= total || data.length === 0) {
539
+ // 获取到所有数据
540
+ finished = true// 没有更多了
541
+ finishedTxt = "没有更多了"
542
+ this.setData({ finishedTxt })
543
+ } else {
544
+ finishedTxt = "加载中"
545
+ }
546
+ this.setData({
547
+ refreshing: false,
548
+ page_index: this.data.page_index + 1,
549
+ finishedTxt,
550
+ finished,
551
+ total,
552
+ is_jurisdiction
553
+ })
554
+ this._freshing = false
555
+ this.scrolling = false
556
+ }
557
+ })
558
+ },
559
+ formatData(data, refreshing = false) {
560
+ let goodsInfo = this.data.goodsInfo
561
+ data.forEach((item, index) => {
562
+ this.formatItem(item)
563
+ if (!refreshing) {
564
+ goodsInfo.push(item)
565
+ }
566
+ })
567
+ if (refreshing) {
568
+ //下拉刷新的时候直接赋值
569
+ goodsInfo = JSON.parse(JSON.stringify(data))
570
+ }
571
+ this.setData({
572
+ goodsInfo
573
+ },()=>{
574
+ this.getActivityStatus(this.data.goodsInfo)
575
+ })
576
+ },
577
+ getActivityStatus(data){
578
+ activityList = []
579
+ preheatList = []
580
+ data.forEach((item, index) => {
581
+ if (item.is_activity && item.end_at) {
582
+ hasActivity = true
583
+ item.activityCountdown = 0
584
+ activityList.push({
585
+ time: item.end_at,
586
+ index,
587
+ })
588
+ }
589
+ // this.data.isSeckill && this.data.preheating
590
+ if (item.activity_type === 8 && item.sec_kill_is_preheat === 1) {
591
+ //预热开始时间
592
+ let startTime = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
593
+ let times = startTime.getTime() - item.sec_kill_preheat_time * 1000
594
+ let preHeatTime = new Date(times) || new Date()
595
+
596
+ let startTime2 = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
597
+ let nowTime = new Date().getTime()
598
+ let preheating = nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
599
+
600
+ if (preheating) {
601
+ hasPreheat = true
602
+ item.preheatTime = 0
603
+ preheatList.push({
604
+ time: item.start_at,
605
+ index,
606
+ })
607
+ }
608
+ }
609
+ })
610
+ if (hasActivity) this.startActivityCountdown(activityList) //活动倒计时
611
+ if (hasPreheat) this.startPreheatCountdown(preheatList) // 预热倒计时
612
+ },
613
+ formatItem(e) {
614
+ e.resourceTypeName = e.resource_type_name // 商品类型
615
+ e.leftStock = e.is_activity && e.now_stock ? e.now_stock : e.stock // 商品库存,活动中且有活动库存就用活动库存
616
+ // 处理未到活动时间的限时折扣
617
+ if (e.activity_type === 3) {
618
+ let nowTime = new Date().getTime()
619
+ let startTime = new Date(e.start_at.replace(/-/g, "/")).getTime()
620
+ let isStart = !!(nowTime - startTime > 0)
621
+ if (!isStart) {
622
+ e.is_activity = 0 // 未到活动时间的限时折扣 不参与比价
623
+ }
624
+ }
625
+ // 预热前和活动结束后的秒杀不参与比价
626
+ if (e.activity_type === 8) {
627
+ let startTime = new Date(e.start_at.replace(/-/g, "/")).getTime()
628
+ let preHeatTime = startTime - e.sec_kill_preheat_time * 1000 // 预热开始时间
629
+ let nowTime = new Date().getTime()
630
+ let isStartPreHeat = !!(nowTime - preHeatTime > 0) // 预热时间到了
631
+ let endTime = new Date(e.end_at.replace(/-/g, "/")).getTime()
632
+ let isEndSecKill = !!(nowTime - endTime > 0) // 秒杀活动结束了
633
+ if (!isStartPreHeat || isEndSecKill) {
634
+ e.is_activity = 0 // 预热前和活动结束后的秒杀 不参与比价
635
+ }
636
+ }
637
+ //展示购买价处理;取原价、营销活动价、超级会员价到一个数组从小到大排序,最低为购买价。防止价格一样,所以加了权重比较
638
+ let arr = []
639
+ arr.push({
640
+ active: "",
641
+ price: e.price,
642
+ weight: e.price + 0.0003,
643
+ })
644
+ // 活动管理、实物商品、有价优惠券、线下课和课时包不能设置活动库存,其他可以设置活动库存得需要判断是否还剩余活动库存;拼团也不能设置活动库存。
645
+ let notExistNowStock = [9, 21, 41, 29, 42].indexOf(e.resource_type) > -1
646
+ e.is_activity &&
647
+ (notExistNowStock ||
648
+ typeof e.now_stock === "number" ||
649
+ e.activity_type === 6) &&
650
+ arr.push({
651
+ //参与营销活动且有活动库存的时候加入比较 now_stock -""空字符串的时候代表已经买完 -0代表不限量
652
+ active: MARKET_ACTIVITY_MAP[e.activity_type],
653
+ price: e.activity_price,
654
+ weight: e.activity_price + 0.0001,
655
+ })
656
+ e.svip_price &&
657
+ arr.push({
658
+ //判断超级会员价
659
+ active: "超级会员",
660
+ price: e.svip_price,
661
+ weight: e.svip_price + 0.0002,
662
+ })
663
+ arr.sort((a, b) => a.weight - b.weight)
664
+ let svipAllFree = e.resource_rights_type === 1
665
+ e.priceShow = arr[0].price //展示的购买价格
666
+ e.priceShowInt = svipAllFree ? this.priceInt(e.price) : this.priceInt(e.priceShow) // 展示价格的整数部分
667
+ e.priceShowFlow = svipAllFree ? this.priceFlow(e.price) : this.priceFlow(e.priceShow) // 展示是价格的小数部分
668
+ e.preferentialShowInt = this.priceInt(e.preferential_price) // 展示券后价的整数部分
669
+ e.preferentialShowFlow = this.priceFlow(e.preferential_price) // 展示券后价的小数部分
670
+ e.currentActive = arr[0].active //当前适用得营销模式;有可能是原价,超级会员,营销活动
671
+ //展示划线价处理;有营销活动、超级会员,划线价是原价;只有原价和原划线价,划线价是原划线价;
672
+ if (e.currentActive !== "") {
673
+ e.priceLine = e.price
674
+ } else {
675
+ e.priceLine = e.line_price || 0 //未设置原划线价的时候不展示划线价
676
+ }
677
+ e.priceLineShowInt = this.priceInt(e.priceLine) // 展示划线价的整数部分
678
+ e.priceLineShowFlow = this.priceFlow(e.priceLine) // 展示划线的小数部分
679
+ e.entityShowStock = (e.resource_type === 21 || e.resource_type === 41 || e.resource_type === 68) && e.show_stock // 实物商品库存依赖 B端店铺设置(show_stock):详情页展示不展示剩余件数
680
+ e.hasStock = [29, 35].indexOf(e.resource_type) > -1 || e.entityShowStock || e.now_stock // 班课、线下课、实物商品、体验课、有活动库存,满足其一即展示库存
681
+ },
682
+ priceInt(val) {
683
+ val = Number(val)
684
+ return ((val / 100).toFixed(2) + '').split('.')[0]
685
+ },
686
+ priceFlow(val) {
687
+ val = Number(val)
688
+ return ((val / 100).toFixed(2) + '').split('.')[1] || '00'
689
+ },
690
+ closePop() {
691
+ this.triggerEvent("closePop")
692
+ },
693
+ preventScroll() {
694
+ return
695
+ },
696
+ sendGoodsCard(e) {
697
+ console.log("npm", e)
698
+ let dataset = e.detail.datas;
699
+ this.setData({
700
+ sending: true,
701
+ sendingIndex: dataset['index']
702
+ })
703
+ // 触发父组件的send
704
+ this.triggerEvent('sendGoodsCard', {
705
+ datas: dataset
706
+ });
707
+ },
708
+ clear() {
709
+ this.setData({
710
+ goodsInfo: [],
711
+ finishedTxt: "no-data"
712
+ })
713
+ },
714
+ setIsTakeGoods(value) {
715
+ this.setData({
716
+ ["aliveConf.is_takegoods"]: value
717
+ })
718
+ },
719
+ deleteGood(id) {
720
+ let deleteGoodIndex;
721
+ if(!this.data.goodsInfo) return;
722
+ this.data.goodsInfo.forEach((goods, index) => {
723
+ if(goods.id === id) {
724
+ deleteGoodIndex = index;
725
+ }
726
+ })
727
+ deleteGoodIndex !== undefined && this.data.goodsInfo.splice(deleteGoodIndex, 1)
728
+ this.setData({
729
+ goodsInfo: this.data.goodsInfo
730
+ })
731
+ },
732
+ selectToast(e) {
733
+ console.log("sage-----单选e",e);
734
+ let tempItemIndex = String(e.currentTarget.dataset.item)
735
+ this.setData({
736
+ selectId: this.data.goodsInfo[tempItemIndex].id
737
+ })
738
+ console.log("sage-----toast",this.data.selectId, this.data.selectGoodsIndexArr.length);
739
+ if (this.data.selectGoodsIndexArr.length >= 10 && this.data.selectGoodsIndexArr.indexOf(this.data.selectId) === -1) {
740
+ this.showToast('批量操作最多支持10条')
741
+ } else {
742
+ return
743
+ }
744
+ },
745
+ showToast(title = '') {
746
+ wx.showToast({
747
+ title,
748
+ icon: 'none',
749
+ duration: 1000,
750
+ })
751
+ },
752
+ },
753
+ observers: {
754
+ // 监听点击发送事件
755
+ "changState.time": function (newVal) {
756
+ // 处理成功回调,主要用于变更按钮发送状态
757
+ console.log('changState', newVal, this.properties.changState)
758
+ let state = this.properties.changState
759
+ if (state && state.index != -1) {
760
+ this.setData({
761
+ sending: false,
762
+ sendingIndex: state.index
763
+ })
764
+ }
765
+ },
766
+ "total": function(newVal){
767
+ this.triggerEvent("totalChange",newVal)
768
+ },
769
+ "isManage": function(newVal){
770
+ this.setData({
771
+ selectGoods: []
772
+ })
773
+ },
774
+ "is_jurisdiction": function(newVal){
775
+ this.triggerEvent("jurisdictionChange",newVal)
776
+ },
777
+ },
778
+ })