首页地址选择

This commit is contained in:
Kiyan 2017-05-08 14:32:56 +08:00
parent 6013badb61
commit 952c42afdf
8 changed files with 55 additions and 49 deletions

View File

@ -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",

View File

@ -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() {

View File

@ -19,7 +19,7 @@
</view>
</view>
<view wx:else class="content">
<view class="address-box">
<view wx:if="{{addressList && addressList.length > 0}}" class="address-box">
<view class="address-box__title">
<image class="address-box__title-img" src="/images/takeout_ic_account.png"></image> 您的收货地址
</view>
@ -37,7 +37,7 @@
<image class="address-box__title-img" src="/images/takeout_ic_address.png"></image> 定位地址
</view>
<view class="address-list">
<view wx:for="{{poiList}}" wx:key="{{index}}" class="address-item">
<view id="{{index}}" bindtap="onAddressItemTap" wx:for="{{poiList}}" wx:key="{{index}}" class="address-item">
<view class="address-item__addr">{{item.title}}</view>
<block wx:if="{{index == 0}}">
<view class="grey-color text-small">

View File

@ -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()
}
})

View File

@ -3,9 +3,9 @@
<!--index.wxml-->
<view class="topbar">
<view class="address trangle">
<navigator url="./address?cb=callback" class="address trangle">
<image class="address__icon" src="/images/location.png"></image>{{currentAddress ? currentAddress.title : '定位中...'}}
</view>
</navigator>
<view class="search">
<icon type="search" size="20" /> 搜索
</view>

View File

@ -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;

View File

@ -161,7 +161,7 @@
<image class="info__phone-icon" src="/images/chat_phone_normal.png"></image>
</view>
</view>
<view class="weui-cell">
<view wx:if="{{info.notice}}" class="weui-cell">
<view class="weui-cell__hd weui-cell__hd_info">
商家公告
</view>

View File

@ -91,6 +91,10 @@ export function getCurrentAddress(callback) {
})
}
export function setCurrentAddress(address) {
currentAddress = address
}
// 获取当前城市
var cityName;