Commit 6dc65d687e67dfbbcdf9cbed738979dbf2d84836
1 parent
e5952bc7
fix:首页秒杀状态显示错误
Showing
1 changed file
with
35 additions
and
39 deletions
pages/index/index/index.js
@@ -379,53 +379,49 @@ Page({ | @@ -379,53 +379,49 @@ Page({ | ||
379 | //当前时间戳 | 379 | //当前时间戳 |
380 | var nt = ut.gettimestamp(); | 380 | var nt = ut.gettimestamp(); |
381 | 381 | ||
382 | - flash_data.forEach(async function (val, ind) { | 382 | + flash_data.forEach(function (val, ind) { |
383 | 383 | ||
384 | if(val.user_price) val.price=val.user_price; | 384 | if(val.user_price) val.price=val.user_price; |
385 | - if (val.start_time > nt) flash_data[ind].status = 0; | ||
386 | - else if (val.end_time > nt) flash_data[ind].status = 1; | 385 | + if (val.start_time > nt) { |
386 | + flash_data[ind].status = 0; | ||
387 | + } else if (val.end_time > nt) { | ||
388 | + flash_data[ind].status = 1; | ||
389 | + } | ||
387 | 390 | ||
388 | if (val.buy_num >= val.goods_num){ | 391 | if (val.buy_num >= val.goods_num){ |
389 | flash_data[ind].status = 2; | 392 | flash_data[ind].status = 2; |
390 | - } else { | ||
391 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | ||
392 | - os.stoid + "/1/" + val.id, {} | ||
393 | - ).then(res => { | ||
394 | - if (res.data.code == 0) { | ||
395 | - if (res.data.data <= 0) flash_data[ind].status = 2; | ||
396 | - }; | ||
397 | - }) | ||
398 | - }; | ||
399 | - | 393 | + } |
400 | }); | 394 | }); |
401 | - | ||
402 | - // var plist = flash_data; | ||
403 | - // //--循环读取接口--- | ||
404 | - // for (var i = 0; i < plist.length; i++) { | ||
405 | - | ||
406 | - // // if (plist[i].user_price) plist[i].price = plist[i].user_price; | ||
407 | - // // var prom_id = plist[i].id; | ||
408 | - // await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | ||
409 | - // os.stoid + "/1/" + prom_id, {} | ||
410 | - // ).then(res => { | ||
411 | - // if (res.data.code == 0) { | ||
412 | - // plist[i].status = 1; | ||
413 | - // if (res.data.data <= 0) plist[i].status = 3; | ||
414 | - // } | ||
415 | - // }) | ||
416 | - // alllist.push(plist[i]); | ||
417 | - // } | ||
418 | - | ||
419 | - | ||
420 | - | ||
421 | - var arr = new Array(); | ||
422 | - //--三个三个一组--- | ||
423 | - for (var i = 0; i < flash_data.length; i += 3) { | ||
424 | - arr.push(flash_data.slice(i, i + 3)); | 395 | + |
396 | + var promisies = []; | ||
397 | + for (const key in flash_data) { | ||
398 | + if (Object.hasOwnProperty.call(flash_data, key)) { | ||
399 | + const val = flash_data[key]; | ||
400 | + promisies[key] = getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | ||
401 | + os.stoid + "/1/" + val.id, | ||
402 | + {} | ||
403 | + ).then(res => { | ||
404 | + if (res.data.code == 0) { | ||
405 | + if (res.data.data <= 0) flash_data[key].status = 2; | ||
406 | + }; | ||
407 | + }); | ||
408 | + } | ||
425 | } | 409 | } |
426 | - th.setData({ | ||
427 | - saleGoods: arr | 410 | + |
411 | + Promise.all(promisies).then((values) => { | ||
412 | + var arr = new Array(); | ||
413 | + //--三个三个一组--- | ||
414 | + for (var i = 0; i < flash_data.length; i += 3) { | ||
415 | + arr.push(flash_data.slice(i, i + 3)); | ||
416 | + } | ||
417 | + | ||
418 | + th.setData({ | ||
419 | + saleGoods: arr | ||
420 | + }); | ||
428 | }); | 421 | }); |
422 | + | ||
423 | + | ||
424 | + | ||
429 | } | 425 | } |
430 | }); | 426 | }); |
431 | 427 |