From c508b3e30db838bcd3a6f9942f32caf55cdd2bcf Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Wed, 30 Nov 2016 11:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=8F=8B=E5=A5=BD=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86=E7=9A=84bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit success,complete等回调的执行顺序好像有问题,navigateTo会在页面渲染onLoad之前执行,造成先到mine页面再到coupon页面。 收货人手机号输入使用digit键盘 cart.js 如果cart为空,弹出提示框 --- app.js | 14 +++--- pages/address/address.wxml | 2 +- pages/cart/cart.js | 88 +++++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/app.js b/app.js index 44e9b69..48542ec 100644 --- a/app.js +++ b/app.js @@ -65,11 +65,15 @@ App({ data: {code: that.globalData.code}, success: function(res) { if (!res.data.token) { - wx.navigateTo({ - url: '../mine/mine', - success: function(res){}, - fail: function() {}, - complete: function() {} + wx.showModal({ + title: '未登录', + content: '请前往 “我的” 页面绑定手机号', + showCancel: false, + success: function(res) { + if (getCurrentPages().length > 1) { + wx.navigateBack() + } + } }) } else { that.globalData.currentCustomer = res.data.customer diff --git a/pages/address/address.wxml b/pages/address/address.wxml index ad30393..51b3232 100644 --- a/pages/address/address.wxml +++ b/pages/address/address.wxml @@ -38,7 +38,7 @@ 手机号: - + diff --git a/pages/cart/cart.js b/pages/cart/cart.js index 9d75be8..bb9ceb0 100644 --- a/pages/cart/cart.js +++ b/pages/cart/cart.js @@ -97,53 +97,61 @@ Page({ return } var cartItems = wx.getStorageSync('cartItems') - if (cartItems) { - var order_items_attributes = cartItems.map(function(obj){ - var rObj = {}; - rObj['product_uid'] = obj.product.uid - rObj['quantity'] = parseInt(obj.quantity) - rObj['shippment_type'] = '包邮' - // rObj['external_content'] = "" - return rObj + if (!cartItems || cartItems.length === 0) { + wx.showModal({ + title: '未选购商品', + content: '您需要将商品加入购物车后才能支付', + showCancel: false, + success: function(res) {} }) + return + } - var params = this.data.address - params['order_from'] = 'from_applet' - params['order_items'] = order_items_attributes - if (this.data.coupon) { - params['coupon_code'] = this.data.coupon.code - } + var order_items_attributes = cartItems.map(function(obj){ + var rObj = {}; + rObj['product_uid'] = obj.product.uid + rObj['quantity'] = parseInt(obj.quantity) + rObj['shippment_type'] = '包邮' + // rObj['external_content'] = "" + return rObj + }) - order.postBilling(params, function(result){ - if (result.statusCode === '403') { - wx.showModal({ - title: '出错', - content: result.data.msg, - showCancel: false, - success: function(res) {} - }) - return - } + var params = this.data.address + params['order_from'] = 'from_applet' + params['order_items'] = order_items_attributes + if (this.data.coupon) { + params['coupon_code'] = this.data.coupon.code + } - pay.pay(result.data.hash, function(){ - wx.removeStorage({ - key: 'cartItems', - success: function(res) { - wx.showModal({ - title: '提示', - content: '你已成功购买,如需查看订单,可下载 ‘巴爷供销社’ APP', - showCancel: false, - success: function(res) { - if (res.confirm) { - that.setData({cartItems: []}) - } + order.postBilling(params, function(result){ + if (result.statusCode === '403') { + wx.showModal({ + title: '出错', + content: result.data.msg, + showCancel: false, + success: function(res) {} + }) + return + } + + pay.pay(result.data.hash, function(){ + wx.removeStorage({ + key: 'cartItems', + success: function(res) { + wx.showModal({ + title: '提示', + content: '你已成功购买,如需查看订单,可下载 ‘巴爷供销社’ APP', + showCancel: false, + success: function(res) { + if (res.confirm) { + that.setData({cartItems: []}) } - }) - } - }) + } + }) + } }) }) - } + }) }, addressValid: function() {