const app = getApp(); Page({ authdialog: null, product_ids: '', product_num: '', data: { isUseAddress: false, settlement: 0.00 }, onLoad: function (options) { var that = this; app.showLoading(); //获取自定义授权组件 that.authdialog = this.selectComponent("#authdialog"); app.request('product.api.carts',{},{ success: function(data, res){ app.setList(that, data.carts); that.doSettlement(); app.hideLoading(); } }); }, /** * 删除订单 */ delOrder: function(e){ var that = this; var pid; if (e == null && arguments.length==2){ pid = arguments[1]; }else{ pid = app.getData(e).id; } var delfun = function(){ app.request('product.api.delCarts',{ product_id: pid },{ success: function(data, res){ app.toast('删除商品成功!'); that.onLoad(); }, fail: function(res){ app.toast('删除商品失败!'); } }); } wx.showModal({ content: '确认删除该商品吗?', success: function(res){ if (res.confirm){ delfun(); } } }) }, /** * 减少商品数量>0 and <=1 */ doSub: function(e){ var id = app.getData(e).id; var list = this.data.list; for(var i=0; i1 and <=库存 */ doAdd: function(e){ var id = app.getData(e).id; var list = this.data.list; for (var i = 0; i < list.length; i++) { if (list[i].product_id == id) { ++list[i].num; break; } } app.setList(this, list); this.doSettlement(); }, /** * 结算金额 */ doSettlement: function(){ var list = this.data.list; var count=0; this.product_ids = ''; this.product_num = ''; for(var i=0; i -1) { id = id.substring(0, idx); } //跳转支付结果页 app.redirect('pay/index?id=' + id); }, fail: function(res){//微信支付失败 app.toast('支付失败!'); console.log('支付失败!', res); } }) }, fail: function(res){ app.toast('支付失败!'); }, complete: function (res) { app.hideLoading(); } }) }, /** * 使用微信地址 */ chooseAddress: function(event){ var that = this; var success = function(){ wx.chooseAddress({ success: function (res) { app.set(that,'addrObj', res); app.set(that,'isUseAddress', true); } }) } wx.getSetting({ success: function(res){ if (res.authSetting['scope.address']){ success(); }else{ wx.authorize({ scope: 'scope.address', success: function () { success(); }, fail: function(res){ that.authdialog.showDialog(); } }) } } }) } })