cart 添加价格总计

wechat_user_type
Ge Hao 8 years ago
parent 95fa531d79
commit dbd81b3030
  1. 12
      pages/cart/cart.js
  2. 1
      pages/cart/cart.wxml
  3. 3
      pages/cart/cart.wxss

@ -17,6 +17,8 @@ Page({
var cartItems = wx.getStorageSync("cartItems") var cartItems = wx.getStorageSync("cartItems")
this.setData({cartItems: cartItems}) this.setData({cartItems: cartItems})
this.changeCartAmount()
var detailAddress = wx.getStorageSync('detailAddress') var detailAddress = wx.getStorageSync('detailAddress')
var receiverName = wx.getStorageSync('receiverName') var receiverName = wx.getStorageSync('receiverName')
var receiverMobile = wx.getStorageSync('receiverMobile') var receiverMobile = wx.getStorageSync('receiverMobile')
@ -41,6 +43,7 @@ Page({
key: 'cartItems', key: 'cartItems',
data: cartItems data: cartItems
}) })
this.changeCartAmount()
}, },
// tap on item to delete cart item // tap on item to delete cart item
@ -68,6 +71,7 @@ Page({
this.setData({ this.setData({
deleteModalHidden: true deleteModalHidden: true
}) })
this.changeCartAmount()
}, },
bindBilling: function () { bindBilling: function () {
@ -89,6 +93,14 @@ Page({
} }
}, },
changeCartAmount: function () {
var amount = 0
this.data.cartItems.forEach(function(entry){
amount += entry.quantity * entry.product.price
})
this.setData({amount: amount})
},
bindTapAddress () { bindTapAddress () {
wx.navigateTo({ wx.navigateTo({
url: '../address/address' url: '../address/address'

@ -45,6 +45,7 @@
<view class="billing-btn"> <view class="billing-btn">
<view>总计:¥{{amount}}元</view>
<button class="button" type='warn' bindtap="bindBilling"> 去支付 </button> <button class="button" type='warn' bindtap="bindBilling"> 去支付 </button>
</view> </view>

@ -5,6 +5,7 @@
.address-container { .address-container {
margin: 15rpx; margin: 15rpx;
padding-bottom: 10rpx; padding-bottom: 10rpx;
border-bottom: 1px solid #e4e4e4;
} }
.receiver { .receiver {
@ -25,7 +26,7 @@
height: 180rpx; height: 180rpx;
padding: 15rpx; padding: 15rpx;
background-color: #fff; background-color: #fff;
border-top: 1px solid #e4e4e4; border-bottom: 1px solid #e4e4e4;
color: #333; color: #333;
display:flex; display:flex;
align-items:center; align-items:center;

Loading…
Cancel
Save