carShopBean.optionid 这个值只读取最后一个循坏的值,求大神不吝赐教!!
for (var i = 0; i < shopList.length; i++) {
if (isFail) {
wx.hideLoading();
return;
}
var carShopBean = shopList[i];
// 获取价格和库存
//console.log(carShopBean);
if (carShopBean.selected) {
propertyChildIds = propertyChildIds + carShopBean.id + ",";
console.log('optionid----------' + i + "-----------");
app.util.request({
url: app.siteGetDataUrl.taoda_get_goodinfo_url,
data: {
m: app.siteInfo.modular,
id: carShopBean.goodsid
},
method: 'post',
success: function (result) {
console.log(carShopBean);
if (!result.data.message.errno) {
var userInfo = wx.getStorageSync('userInfo');
var levelid = userInfo.memberInfo.level;
var groupid = userInfo.memberInfo.groupid;
var goodsid = result.data.data.goodsinfo.id;
var title = result.data.data.goodsinfo.title;
var goodsalltotal = result.data.data.goodsinfo.goodsalltotal;
var minbuy = result.data.data.goodsinfo.minbuy;
var maxbuy = result.data.data.goodsinfo.maxbuy;
var total = result.data.data.goodsinfo.total;
var usermaxbuy = result.data.data.goodsinfo.usermaxbuy;
var stock = result.data.data.goodsinfo.stock;
var unit = result.data.data.goodsinfo.unit;
var optionid = shopList[doneNumber].optionid;
console.log('optionid----------' + i + "-----------" + carShopBean.optionid);
//doneNumber++
//doneNumber++;
if ((result.data.data.goodsinfo.status != 1) || (result.data.data.goodsinfo.goodsdeleted == 1)) {
app.util.message(title + ' 已经下架', "","error");
isFail = true;
wx.hideLoading();
return;
}
if (result.data.data.goodsinfo.buylevels != '') {
var buylevelstr=result.data.data.goodsinfo.buylevels;
var buylevels = buylevelstr.split(",");
if (buylevels.indexOf(levelid) == -1){
app.util.message(title + ' 您的会员等级无法购买', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
if (result.data.data.goodsinfo.buygroups != '') {
var buygroupstr = result.data.data.goodsinfo.buygroups;
var buygroups = buygroupstr.split(",");
if (buygroups.indexOf(groupid) == -1) {
app.util.message(title + ' 您所在会员组无法购买', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
if (result.data.data.goodsinfo.type ==4) {
if (goodsalltotal < minbuy) {
app.util.message(title + minbuy + unit + ' 起批!', "", "error");
isFail = true;
wx.hideLoading();
return;
}
} else{
if (0 < minbuy) {
if (total < minbuy) {
app.util.message(title + minbuy + unit + ' 起售!', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
if (0 < maxbuy) {
if (maxbuy < total) {
app.util.message(title + ' 一次限购 ' + minmaxbuybuy + unit + "!", "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
}
if (0 < usermaxbuy) {
app.util.request({
url: app.siteGetDataUrl.taoda_get_usergoodsordercount_url,
data: {
m: app.siteInfo.modular,
id: goodsid
},
method: 'post',
success: function (resCoun) {
console.log('resCoun----------' + resCoun);
if (!res.data.message.errno) {
if (usermaxbuy <= resCoun.data.count) {
app.util.message(title + ' 最多限购' + usermaxbuy + unit + "!", "", "error");
isFail = true;
wx.hideLoading();
return;
}
}else{
app.util.message(title + ' 获取会员商品订单数出错', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
});
}
if (0 < optionid) {
app.util.request({
url: app.siteGetDataUrl.taoda_get_GoodsOptionid_url,
data: {
m: app.siteInfo.modular,
id: goodsid,
optionid: optionid
},
method: 'post',
success: function (resOptionid) {
console.log(resOptionid);
if (!resOptionid.data.message.errno) {
if (resOptionid.data.data.stock != -1) {
if (!resOptionid.data.data.stock) {
app.util.message(title + resOptionid.data.data.title + optionid + ' 库存不足!', "", "error");
isFail = true;
wx.hideLoading();
return;
}else{
if (resOptionid.data.data.stock < carShopBean.totalmaxbuy) {
app.util.message(title + resOptionid.data.data.title + ' 库存不足,请重新购买', "", "error");
isFail = true;
wx.hideLoading();
return;
}
if (resOptionid.data.data.marketprice != carShopBean.marketprice) {
app.util.message(title + resOptionid.data.data.title + ' 价格有调整,请重新购买!', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
}
} else {
app.util.message(title + ' 获取会员商品订单数出错', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
})
} else if (stock!=-1){
if (!stock) {
app.util.message(title + ' 库存不足!', "", "error");
isFail = true;
wx.hideLoading();
return;
}else{
if (stock < carShopBean.totalmaxbuy) {
app.util.message(title + ' 库存不足,请重新购买', "", "error");
isFail = true;
wx.hideLoading();
return;
}
if (result.data.data.goodsinfo.marketprice != carShopBean.marketprice) {
app.util.message(title + ' 价格有调整,请重新购买!', "", "error");
isFail = true;
wx.hideLoading();
return;
}
}
}
// if (needDoneNUmber == doneNumber) {
// that.navigateToPayOrder();
// }
}
}
})
}
}
代码看起来很吃力,如果稍微懂一点Promise不至于写出这样的代码。建议你看下Promise.all()
你这不是在故意显摆你很厉害吗?最讨厌这种人,以为自己写的代码很牛x的样子在这贴出来!