From cb5efbc0ec6eaf1fbd417b0d0a6b0a6f1a85adc4 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Tue, 16 May 2017 14:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.json | 2 +- app/pages/index/category.wxml | 2 +- app/pages/index/index.wxml | 4 +- app/pages/index/search.js | 96 ++++++++++++++++++++++++---- app/pages/index/search.json | 4 +- app/pages/index/search.wxml | 27 +++++++- app/pages/index/search.wxss | 8 ++- app/pages/index/templates/goods.wxml | 13 ++++ app/pages/index/templates/goods.wxss | 0 app/utils/apis.js | 30 +++++++++ 10 files changed, 168 insertions(+), 18 deletions(-) create mode 100644 app/pages/index/templates/goods.wxml create mode 100644 app/pages/index/templates/goods.wxss diff --git a/app/app.json b/app/app.json index 8f9a0c3..340abd4 100644 --- a/app/app.json +++ b/app/app.json @@ -1,8 +1,8 @@ { "pages": [ "pages/index/index", - "pages/index/category", "pages/index/search", + "pages/index/category", "pages/shop/show", "pages/order/list", "pages/order/show", diff --git a/app/pages/index/category.wxml b/app/pages/index/category.wxml index 8f73e58..c3ca147 100644 --- a/app/pages/index/category.wxml +++ b/app/pages/index/category.wxml @@ -6,4 +6,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/pages/index/index.wxml b/app/pages/index/index.wxml index 79b7dd1..8347767 100644 --- a/app/pages/index/index.wxml +++ b/app/pages/index/index.wxml @@ -6,9 +6,9 @@ {{currentAddress ? currentAddress.title : '定位中...'}} - + 搜索 - + diff --git a/app/pages/index/search.js b/app/pages/index/search.js index 1fe2621..e07fdf6 100644 --- a/app/pages/index/search.js +++ b/app/pages/index/search.js @@ -1,80 +1,154 @@ // pages/index/search.js +import debounce from '../../utils/debounce' +import { + search +} from '../../utils/apis' Page({ /** * 页面的初始数据 */ data: { - + inputShowed: false, + inputVal: "", + page: 0, + hasMore: true, + loading: false + }, + showInput: function () { + this.setData({ + inputShowed: true + }); + }, + hideInput: function () { + this.setData({ + inputVal: "", + inputShowed: false + }); + }, + clearInput: function () { + this.setData({ + inputVal: "" + }); + }, + inputTyping: function (e) { + var {value} = e.detail + this.setData({ + inputVal: value, + page: 0, + hasMore: true, + loading: false + }); + if (value) { + this.loadData() + } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { - + this.inputTyping = debounce(this.inputTyping, 300) }, /** * 生命周期函数--监听页面初次渲染完成 */ 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, + inputVal: keyword + } = this.data + if (loading) { + return + } + that.setData({ + loading: true + }) + + search({ + keyword, 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 + }) + } + }) + } }) \ No newline at end of file diff --git a/app/pages/index/search.json b/app/pages/index/search.json index 9e26dfe..8da7b3a 100644 --- a/app/pages/index/search.json +++ b/app/pages/index/search.json @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "navigationBarTitleText": "搜索" +} \ No newline at end of file diff --git a/app/pages/index/search.wxml b/app/pages/index/search.wxml index 2e49c82..350e459 100644 --- a/app/pages/index/search.wxml +++ b/app/pages/index/search.wxml @@ -1,2 +1,27 @@ -pages/index/search.wxml + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/pages/index/search.wxss b/app/pages/index/search.wxss index 7f4a7fb..38568e0 100644 --- a/app/pages/index/search.wxss +++ b/app/pages/index/search.wxss @@ -1 +1,7 @@ -/* pages/index/search.wxss */ \ No newline at end of file +/* pages/index/search.wxss */ +@import '/templates/load-more.wxss'; +@import './templates/shop.wxss'; + +.search-list { + margin-top: 10px; +} \ No newline at end of file diff --git a/app/pages/index/templates/goods.wxml b/app/pages/index/templates/goods.wxml new file mode 100644 index 0000000..8d07f59 --- /dev/null +++ b/app/pages/index/templates/goods.wxml @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/app/pages/index/templates/goods.wxss b/app/pages/index/templates/goods.wxss new file mode 100644 index 0000000..e69de29 diff --git a/app/utils/apis.js b/app/utils/apis.js index f3ec774..fbdda3a 100644 --- a/app/utils/apis.js +++ b/app/utils/apis.js @@ -517,3 +517,33 @@ export function getSellersByCategory(options) { }) } + +// 搜索商家和商品 +export function search(options) { + var { + keyword, page, + success, error + } = options + page = page || 0 + getApp().getCurrentAddress(address => { + var { + location: {longitude, latitude}, + city_id, + city: city_name, + district_id, + district: district_name + } = address + fetch({ + url: 'index.php?m=Mall&c=Seller&a=search', + data: { + keyword, + city_id, city_name, + district_id, district_name, + page, + longitude, latitude + }, + success, error + }) + + }) +}