From f998471164daf7f7d824e372072f84832b2eaf0f Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Mon, 19 Dec 2016 14:10:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6item=E5=A2=9E?= =?UTF-8?q?=E5=87=8F=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/cart/cart.js | 36 +++++++++++++++++++++++++++++++++++- pages/cart/cart.wxml | 17 ++++++++--------- pages/cart/cart.wxss | 34 +++++++++++++++++++++++----------- 3 files changed, 66 insertions(+), 21 deletions(-) diff --git a/pages/cart/cart.js b/pages/cart/cart.js index 5430007..05acbe6 100644 --- a/pages/cart/cart.js +++ b/pages/cart/cart.js @@ -60,17 +60,24 @@ Page({ }, bindChangeQuantity: function (e) { + if (e.detail.value === "") { return "" } + var cartItems = this.data.cartItems var item = cartItems.filter(function(ele){ return ele.id === e.currentTarget.dataset.id })[0] - item.quantity = e.detail.value + if (e.detail.value >= 1) { + item.quantity = parseInt(e.detail.value) + } else { + item.quantity = 1 + } this.setData({ cartItems: cartItems }) wx.setStorage({ key: 'cartItems', data: cartItems }) this.changeCartAmount() + return item.quantity.toString() }, // tap on item to delete cart item @@ -228,6 +235,33 @@ Page({ this.setData({amount: amount}) }, + addQuantity: function(e) { + this.changeCartItemQuantity('+', e) + }, + + minusQuantity: function(e) { + this.changeCartItemQuantity('-', e) + }, + + changeCartItemQuantity: function(op, e) { + var cartItems = this.data.cartItems + var item = cartItems.filter(function(ele){ + return ele.id === e.currentTarget.dataset.id + })[0] + if (op === '-' && item.quantity > 1) { + item.quantity -= 1 + } else if (op === '+') { + item.quantity += 1 + } + + this.setData({ cartItems: cartItems }) + wx.setStorage({ + key: 'cartItems', + data: cartItems + }) + this.changeCartAmount() + }, + bindTapAddress () { wx.navigateTo({ url: '../address/address' diff --git a/pages/cart/cart.wxml b/pages/cart/cart.wxml index e251956..f4ebece 100644 --- a/pages/cart/cart.wxml +++ b/pages/cart/cart.wxml @@ -38,24 +38,23 @@ - {{item.product.name}} + {{item.product.name}} - ¥{{item.product['baye-price']}} / 件 + ¥{{item.product['baye-price'] * item.quantity}} - ¥{{item.product['member-price']}} / 件 + ¥{{item.product['member-price'] * item.quantity}} - - - 数量: - - - + + - + + + + diff --git a/pages/cart/cart.wxss b/pages/cart/cart.wxss index 00a60fe..62769d3 100644 --- a/pages/cart/cart.wxss +++ b/pages/cart/cart.wxss @@ -75,18 +75,36 @@ display: block; } -.pull-right { +.quantity { margin-left: auto; - font-size: 28rpx; + font-size: 26rpx; display: flex; } -.numbers input { +.quantity .op { border: 1rpx solid lightgrey; - width: 60rpx; + width: 70rpx; + font-size: 32rpx; + font-weight: 800; + line-height: 50rpx; + height: 50rpx; + text-align: center; +} + +.quantity .number { + border-top: 1rpx solid lightgrey; + border-bottom: 1rpx solid lightgrey; + line-height: 50rpx; + height: 50rpx; + text-align: center; } -.numbers text { +.quantity .input { + width: 80rpx; +} + +.numbers .price { + color: red; padding-top: 15rpx; } @@ -108,12 +126,6 @@ font-size: 30rpx; } -.quantity input { - min-height: 10rpx; - height: 50rpx; - margin-right: 20rpx; -} - .separate { height: 18rpx; background-color: #f2f2f2;