From 357b8d9bd926f665715ea1373e4ad515aa6d5577 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Mon, 15 May 2017 16:50:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.json | 6 +- app/pages/index/category.js | 126 ++++++++++++++++++++++ app/pages/{shop => index}/category.json | 0 app/pages/index/category.wxml | 9 ++ app/pages/index/category.wxss | 7 ++ app/pages/index/index.js | 3 +- app/pages/index/index.wxml | 35 +----- app/pages/index/index.wxss | 3 +- app/pages/index/search.js | 80 ++++++++++++++ app/pages/{shop => index}/search.json | 0 app/pages/index/search.wxml | 2 + app/pages/index/search.wxss | 1 + app/pages/index/templates/shop.wxml | 34 ++++++ app/pages/index/{ => templates}/shop.wxss | 3 + app/pages/shop/category.js | 19 ---- app/pages/shop/category.wxml | 2 - app/pages/shop/category.wxss | 1 - app/pages/shop/search.js | 19 ---- app/pages/shop/search.wxml | 2 - app/pages/shop/search.wxss | 1 - app/utils/apis.js | 63 ++++++++--- 21 files changed, 318 insertions(+), 98 deletions(-) create mode 100644 app/pages/index/category.js rename app/pages/{shop => index}/category.json (100%) create mode 100644 app/pages/index/category.wxml create mode 100644 app/pages/index/category.wxss create mode 100644 app/pages/index/search.js rename app/pages/{shop => index}/search.json (100%) create mode 100644 app/pages/index/search.wxml create mode 100644 app/pages/index/search.wxss create mode 100644 app/pages/index/templates/shop.wxml rename app/pages/index/{ => templates}/shop.wxss (82%) delete mode 100644 app/pages/shop/category.js delete mode 100644 app/pages/shop/category.wxml delete mode 100644 app/pages/shop/category.wxss delete mode 100644 app/pages/shop/search.js delete mode 100644 app/pages/shop/search.wxml delete mode 100644 app/pages/shop/search.wxss diff --git a/app/app.json b/app/app.json index a128b06..8f9a0c3 100644 --- a/app/app.json +++ b/app/app.json @@ -1,6 +1,8 @@ { "pages": [ "pages/index/index", + "pages/index/category", + "pages/index/search", "pages/shop/show", "pages/order/list", "pages/order/show", @@ -10,9 +12,7 @@ "pages/address/list", "pages/index/address", "pages/address/add", - "pages/login/login", - "pages/shop/category", - "pages/shop/search" + "pages/login/login" ], "window": { "backgroundColor": "#f8f8f8", diff --git a/app/pages/index/category.js b/app/pages/index/category.js new file mode 100644 index 0000000..7bff39d --- /dev/null +++ b/app/pages/index/category.js @@ -0,0 +1,126 @@ +// pages/index/category.js +import { + getSellersByCategory +} from '../../utils/apis' + +Page({ + + /** + * 页面的初始数据 + */ + data: { + page: 0, + hasMore: true, + loading: false + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.id = options.id || 1 + this.loadData() + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + var {loading, hasMore} = this.data + if (hasMore && !loading) { + this.loadData() + } + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + loadData() { + var that = this + var {id: category_id} = this + var {loading, page} = this.data + if (loading) { + return + } + that.setData({ + loading: true + }) + + getSellersByCategory({ + category_id, page, + success(data) { + var {list} = that.data + var { + list: list2, count, page + } = data + list2 = list2.map(item => { + item['distanceFormat'] = (item.distance / 1000).toFixed(2) + return item + }) + that.setData({ + loading: false, + list: list ? list.concat(list2) : list2, + hasMore: count == 10, + page: page + 1 + }) + wx.setNavigationBarTitle({ + title: data.title, + }) + } + }) + + } +}) \ No newline at end of file diff --git a/app/pages/shop/category.json b/app/pages/index/category.json similarity index 100% rename from app/pages/shop/category.json rename to app/pages/index/category.json diff --git a/app/pages/index/category.wxml b/app/pages/index/category.wxml new file mode 100644 index 0000000..8f73e58 --- /dev/null +++ b/app/pages/index/category.wxml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/pages/index/category.wxss b/app/pages/index/category.wxss new file mode 100644 index 0000000..92375e6 --- /dev/null +++ b/app/pages/index/category.wxss @@ -0,0 +1,7 @@ +/* pages/index/category.wxss */ +@import '/templates/load-more.wxss'; +@import './templates/shop.wxss'; + +.shop-list { + margin-top: 10px; +} \ No newline at end of file diff --git a/app/pages/index/index.js b/app/pages/index/index.js index 573eb9c..eef7e7e 100644 --- a/app/pages/index/index.js +++ b/app/pages/index/index.js @@ -76,7 +76,7 @@ Page({ } var that = this var { - page, currentAddress, + page, } = this.data this.setData({ @@ -84,7 +84,6 @@ Page({ }) getSellers({ page, - address: currentAddress, success(data) { var { shopList diff --git a/app/pages/index/index.wxml b/app/pages/index/index.wxml index ff40cb0..79b7dd1 100644 --- a/app/pages/index/index.wxml +++ b/app/pages/index/index.wxml @@ -1,5 +1,5 @@ - + @@ -11,7 +11,7 @@ - + @@ -20,36 +20,7 @@ - - - - - - {{item.seller_name}} - - - -