From 6dc65d687e67dfbbcdf9cbed738979dbf2d84836 Mon Sep 17 00:00:00 2001 From: banche Date: Fri, 11 Mar 2022 17:52:36 +0800 Subject: [PATCH] fix:首页秒杀状态显示错误 --- pages/index/index/index.js | 74 +++++++++++++++++++++++++++++++++++--------------------------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/pages/index/index/index.js b/pages/index/index/index.js index d42dfff..9768921 100644 --- a/pages/index/index/index.js +++ b/pages/index/index/index.js @@ -379,53 +379,49 @@ Page({ //当前时间戳 var nt = ut.gettimestamp(); - flash_data.forEach(async function (val, ind) { + flash_data.forEach(function (val, ind) { if(val.user_price) val.price=val.user_price; - if (val.start_time > nt) flash_data[ind].status = 0; - else if (val.end_time > nt) flash_data[ind].status = 1; + if (val.start_time > nt) { + flash_data[ind].status = 0; + } else if (val.end_time > nt) { + flash_data[ind].status = 1; + } if (val.buy_num >= val.goods_num){ flash_data[ind].status = 2; - } else { - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + - os.stoid + "/1/" + val.id, {} - ).then(res => { - if (res.data.code == 0) { - if (res.data.data <= 0) flash_data[ind].status = 2; - }; - }) - }; - + } }); - - // var plist = flash_data; - // //--循环读取接口--- - // for (var i = 0; i < plist.length; i++) { - - // // if (plist[i].user_price) plist[i].price = plist[i].user_price; - // // var prom_id = plist[i].id; - // await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + - // os.stoid + "/1/" + prom_id, {} - // ).then(res => { - // if (res.data.code == 0) { - // plist[i].status = 1; - // if (res.data.data <= 0) plist[i].status = 3; - // } - // }) - // alllist.push(plist[i]); - // } - - - - var arr = new Array(); - //--三个三个一组--- - for (var i = 0; i < flash_data.length; i += 3) { - arr.push(flash_data.slice(i, i + 3)); + + var promisies = []; + for (const key in flash_data) { + if (Object.hasOwnProperty.call(flash_data, key)) { + const val = flash_data[key]; + promisies[key] = getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + + os.stoid + "/1/" + val.id, + {} + ).then(res => { + if (res.data.code == 0) { + if (res.data.data <= 0) flash_data[key].status = 2; + }; + }); + } } - th.setData({ - saleGoods: arr + + Promise.all(promisies).then((values) => { + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < flash_data.length; i += 3) { + arr.push(flash_data.slice(i, i + 3)); + } + + th.setData({ + saleGoods: arr + }); }); + + + } }); -- libgit2 0.21.4