• Promises-小程序购物车结算


      //结算提交
      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); }); } }) }

      

  • 相关阅读:
    numpy用法介绍-未完待续
    GeoJSON相关操作
    awk日志分析
    awk获取外部变量
    Shell编程二
    Shell编程
    Linux监控平台搭建
    Linux集群架构
    Linux集群
    MySQL主从(MySQL proxy Lua读写分离设置,一主多从同步配置,分库分表方案)
  • 原文地址:https://www.cnblogs.com/pangxiaox/p/7802856.html
Copyright © 2020-2023  润新知