Promises-小程序購物車結算
阿新 • • 發佈:2017-11-08
ping ood err opp mode method syn catch model
//結算提交 checkOut : function(){ var price = this.data.sum; var user = wx.getStorageSync(‘userInfo‘); if (!user){ wx.showModel({ title:‘提示‘, content:‘請登錄‘, success : function(){ }, }) } let goods_id=0; var shop = this.data.shoppingCartInfo; wx.request({ url: `${app.globalData.API_URL}`+‘/order‘, data:{ goods_price : this.data.sum, user_id : user.mid }, method: ‘POST‘, header :{ ‘content-type‘:‘application/json‘ }, success : function(res){ var order_id = res.data; //引入異步 var promises = new promise(function(resolve,reject){ resolve(shop); }) promises.then(function(value){
//循環遍歷 value.forEach(function(value){ console.log(value,‘foreach‘); wx.request({ url: `${app.globalData.API_URL}/ordergoods`, data: { order_id : order_id, goods_id : value.goodId, goods_name : value.goodName, goods_price : value.goodPrice, goods_num : value.goodSum, spec_key : value.goodImg }, method: ‘POST‘, success: function(res){ console.log(‘成功‘); }, fail: function(res) { }, }); }); }).catch(function(error){ console.error(error); }); } }) }
Promises-小程序購物車結算