From c59e69d11c5b5d9d0645de0edb10700a05fabb61 Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Mon, 17 Oct 2016 16:45:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E7=B1=BB=E5=88=AB?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E9=A1=B5=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0title=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 3 ++- pages/address/address.json | 3 +++ pages/cart/cart.json | 3 +++ pages/category/category.js | 19 +++++++++++++++++++ pages/category/category.json | 3 +++ pages/category/category.wxml | 0 pages/category/category.wxss | 0 pages/index/index.js | 16 +++++++++++----- pages/index/index.json | 3 +++ pages/index/index.wxml | 5 ++--- pages/mine/mine.json | 3 +++ utils/product.js | 17 ++++++++++++++++- 12 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 pages/address/address.json create mode 100644 pages/cart/cart.json create mode 100644 pages/category/category.js create mode 100644 pages/category/category.json create mode 100644 pages/category/category.wxml create mode 100644 pages/category/category.wxss create mode 100644 pages/index/index.json create mode 100644 pages/mine/mine.json diff --git a/app.json b/app.json index 9758444..7815ef3 100644 --- a/app.json +++ b/app.json @@ -4,7 +4,8 @@ "pages/show_product/show_product", "pages/address/address", "pages/cart/cart", - "pages/mine/mine" + "pages/mine/mine", + "pages/category/category" ], "window":{ "backgroundTextStyle":"light", diff --git a/pages/address/address.json b/pages/address/address.json new file mode 100644 index 0000000..99202bc --- /dev/null +++ b/pages/address/address.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "收货地址" +} diff --git a/pages/cart/cart.json b/pages/cart/cart.json new file mode 100644 index 0000000..4064742 --- /dev/null +++ b/pages/cart/cart.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "购物车" +} diff --git a/pages/category/category.js b/pages/category/category.js new file mode 100644 index 0000000..2d7e644 --- /dev/null +++ b/pages/category/category.js @@ -0,0 +1,19 @@ +const product = require('../../utils/product.js') + +Page({ + data: { + items: [] + }, + + onLoad: function(params) { + var that = this + product.getCategories(params.type).then(function(result) { + var data = getApp().store.sync(result.data) + that.setData({'items': data}) + wx.setStorage({ + key:`cate_${params.type}`, + data:data + }) + }) + } +}) diff --git a/pages/category/category.json b/pages/category/category.json new file mode 100644 index 0000000..b144292 --- /dev/null +++ b/pages/category/category.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "分类" +} diff --git a/pages/category/category.wxml b/pages/category/category.wxml new file mode 100644 index 0000000..e69de29 diff --git a/pages/category/category.wxss b/pages/category/category.wxss new file mode 100644 index 0000000..e69de29 diff --git a/pages/index/index.js b/pages/index/index.js index fe625f0..0eb356d 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -2,13 +2,13 @@ const product = require('../../utils/product.js') Page({ data: { - categories: [2,6,7], + categories: [2,7,9], items: [], slides: [], - navs: [{icon: "../../images/1.png", name: "资产"}, - {icon: "../../images/1.png", name: "直销"}, - {icon: "../../images/1.png", name: "严选"}, - {icon: "../../images/1.png", name: "包装"}] + navs: [{icon: "../../images/1.png", name: "资产", key: '1'}, + {icon: "../../images/1.png", name: "直销", key: '2'}, + {icon: "../../images/1.png", name: "严选", key: '3'}, + {icon: "../../images/1.png", name: "包装", key: '4'}] }, bindShowProduct: function (e) { @@ -17,6 +17,12 @@ Page({ }) }, + catchTapCategory: function (e) { + wx.navigateTo({ + url: `../category/category?type=${e.currentTarget.dataset.type}` + }) + }, + onLoad: function() { var that = this diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..e2b7497 --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "商城首页" +} diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 31081ab..d87db12 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -12,7 +12,7 @@ - + {{item.name}} @@ -26,7 +26,7 @@ - 新品上市 + {{category}} @@ -37,7 +37,6 @@ {{item.name}} {{item.desc || '私人稻田精品礼盒'}} - 立即购买 diff --git a/pages/mine/mine.json b/pages/mine/mine.json new file mode 100644 index 0000000..3013f7f --- /dev/null +++ b/pages/mine/mine.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "我的资料" +} diff --git a/utils/product.js b/utils/product.js index 1e8368d..a7c159d 100644 --- a/utils/product.js +++ b/utils/product.js @@ -35,7 +35,18 @@ function postBilling (data) { }) }) } - + +function getCategories (data) { + return new Promise((resolve, reject) => { + wx.request({ + url: `${API_URL}/products?category=${data}`, + header: { 'Content-Type': 'application/json'}, + success: resolve, + fail: reject + }) + }) +} + module.exports = { getProducts () { @@ -48,5 +59,9 @@ module.exports = { postBilling (data) { return postBilling(data) + }, + + getCategories (data) { + return getCategories(data) } }