加入购物车 数量叠加

wechat_user_type
Ge Hao 8 years ago
parent 43b8453d48
commit 024693a55c
  1. 6
      pages/category/category.js
  2. 2
      pages/category/category.wxml
  3. 2
      pages/show_product/show_product.js

@ -24,7 +24,7 @@ Page({
})
},
bindShowProduct: function(e) {
bindTapProduct: function(e) {
var that = this
var cartItems = wx.getStorageSync('cartItems') || []
var thisItem = this.data.items.find(function(ele){
@ -32,11 +32,11 @@ Page({
})
var exist = cartItems.find(function(ele){
return ele.id === that.data.id
return ele.id === thisItem.id
})
if (exist) {
exist.quantity = '1'
exist.quantity = parseInt(exist.quantity) + 1
} else {
cartItems.push({
id: thisItem.id,

@ -1,7 +1,7 @@
<scroll-view scroll-y="true" height="100%">
<view class="item-container">
<block wx:for="{{items}}" wx:for-item="item">
<view class="item" bindtap="bindShowProduct" data-id="{{item.id}}">
<view class="item" bindtap="bindTapProduct" data-id="{{item.id}}">
<image class="head-img" src="{{item['image-url']}}" mode="scaleToFill"></image>
<view class="first-line">
<text class="name">{{item.name}}</text>

@ -34,7 +34,7 @@ Page({
})
if (exist) {
exist.quantity = this.data.quantity
exist.quantity = parseInt(exist.quantity) + 1
} else {
cartItems.push({
id: this.data.id,

Loading…
Cancel
Save