From 952c42afdf0c8b86b8b821ad66b0ef30331ced81 Mon Sep 17 00:00:00 2001 From: Kiyan Date: Mon, 8 May 2017 14:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=9C=B0=E5=9D=80=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.json | 2 +- app/pages/index/address.js | 66 ++++++++++++++---------------------- app/pages/index/address.wxml | 4 +-- app/pages/index/index.js | 20 +++++++++-- app/pages/index/index.wxml | 4 +-- app/pages/index/index.wxss | 2 +- app/pages/shop/show.wxml | 2 +- app/utils/util.js | 4 +++ 8 files changed, 55 insertions(+), 49 deletions(-) diff --git a/app/app.json b/app/app.json index a8adad0..bb45ab2 100644 --- a/app/app.json +++ b/app/app.json @@ -1,8 +1,8 @@ { "pages": [ "pages/index/index", - "pages/shop/show", "pages/index/address", + "pages/shop/show", "pages/mine/mine", "pages/order/show", "pages/order/quasi", diff --git a/app/pages/index/address.js b/app/pages/index/address.js index deb7c0a..a4fdf67 100644 --- a/app/pages/index/address.js +++ b/app/pages/index/address.js @@ -1,51 +1,17 @@ // pages/index/address.js import { - getCurrentAddressList, + getPrevPage, + getCurrentAddressList, setCurrentAddress, searchAddressList, splitByKeyword } from '../../utils/util' import debounce from '../../utils/debounce' - - var initReLocateLabel = '重新定位' Page({ data: { reLocateLabel: initReLocateLabel, - addressList: [ - { - "addr_id": "170", - "user_id": "4", - "city_id": "330300", - "district_id": null, - "addr": "龙华大厦", - "detail": "", - "longitude": "120.69101", - "latitude": "28.002974", - "receiver": "test4", - "phone": "13000000005", - "create_time": "2017-02-20 10:38:11", - "delete": "0", - "district_name": "", - "city_name": "温州市" - }, - { - "addr_id": "160", - "user_id": "4", - "city_id": "330300", - "district_id": null, - "addr": "电商大厦", - "detail": "", - "longitude": "120.737561", - "latitude": "27.979617", - "receiver": "test4", - "phone": "13000000004", - "create_time": "2016-12-16 13:37:10", - "delete": "0", - "district_name": "", - "city_name": "温州市" - } - ], + addressList: [], poiList: [], @@ -55,6 +21,7 @@ Page({ }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 + this.callback = options.cb || 'callback' this.initPoiList() this.onSearchInput = debounce(this.onSearchInput, 300) }, @@ -88,8 +55,8 @@ Page({ keyword: value, success(data) { data = data.map(item => { - item['titleSplit'] = splitByKeyword(item.title, value) - return item + item['titleSplit'] = splitByKeyword(item.title, value) + return item }) that.setData({ searchList: data @@ -105,7 +72,26 @@ Page({ }) }, onSearchItemTap(e) { - console.log(e) + var {id} = e.currentTarget + var {searchList} = this.data + var { + title, address, location, + city, district, adcode + } = searchList[id] + + getPrevPage()[this.callback]({ + location, title, address, + city, district, + district_id: adcode.toString(), + city_id: adcode.toString().replace(/\d{2}$/, '00') + }) + wx.navigateBack() + }, + onAddressItemTap(e) { + var {id} = e.currentTarget + var {poiList} = this.data + getPrevPage()[this.callback](poiList[id]) + wx.navigateBack() }, initPoiList() { diff --git a/app/pages/index/address.wxml b/app/pages/index/address.wxml index ea0720f..ffb4e88 100644 --- a/app/pages/index/address.wxml +++ b/app/pages/index/address.wxml @@ -19,7 +19,7 @@ - + 您的收货地址 @@ -37,7 +37,7 @@ 定位地址 - + {{item.title}} diff --git a/app/pages/index/index.js b/app/pages/index/index.js index 4502d22..861e77f 100644 --- a/app/pages/index/index.js +++ b/app/pages/index/index.js @@ -1,7 +1,7 @@ //index.js //获取应用实例 import { - getCurrentAddress + getCurrentAddress, setCurrentAddress } from '../../utils/util' import { @@ -62,7 +62,7 @@ Page({ initAddress() { var that = this - getCurrentAddress(function(address) { + getCurrentAddress(function (address) { that.setData({ currentAddress: address }) @@ -102,9 +102,25 @@ Page({ } }) }, + invalidateData() { + this.setData({ + page: 0, + hasMore: true, + loading: false, + shopList: null + }) + }, onReachBottom(e) { if (this.data.hasMore) { this.loadData() } }, + callback(address) { + setCurrentAddress(address) + this.setData({ + currentAddress: address + }) + this.invalidateData() + this.loadData() + } }) diff --git a/app/pages/index/index.wxml b/app/pages/index/index.wxml index 167820d..4237d29 100644 --- a/app/pages/index/index.wxml +++ b/app/pages/index/index.wxml @@ -3,9 +3,9 @@ - + {{currentAddress ? currentAddress.title : '定位中...'}} - + 搜索 diff --git a/app/pages/index/index.wxss b/app/pages/index/index.wxss index 9231287..66d7a0f 100644 --- a/app/pages/index/index.wxss +++ b/app/pages/index/index.wxss @@ -13,7 +13,7 @@ .address { position: relative; padding: 3px 15px 3px 5px; - min-width: 40%; + min-width: 100px; max-width: 50%; font-size: 14px; color: #fff; diff --git a/app/pages/shop/show.wxml b/app/pages/shop/show.wxml index 06a8762..5f9c992 100644 --- a/app/pages/shop/show.wxml +++ b/app/pages/shop/show.wxml @@ -161,7 +161,7 @@ - + 商家公告 diff --git a/app/utils/util.js b/app/utils/util.js index 40efd89..aaa943c 100644 --- a/app/utils/util.js +++ b/app/utils/util.js @@ -91,6 +91,10 @@ export function getCurrentAddress(callback) { }) } +export function setCurrentAddress(address) { + currentAddress = address +} + // 获取当前城市 var cityName;