From 1366fc5f79624216c6170f43cea1947b2554be69 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Wed, 19 Oct 2016 17:40:20 +0800 Subject: [PATCH] =?UTF-8?q?category=20=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/cart/cart.js | 2 +- pages/cart/cart.wxml | 8 ++++---- pages/cart/cart.wxss | 6 +----- pages/category/category.js | 32 ++++++++++++++++++++++++++++++++ pages/category/category.wxml | 19 ++++++++++++++----- pages/category/category.wxss | 33 +++++++++++++++++++++++++++++++++ pages/index/index.js | 6 +++--- utils/product.js | 2 +- 8 files changed, 89 insertions(+), 19 deletions(-) diff --git a/pages/cart/cart.js b/pages/cart/cart.js index b2d0e7b..62caecd 100644 --- a/pages/cart/cart.js +++ b/pages/cart/cart.js @@ -44,7 +44,7 @@ Page({ }, // tap on item to delete cart item - bindTapOnItem: function (e) { + catchTapOnItem: function (e) { this.setData({ deleteModalHidden: false, wantToDeleteItem: e.currentTarget.dataset.id diff --git a/pages/cart/cart.wxml b/pages/cart/cart.wxml index 78c601d..8815a92 100644 --- a/pages/cart/cart.wxml +++ b/pages/cart/cart.wxml @@ -17,17 +17,17 @@ - - + + - + {{item.product.name}} - ¥{{item.product.price}} / 件 + ¥{{item.product.price}} / 件 diff --git a/pages/cart/cart.wxss b/pages/cart/cart.wxss index 77c5742..be37232 100644 --- a/pages/cart/cart.wxss +++ b/pages/cart/cart.wxss @@ -9,10 +9,7 @@ .receiver { display: flex; -} - -.left { - width: 60%; + justify-content: space-between; } .address { @@ -20,7 +17,6 @@ } .right { - width: 40%; margin-left: auto; text-align: right; } diff --git a/pages/category/category.js b/pages/category/category.js index 698a6f6..f369462 100644 --- a/pages/category/category.js +++ b/pages/category/category.js @@ -22,5 +22,37 @@ Page({ var data = wx.getStorage(key) wx.setData({items: data}) }) + }, + + bindShowProduct: function(e) { + var that = this + var cartItems = wx.getStorageSync('cartItems') || [] + var thisItem = this.data.items.find(function(ele){ + return ele.id === e.currentTarget.dataset.id + }) + debugger + + var exist = cartItems.find(function(ele){ + return ele.id === that.data.id + }) + + if (exist) { + exist.quantity = '1' + } else { + cartItems.push({ + id: thisItem.id, + quantity: '1', + product: thisItem + }) + } + wx.setStorage({ + key: 'cartItems', + data: cartItems + }) + + wx.redirectTo({ + url: '../cart/cart' + }) + } }) diff --git a/pages/category/category.wxml b/pages/category/category.wxml index f52ad6e..1fd5929 100644 --- a/pages/category/category.wxml +++ b/pages/category/category.wxml @@ -1,7 +1,16 @@ - - - - - + + + + + + {{item.name}} + + + ¥{{item.price}} + 加入购物车 + + + + \ No newline at end of file diff --git a/pages/category/category.wxss b/pages/category/category.wxss index e69de29..1549dc4 100644 --- a/pages/category/category.wxss +++ b/pages/category/category.wxss @@ -0,0 +1,33 @@ +.item-container { + display: flex; + flex-direction: row; + flex-wrap: wrap; + margin-bottom: 100rpx; +} + +.item { + width: 335rpx; + margin-bottom: 80rpx; + display: flex; + flex-direction: column; + font-size: 30rpx; + margin-left: 20rpx; + margin-right: 20rpx; +} + +.item image { + width: 335rpx; + height: 335rpx; + margin-bottom: 20rpx; +} + +.item .first-line { + font-size: 25rpx; + margin-bottom: 20rpx; +} + +.item .second-line { + display: flex; + flex-direction: row; + justify-content: space-between; +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index b4fc7be..4ec6d10 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -4,10 +4,10 @@ Page({ data: { items: [], slides: [], - navs: [{icon: "../../images/asset.png", name: "资产"}, + navs: [{icon: "../../images/asset.png", name: "资产"}, {icon: "../../images/direct_sale.png", name: "直销"}, - {icon: "../../images/recommend.png", name: "严选"}, - {icon: "../../images/packing.png", name: "包装"}], + {icon: "../../images/recommend.png", name: "严选"}, + {icon: "../../images/packing.png", name: "包装"}], popularity_products: [], new_products: [], diff --git a/utils/product.js b/utils/product.js index a7c159d..fb39625 100644 --- a/utils/product.js +++ b/utils/product.js @@ -39,7 +39,7 @@ function postBilling (data) { function getCategories (data) { return new Promise((resolve, reject) => { wx.request({ - url: `${API_URL}/products?category=${data}`, + url: `${API_URL}/products/category?type=${data}`, header: { 'Content-Type': 'application/json'}, success: resolve, fail: reject