xiaoe_mp_npm 0.5.42-test13 → 0.5.42-test15

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.
@@ -35,7 +35,7 @@ Component({
35
35
  type: Object,
36
36
  value: {},
37
37
  observer(newVal) {
38
- newVal.switch && this.handlerListInfo(newVal)
38
+ this.handlerListInfo(newVal)
39
39
  }
40
40
  }
41
41
  },
@@ -16,6 +16,18 @@ import {
16
16
  import { rpxToVmin } from '../common/utils/index.js'
17
17
  const computedBehavior = require('miniprogram-computed').behavior
18
18
 
19
+ let activityCountdownTimer = null // 活动倒计时计时器
20
+ let hadActivity = false
21
+ let activityList = [] // 参与活动的商品
22
+
23
+ // 预热模块
24
+ let preheatTimer = null // 预热倒计时计时器
25
+ let hadPreheat = false
26
+ let preheatList = [] // 参与活动的商品
27
+
28
+ let hasActivity = false // 是否有参与活动的商品
29
+ let hasPreheat = false // 是否有参与预热的商品
30
+
19
31
  const MARKET_ACTIVITY_MAP = {
20
32
  3: "限时折扣",
21
33
  4: "好友助力",
@@ -60,6 +72,12 @@ Component({
60
72
  newVal && this.data.explainingGoods.length && this.getExplainingGoodsInfo()
61
73
  newVal && this.getPreferentialPriceSetting()
62
74
  newVal && this.onLoad()
75
+ if(!newVal){
76
+ clearInterval(activityCountdownTimer)
77
+ activityCountdownTimer = null
78
+ clearInterval(preheatTimer)
79
+ preheatTimer = null
80
+ }
63
81
  }
64
82
  },
65
83
  // 讲解中商品
@@ -121,7 +139,7 @@ Component({
121
139
  type: Object,
122
140
  value: {},
123
141
  observer(newVal) {
124
- newVal.switch && this.handlerListInfo(newVal)
142
+ this.handlerListInfo(newVal)
125
143
  }
126
144
  },
127
145
  orientation: {
@@ -163,6 +181,56 @@ Component({
163
181
  },
164
182
  },
165
183
  methods: {
184
+ // 商品总活动倒计时
185
+ startActivityCountdown(list) {
186
+ clearInterval(activityCountdownTimer)
187
+ activityCountdownTimer = setInterval(() => {
188
+ hadActivity = false
189
+ list.forEach((i) => {
190
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
191
+ if (targetDate <= 0) return
192
+ hadActivity = true
193
+ let temp = `goodsInfo[${i.index}].activityCountdown`
194
+ this.setData({
195
+ [temp]: targetDate,
196
+ })
197
+ })
198
+ if (!hadActivity) {
199
+ clearInterval(activityCountdownTimer)
200
+ activityCountdownTimer = null
201
+ }
202
+ }, 1000)
203
+ },
204
+ // 预热倒计时
205
+ startPreheatCountdown(list) {
206
+ clearInterval(preheatTimer)
207
+ preheatTimer = setInterval(() => {
208
+ hadPreheat = false
209
+ list.forEach((i) => {
210
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
211
+ if (targetDate <= 0) {
212
+ activityList.push({
213
+ time: this.data.goodsInfo[i.index].end_at,
214
+ index: i.index,
215
+ })
216
+ this.setData({
217
+ [`goodsInfo[${i.index}].preheatTime`]: 0,
218
+ })
219
+ return
220
+ }
221
+ hadPreheat = true
222
+ let temp = `goodsInfo[${i.index}].preheatTime`
223
+ this.setData({
224
+ [temp]: targetDate,
225
+ })
226
+ })
227
+ if (!hadPreheat) {
228
+ clearInterval(preheatTimer)
229
+ preheatTimer = null
230
+ }
231
+ }, 1000)
232
+ },
233
+
166
234
  /**
167
235
  * 带货/优惠券实时同步
168
236
  * @param {object} msgData im消息体
@@ -171,10 +239,14 @@ Component({
171
239
  handlerListInfo(msgData) {
172
240
  let type = '', marketInfo = []
173
241
 
174
- // jer todo 还有im接受的相关逻辑需要补充
175
242
  // 遍历获取操作类型
176
243
  for (let key in msgData) {
177
244
  switch (key) {
245
+ // 带货开关操作
246
+ case "switch":
247
+ type = "goodsSwitch";
248
+ marketInfo = Number(msgData[key]);
249
+ break;
178
250
  // 新增操作
179
251
  case "conf_list":
180
252
  type = "goodsConfList";
@@ -214,6 +286,27 @@ Component({
214
286
  let goodsInfo = this.data.goodsInfo,
215
287
  formExplainingGoods = this.data.formExplainingGoods
216
288
  switch (type) {
289
+ // 带货和优惠券开关操作
290
+ case "goodsSwitch":
291
+ if (!marketInfo) {
292
+ // 清空数据
293
+ this.setData({
294
+ goodsInfo: [],
295
+ page_index: 1,
296
+ total: 0,
297
+ refreshing: false,
298
+ finishedTxt: '加载中',
299
+ finished: false,
300
+ formExplainingGoods: {},
301
+ explainingGoodsIndex: 1,
302
+ currentGoodsItem: {},
303
+ componentsState: 1
304
+ })
305
+ } else if (this.data.goodsInfo.length === 0 && marketInfo === 1) {
306
+ // 重新打开按钮后,请求一次列表
307
+ this.properties.isGrayMarketing ? getGoodsListNew : getGoodsList
308
+ }
309
+ break;
217
310
  case "goodsConfList":
218
311
  // 如果已经加载完了,可以拼接数据
219
312
  if (this.data.finished) this.formatData(marketInfo, true);
@@ -222,7 +315,6 @@ Component({
222
315
  case "goodsBatchSwitchList":
223
316
  marketInfo.map((item) => {
224
317
  for (let index = 0; index < goodsInfo.length; index++) {
225
- // jer todo 可能需要更改一下这个超级会员的字段
226
318
  if (item.id === goodsInfo[index].id) {
227
319
  // 遍历插入相应的修改值
228
320
  for (let key in item) {
@@ -238,14 +330,13 @@ Component({
238
330
  break;
239
331
  } else if (type === "goodsBatchSwitchList" && item.is_display_package === 1 && item.order_weight < goodsInfo[index].order_weight) {
240
332
  // 由于兼容显示商品时,接口并没有此商品的话,需要做一个插入商品到对应位置的操作,获取需要插入状态值(只有学员才需要操作)
333
+ this.formatItem(item)
241
334
  goodsInfo.splice(index, 0, item);
242
335
  break;
243
336
  }
244
337
  };
245
338
  });
246
- this.setData({
247
- goodsInfo,
248
- })
339
+ this.formatData(goodsInfo, false)
249
340
  break;
250
341
  case "goodsDelList":
251
342
  let delIndex = -1; // 删除数据的当前下标
@@ -265,9 +356,7 @@ Component({
265
356
  // 重置删除下标
266
357
  delIndex = -1;
267
358
  });
268
- this.setData({
269
- goodsInfo,
270
- })
359
+ this.formatData(goodsInfo, false)
271
360
  break;
272
361
  default:
273
362
  break;
@@ -420,7 +509,45 @@ Component({
420
509
  //下拉刷新的时候直接赋值
421
510
  goodsInfo = JSON.parse(JSON.stringify(data))
422
511
  }
423
- this.setData({goodsInfo})
512
+ this.setData({goodsInfo},()=>{
513
+ this.getActivityStatus(this.data.goodsInfo)
514
+ })
515
+ },
516
+ getActivityStatus(data){
517
+ activityList = []
518
+ preheatList = []
519
+ data.forEach((item, index) => {
520
+ if (item.is_activity && item.end_at) {
521
+ hasActivity = true
522
+ item.activityCountdown = 0
523
+ activityList.push({
524
+ time: item.end_at,
525
+ index,
526
+ })
527
+ }
528
+ // this.data.isSeckill && this.data.preheating
529
+ if (item.activity_type === 8 && item.sec_kill_is_preheat === 1) {
530
+ //预热开始时间
531
+ let startTime = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
532
+ let times = startTime.getTime() - item.sec_kill_preheat_time * 1000
533
+ let preHeatTime = new Date(times) || new Date()
534
+
535
+ let startTime2 = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
536
+ let nowTime = new Date().getTime()
537
+ let preheating = nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
538
+
539
+ if (preheating) {
540
+ hasPreheat = true
541
+ item.preheatTime = 0
542
+ preheatList.push({
543
+ time: item.start_at,
544
+ index,
545
+ })
546
+ }
547
+ }
548
+ })
549
+ if (hasActivity) this.startActivityCountdown(activityList) //活动倒计时
550
+ if (hasPreheat) this.startPreheatCountdown(preheatList) // 预热倒计时
424
551
  },
425
552
  formatItem(e) {
426
553
  e.resourceTypeName = e.resource_type_name // 商品类型
@@ -44,6 +44,7 @@
44
44
  <coupon-list
45
45
  showList="{{ showList }}"
46
46
  aliveInfo="{{ aliveInfo }}"
47
+ msgCouponData="{{msgCouponData}}"
47
48
  bind:showPopup="showInfoCollection"
48
49
  bind:receivedSuccess="receivedSuccess"
49
50
  sensorReportParams="{{sensorReportParams}}"
@@ -103,7 +103,7 @@ Component({
103
103
  type: Object,
104
104
  value: {},
105
105
  observer(newVal) {
106
- newVal.switch && this.handlerListInfo(newVal)
106
+ this.handlerListInfo(newVal)
107
107
  },
108
108
  },
109
109
  isManage: {
@@ -162,6 +162,11 @@ Component({
162
162
  // 遍历获取操作类型
163
163
  for (let key in msgData) {
164
164
  switch (key) {
165
+ // 带货开关操作
166
+ case "switch":
167
+ type = "goodsSwitch";
168
+ marketInfo = Number(msgData[key]);
169
+ break;
165
170
  // 新增操作
166
171
  case 'conf_list':
167
172
  type = 'goodsConfList'
@@ -197,17 +202,37 @@ Component({
197
202
  // 处理实时同步的带货逻辑
198
203
  changeGoodsList(type, marketInfo) {
199
204
  let goodsInfo = this.data.goodsInfo,
200
- delIndex = -1 // 删除数据的当前下标
201
- // jer todo 添加批量显隐的数组
202
- // selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏id数组
203
- // selectGoods = this.data.selectGoods // 批量隐藏数据数组
205
+ delIndex = -1, // 删除数据的当前下标
206
+ selectGoods = this.data.selectGoods, // 批量隐藏数组id
207
+ selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏数组索引
208
+ total = this.data.total, // 管理商品总数
209
+ isHasGoods = false // 是否已有这个商品
204
210
  switch (type) {
211
+ // 带货和优惠券开关操作
212
+ case "goodsSwitch":
213
+ if (!marketInfo) {
214
+ this.triggerEvent("closePopup")
215
+ }
216
+ break;
205
217
  case 'goodsConfList':
206
218
  // 如果已经加载完了,可以拼接数据
207
- if (this.data.finished) this.formatData(marketInfo);
208
- // 管理商品需要增加
209
- // jer todo 添加批量显隐的总数逻辑
210
- // this.data.marketResource.courseList[0].total += marketInfo.length
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
+ }
211
236
  break
212
237
  case 'goodsUpdateList':
213
238
  case 'goodsBatchSwitchList':
@@ -222,6 +247,7 @@ Component({
222
247
  }
223
248
  }
224
249
  })
250
+ this.formatData(goodsInfo, true);
225
251
  break
226
252
  case 'goodsDelList':
227
253
  marketInfo.map((id) => {
@@ -240,28 +266,30 @@ Component({
240
266
  // 重置删除下标
241
267
  delIndex = -1
242
268
 
243
- // jer todo 此处处理批量显隐的,删掉了,需要把选择的也删掉
244
- // if (selectGoodsIndexArr.length > 0) {
245
- // for (let index = 0; index < selectGoodsIndexArr.length; index++) {
246
- // if (id === selectGoodsIndexArr[index]) {
247
- // // 删除操作,获取下标
248
- // selectGoodsIndexArr.splice(index, 1)
249
- // selectGoods.splice(index, 1)
250
- // index--
251
- // }
252
- // }
253
- // }
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
+ }
254
283
  })
255
- // jer todo 管理商品需要减少
256
- // this.data.marketResource.courseList[0].total -= marketInfo.length
284
+ this.formatData(goodsInfo, true);
257
285
  break
258
286
  default:
259
287
  break
260
288
  }
261
289
  this.setData({
262
- goodsInfo,
263
- // selectGoodsIndexArr,
264
- // selectGoods,
290
+ total,
291
+ selectGoods,
292
+ selectGoodsIndexArr,
265
293
  })
266
294
  },
267
295
  // 管理商品多选
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaoe_mp_npm",
3
- "version": "0.5.42-test13",
3
+ "version": "0.5.42-test15",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@ Component({
35
35
  type: Object,
36
36
  value: {},
37
37
  observer(newVal) {
38
- newVal.switch && this.handlerListInfo(newVal)
38
+ this.handlerListInfo(newVal)
39
39
  }
40
40
  }
41
41
  },
@@ -16,6 +16,18 @@ import {
16
16
  import { rpxToVmin } from '../common/utils/index.js'
17
17
  const computedBehavior = require('miniprogram-computed').behavior
18
18
 
19
+ let activityCountdownTimer = null // 活动倒计时计时器
20
+ let hadActivity = false
21
+ let activityList = [] // 参与活动的商品
22
+
23
+ // 预热模块
24
+ let preheatTimer = null // 预热倒计时计时器
25
+ let hadPreheat = false
26
+ let preheatList = [] // 参与活动的商品
27
+
28
+ let hasActivity = false // 是否有参与活动的商品
29
+ let hasPreheat = false // 是否有参与预热的商品
30
+
19
31
  const MARKET_ACTIVITY_MAP = {
20
32
  3: "限时折扣",
21
33
  4: "好友助力",
@@ -60,6 +72,12 @@ Component({
60
72
  newVal && this.data.explainingGoods.length && this.getExplainingGoodsInfo()
61
73
  newVal && this.getPreferentialPriceSetting()
62
74
  newVal && this.onLoad()
75
+ if(!newVal){
76
+ clearInterval(activityCountdownTimer)
77
+ activityCountdownTimer = null
78
+ clearInterval(preheatTimer)
79
+ preheatTimer = null
80
+ }
63
81
  }
64
82
  },
65
83
  // 讲解中商品
@@ -121,7 +139,7 @@ Component({
121
139
  type: Object,
122
140
  value: {},
123
141
  observer(newVal) {
124
- newVal.switch && this.handlerListInfo(newVal)
142
+ this.handlerListInfo(newVal)
125
143
  }
126
144
  },
127
145
  orientation: {
@@ -163,6 +181,56 @@ Component({
163
181
  },
164
182
  },
165
183
  methods: {
184
+ // 商品总活动倒计时
185
+ startActivityCountdown(list) {
186
+ clearInterval(activityCountdownTimer)
187
+ activityCountdownTimer = setInterval(() => {
188
+ hadActivity = false
189
+ list.forEach((i) => {
190
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
191
+ if (targetDate <= 0) return
192
+ hadActivity = true
193
+ let temp = `goodsInfo[${i.index}].activityCountdown`
194
+ this.setData({
195
+ [temp]: targetDate,
196
+ })
197
+ })
198
+ if (!hadActivity) {
199
+ clearInterval(activityCountdownTimer)
200
+ activityCountdownTimer = null
201
+ }
202
+ }, 1000)
203
+ },
204
+ // 预热倒计时
205
+ startPreheatCountdown(list) {
206
+ clearInterval(preheatTimer)
207
+ preheatTimer = setInterval(() => {
208
+ hadPreheat = false
209
+ list.forEach((i) => {
210
+ let targetDate = new Date(i.time.replace(/-/g, '/')).getTime() - new Date().getTime()
211
+ if (targetDate <= 0) {
212
+ activityList.push({
213
+ time: this.data.goodsInfo[i.index].end_at,
214
+ index: i.index,
215
+ })
216
+ this.setData({
217
+ [`goodsInfo[${i.index}].preheatTime`]: 0,
218
+ })
219
+ return
220
+ }
221
+ hadPreheat = true
222
+ let temp = `goodsInfo[${i.index}].preheatTime`
223
+ this.setData({
224
+ [temp]: targetDate,
225
+ })
226
+ })
227
+ if (!hadPreheat) {
228
+ clearInterval(preheatTimer)
229
+ preheatTimer = null
230
+ }
231
+ }, 1000)
232
+ },
233
+
166
234
  /**
167
235
  * 带货/优惠券实时同步
168
236
  * @param {object} msgData im消息体
@@ -171,10 +239,14 @@ Component({
171
239
  handlerListInfo(msgData) {
172
240
  let type = '', marketInfo = []
173
241
 
174
- // jer todo 还有im接受的相关逻辑需要补充
175
242
  // 遍历获取操作类型
176
243
  for (let key in msgData) {
177
244
  switch (key) {
245
+ // 带货开关操作
246
+ case "switch":
247
+ type = "goodsSwitch";
248
+ marketInfo = Number(msgData[key]);
249
+ break;
178
250
  // 新增操作
179
251
  case "conf_list":
180
252
  type = "goodsConfList";
@@ -214,6 +286,27 @@ Component({
214
286
  let goodsInfo = this.data.goodsInfo,
215
287
  formExplainingGoods = this.data.formExplainingGoods
216
288
  switch (type) {
289
+ // 带货和优惠券开关操作
290
+ case "goodsSwitch":
291
+ if (!marketInfo) {
292
+ // 清空数据
293
+ this.setData({
294
+ goodsInfo: [],
295
+ page_index: 1,
296
+ total: 0,
297
+ refreshing: false,
298
+ finishedTxt: '加载中',
299
+ finished: false,
300
+ formExplainingGoods: {},
301
+ explainingGoodsIndex: 1,
302
+ currentGoodsItem: {},
303
+ componentsState: 1
304
+ })
305
+ } else if (this.data.goodsInfo.length === 0 && marketInfo === 1) {
306
+ // 重新打开按钮后,请求一次列表
307
+ this.properties.isGrayMarketing ? getGoodsListNew : getGoodsList
308
+ }
309
+ break;
217
310
  case "goodsConfList":
218
311
  // 如果已经加载完了,可以拼接数据
219
312
  if (this.data.finished) this.formatData(marketInfo, true);
@@ -222,7 +315,6 @@ Component({
222
315
  case "goodsBatchSwitchList":
223
316
  marketInfo.map((item) => {
224
317
  for (let index = 0; index < goodsInfo.length; index++) {
225
- // jer todo 可能需要更改一下这个超级会员的字段
226
318
  if (item.id === goodsInfo[index].id) {
227
319
  // 遍历插入相应的修改值
228
320
  for (let key in item) {
@@ -238,14 +330,13 @@ Component({
238
330
  break;
239
331
  } else if (type === "goodsBatchSwitchList" && item.is_display_package === 1 && item.order_weight < goodsInfo[index].order_weight) {
240
332
  // 由于兼容显示商品时,接口并没有此商品的话,需要做一个插入商品到对应位置的操作,获取需要插入状态值(只有学员才需要操作)
333
+ this.formatItem(item)
241
334
  goodsInfo.splice(index, 0, item);
242
335
  break;
243
336
  }
244
337
  };
245
338
  });
246
- this.setData({
247
- goodsInfo,
248
- })
339
+ this.formatData(goodsInfo, false)
249
340
  break;
250
341
  case "goodsDelList":
251
342
  let delIndex = -1; // 删除数据的当前下标
@@ -265,9 +356,7 @@ Component({
265
356
  // 重置删除下标
266
357
  delIndex = -1;
267
358
  });
268
- this.setData({
269
- goodsInfo,
270
- })
359
+ this.formatData(goodsInfo, false)
271
360
  break;
272
361
  default:
273
362
  break;
@@ -420,7 +509,45 @@ Component({
420
509
  //下拉刷新的时候直接赋值
421
510
  goodsInfo = JSON.parse(JSON.stringify(data))
422
511
  }
423
- this.setData({goodsInfo})
512
+ this.setData({goodsInfo},()=>{
513
+ this.getActivityStatus(this.data.goodsInfo)
514
+ })
515
+ },
516
+ getActivityStatus(data){
517
+ activityList = []
518
+ preheatList = []
519
+ data.forEach((item, index) => {
520
+ if (item.is_activity && item.end_at) {
521
+ hasActivity = true
522
+ item.activityCountdown = 0
523
+ activityList.push({
524
+ time: item.end_at,
525
+ index,
526
+ })
527
+ }
528
+ // this.data.isSeckill && this.data.preheating
529
+ if (item.activity_type === 8 && item.sec_kill_is_preheat === 1) {
530
+ //预热开始时间
531
+ let startTime = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
532
+ let times = startTime.getTime() - item.sec_kill_preheat_time * 1000
533
+ let preHeatTime = new Date(times) || new Date()
534
+
535
+ let startTime2 = (item.start_at && new Date(item.start_at.replace(/-/g, '/'))) || new Date()
536
+ let nowTime = new Date().getTime()
537
+ let preheating = nowTime > preHeatTime.getTime() && startTime2.getTime() > nowTime
538
+
539
+ if (preheating) {
540
+ hasPreheat = true
541
+ item.preheatTime = 0
542
+ preheatList.push({
543
+ time: item.start_at,
544
+ index,
545
+ })
546
+ }
547
+ }
548
+ })
549
+ if (hasActivity) this.startActivityCountdown(activityList) //活动倒计时
550
+ if (hasPreheat) this.startPreheatCountdown(preheatList) // 预热倒计时
424
551
  },
425
552
  formatItem(e) {
426
553
  e.resourceTypeName = e.resource_type_name // 商品类型
@@ -44,6 +44,7 @@
44
44
  <coupon-list
45
45
  showList="{{ showList }}"
46
46
  aliveInfo="{{ aliveInfo }}"
47
+ msgCouponData="{{msgCouponData}}"
47
48
  bind:showPopup="showInfoCollection"
48
49
  bind:receivedSuccess="receivedSuccess"
49
50
  sensorReportParams="{{sensorReportParams}}"
@@ -103,7 +103,7 @@ Component({
103
103
  type: Object,
104
104
  value: {},
105
105
  observer(newVal) {
106
- newVal.switch && this.handlerListInfo(newVal)
106
+ this.handlerListInfo(newVal)
107
107
  },
108
108
  },
109
109
  isManage: {
@@ -162,6 +162,11 @@ Component({
162
162
  // 遍历获取操作类型
163
163
  for (let key in msgData) {
164
164
  switch (key) {
165
+ // 带货开关操作
166
+ case "switch":
167
+ type = "goodsSwitch";
168
+ marketInfo = Number(msgData[key]);
169
+ break;
165
170
  // 新增操作
166
171
  case 'conf_list':
167
172
  type = 'goodsConfList'
@@ -197,17 +202,37 @@ Component({
197
202
  // 处理实时同步的带货逻辑
198
203
  changeGoodsList(type, marketInfo) {
199
204
  let goodsInfo = this.data.goodsInfo,
200
- delIndex = -1 // 删除数据的当前下标
201
- // jer todo 添加批量显隐的数组
202
- // selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏id数组
203
- // selectGoods = this.data.selectGoods // 批量隐藏数据数组
205
+ delIndex = -1, // 删除数据的当前下标
206
+ selectGoods = this.data.selectGoods, // 批量隐藏数组id
207
+ selectGoodsIndexArr = this.data.selectGoodsIndexArr, // 批量隐藏数组索引
208
+ total = this.data.total, // 管理商品总数
209
+ isHasGoods = false // 是否已有这个商品
204
210
  switch (type) {
211
+ // 带货和优惠券开关操作
212
+ case "goodsSwitch":
213
+ if (!marketInfo) {
214
+ this.triggerEvent("closePopup")
215
+ }
216
+ break;
205
217
  case 'goodsConfList':
206
218
  // 如果已经加载完了,可以拼接数据
207
- if (this.data.finished) this.formatData(marketInfo);
208
- // 管理商品需要增加
209
- // jer todo 添加批量显隐的总数逻辑
210
- // this.data.marketResource.courseList[0].total += marketInfo.length
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
+ }
211
236
  break
212
237
  case 'goodsUpdateList':
213
238
  case 'goodsBatchSwitchList':
@@ -222,6 +247,7 @@ Component({
222
247
  }
223
248
  }
224
249
  })
250
+ this.formatData(goodsInfo, true);
225
251
  break
226
252
  case 'goodsDelList':
227
253
  marketInfo.map((id) => {
@@ -240,28 +266,30 @@ Component({
240
266
  // 重置删除下标
241
267
  delIndex = -1
242
268
 
243
- // jer todo 此处处理批量显隐的,删掉了,需要把选择的也删掉
244
- // if (selectGoodsIndexArr.length > 0) {
245
- // for (let index = 0; index < selectGoodsIndexArr.length; index++) {
246
- // if (id === selectGoodsIndexArr[index]) {
247
- // // 删除操作,获取下标
248
- // selectGoodsIndexArr.splice(index, 1)
249
- // selectGoods.splice(index, 1)
250
- // index--
251
- // }
252
- // }
253
- // }
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
+ }
254
283
  })
255
- // jer todo 管理商品需要减少
256
- // this.data.marketResource.courseList[0].total -= marketInfo.length
284
+ this.formatData(goodsInfo, true);
257
285
  break
258
286
  default:
259
287
  break
260
288
  }
261
289
  this.setData({
262
- goodsInfo,
263
- // selectGoodsIndexArr,
264
- // selectGoods,
290
+ total,
291
+ selectGoods,
292
+ selectGoodsIndexArr,
265
293
  })
266
294
  },
267
295
  // 管理商品多选