From 8ae4eea501577a1fc865153a89b83c054fc71c3e Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Wed, 12 Oct 2016 16:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=A6=82=E4=B8=8B=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新的IDE好像只能有三个文件夹,所以更改了json库的位置 完成cart的商品列表显示,可以修改数量,删除购物车物品 把 cartItems 的数据格式改的简单了些,先不考虑那么多了,本地方便就好 --- app.js | 2 +- pages/cart/cart.js | 42 +++++++++- pages/cart/cart.wxml | 47 +++++++++-- pages/cart/cart.wxss | 77 +++++++++++++++++++ pages/show_product/show_product.js | 15 ++-- .../jsonapi-datastore/LICENSE.md | 0 .../jsonapi-datastore/README.md | 0 .../dist/jsonapi-datastore.js | 0 .../jsonapi-datastore/package.json | 0 9 files changed, 169 insertions(+), 14 deletions(-) rename {node_modules => utils}/jsonapi-datastore/LICENSE.md (100%) rename {node_modules => utils}/jsonapi-datastore/README.md (100%) rename {node_modules => utils}/jsonapi-datastore/dist/jsonapi-datastore.js (100%) rename {node_modules => utils}/jsonapi-datastore/package.json (100%) diff --git a/app.js b/app.js index 0094526..311af40 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,6 @@ App({ onLaunch: function () { - const jsonApi = require('node_modules/jsonapi-datastore/dist/jsonapi-datastore.js') + const jsonApi = require('utils/jsonapi-datastore/dist/jsonapi-datastore.js') this.store = new(jsonApi.JsonApiDataStore) this.jsonModel = jsonApi.JsonApiDataStoreModel } diff --git a/pages/cart/cart.js b/pages/cart/cart.js index 2d4414a..0200d19 100644 --- a/pages/cart/cart.js +++ b/pages/cart/cart.js @@ -2,18 +2,25 @@ const district = require('../../utils/address_data.js') Page({ data: { - address:{} + deleteModalHidden: true, + wantToDeleteItem: '', + address:{}, + cartItems:[], + amount:0 }, onLoad: function (params) { }, onShow: function (params) { + var cartItems = wx.getStorageSync("cartItems") + this.setData({cartItems: cartItems}) + var address = {} var detailAddress = wx.getStorageSync('detailAddress') address.detail = detailAddress - var districtIndex = wx.getStorageSync('currentDistrict') + var districtIndex = wx.getStorageSync('currentDistrict') || [0,0,0] address.province = district.provinces()[districtIndex[0]] address.city = district.cities(address.province)[districtIndex[1]] address.county = district.counties(address.province, address.city)[districtIndex[2]] @@ -21,6 +28,37 @@ Page({ this.setData({address: address}) }, + bindChangeQuantity: function (e) { + + }, + + // tap on item to delete cart item + bindTapOnItem: function (e) { + this.setData({ + deleteModalHidden: false, + wantToDeleteItem: e.currentTarget.dataset.id + }) + }, + + deleteModalChange: function (e) { + var that = this + if (e.type === "confirm") { + var cartItems = that.data.cartItems + var index = cartItems.findIndex(function(ele){ + return ele.id === that.data.wantToDeleteItem + }) + cartItems.splice(index, 1) + this.setData({ cartItems: cartItems }) + wx.setStorage({ + key: 'cartItems', + data: cartItems + }) + } + this.setData({ + deleteModalHidden: true + }) + }, + // bindBilling: function () { // var cartItems = wx.getStorageSync('cartItems') // }, diff --git a/pages/cart/cart.wxml b/pages/cart/cart.wxml index c522be5..3ca7b6e 100644 --- a/pages/cart/cart.wxml +++ b/pages/cart/cart.wxml @@ -1,10 +1,47 @@ - - {{address.province}} {{address.city}} {{address.county}} {{address.detail}} - - 修改地址 + + + 收货人:{{address.name}} + {{address.mobile}} + + + {{address.province}} {{address.city}} {{address.county}} {{address.detail}} + + + - 填写收货地址 + + + + + + + + + + + + {{item.product.name}} + + + ¥{{item.product.price}} / 件 + + 购买数量: + + + + + + + + + + + + + \ No newline at end of file diff --git a/pages/cart/cart.wxss b/pages/cart/cart.wxss index e69de29..b764fb5 100644 --- a/pages/cart/cart.wxss +++ b/pages/cart/cart.wxss @@ -0,0 +1,77 @@ +.button button { + border-radius: 0; +} + +.address-container { + margin: 15rpx; +} + +.item { + height: 180rpx; + padding: 15rpx; + background-color: #fff; + border-top: 1px solid #e4e4e4; + color: #787878; + display:flex; + align-items:center; +} + +.item image { + display: block; + width: 300rpx; +} + +.item-right { + display: block; + margin-left: 11px; + flex: 1; +} + +.title { + padding-bottom: 15px; +} + +.title text { + font-size: 16px; + color: #787878; + white-space: pre-wrap; + line-height: 17px; +} + +text { + font-size: 15px; + color: #444; +} + +.numbers { + display: flex; +} + +.numbers text, input { + display: block; +} + +.pull-right { + margin: auto; + font-size: 15px; + display: flex; +} + +.numbers input { + border: 1rpx solid lightgrey; + width: 60rpx; +} + +.numbers text { + padding: 10rpx; +} + +.billing-btn { + position: fixed; + bottom: 0; + width: 100%; +} + +.billing-btn .button { + border-radius: 0; +} \ No newline at end of file diff --git a/pages/show_product/show_product.js b/pages/show_product/show_product.js index 709effb..ebac755 100644 --- a/pages/show_product/show_product.js +++ b/pages/show_product/show_product.js @@ -28,19 +28,22 @@ Page({ }, bindAddToCart (e) { - var cartItems = wx.getStorageSync('cartItems') || {data:[]} + var cartItems = wx.getStorageSync('cartItems') || [] - var exist = cartItems.data.find(function(ele){ + var exist = cartItems.find(function(ele){ return ele.id === app.getCurrentPage().data.id }) if (exist) { exist.quantity = this.data.quantity } else { - var model = getApp().jsonModel - var product = new model('products', this.data.id) - product.setAttribute('quantity', this.data.quantity) - cartItems.data.push(product) + // var model = getApp().jsonModel + // var product = new model('products', this.data.id) + // product.setAttribute('quantity', this.data.quantity) + var product = {id: this.data.id, + quantity: this.data.quantity, + product: this.data.product} + cartItems.push(product) } this.setData({ toastAddProduct:false }); diff --git a/node_modules/jsonapi-datastore/LICENSE.md b/utils/jsonapi-datastore/LICENSE.md similarity index 100% rename from node_modules/jsonapi-datastore/LICENSE.md rename to utils/jsonapi-datastore/LICENSE.md diff --git a/node_modules/jsonapi-datastore/README.md b/utils/jsonapi-datastore/README.md similarity index 100% rename from node_modules/jsonapi-datastore/README.md rename to utils/jsonapi-datastore/README.md diff --git a/node_modules/jsonapi-datastore/dist/jsonapi-datastore.js b/utils/jsonapi-datastore/dist/jsonapi-datastore.js similarity index 100% rename from node_modules/jsonapi-datastore/dist/jsonapi-datastore.js rename to utils/jsonapi-datastore/dist/jsonapi-datastore.js diff --git a/node_modules/jsonapi-datastore/package.json b/utils/jsonapi-datastore/package.json similarity index 100% rename from node_modules/jsonapi-datastore/package.json rename to utils/jsonapi-datastore/package.json