[更新]
This commit is contained in:
180
pages/switchcity/switchcity.js
Normal file
180
pages/switchcity/switchcity.js
Normal file
@@ -0,0 +1,180 @@
|
||||
// 获取城市
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
winHeight : 0, //可视高度
|
||||
cityList : [], //城市列表
|
||||
adcode : 0, //城市code
|
||||
scrollTop : 0, //置顶高度
|
||||
scrollTopId : '', //置顶id
|
||||
searchLetter: [], //热门城市
|
||||
regionShow : false, //区域显示开关
|
||||
city : '', //城市名称
|
||||
area : '', //区域名称
|
||||
cityName : '', //定位城市名称
|
||||
defaultcity : '', //定位区域名称
|
||||
defaultregi : '', //区域名称
|
||||
regiList : [], //区域列表
|
||||
address : {
|
||||
city_code: "",
|
||||
area_code: ""
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(e) {
|
||||
wx.getLocation({
|
||||
success: res => {
|
||||
// 解析坐标
|
||||
getApp().qqmapsdk.reverseGeocoder({
|
||||
location: {
|
||||
latitude : res.latitude,
|
||||
longitude : res.longitude
|
||||
},
|
||||
success: res=>{
|
||||
this.setData({
|
||||
defaultcity : res.result.ad_info.city,
|
||||
defaultregi : res.result.ad_info.district
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: res => {}
|
||||
})
|
||||
|
||||
if(e.area === '') e.area_code = '0'
|
||||
|
||||
this.setData({
|
||||
address : {
|
||||
area_code: e.area_code,
|
||||
city_code: e.city_code,
|
||||
area: e.area,
|
||||
city: e.city
|
||||
}
|
||||
})
|
||||
|
||||
// 获取全部城市
|
||||
this.local();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onShow() {},
|
||||
|
||||
/**
|
||||
* 全部城市
|
||||
*/
|
||||
local() {
|
||||
wx.$api.index.newCity().then(res=>{
|
||||
this.setData({
|
||||
cityList : res.data
|
||||
})
|
||||
// 获取区级列表
|
||||
this.regilist(this.data.address.city_code)
|
||||
}).catch(err=>{
|
||||
if(!err.login){
|
||||
// 写入缓存
|
||||
wx.setStorage({
|
||||
key : 'token',
|
||||
data : ''
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 城市字母
|
||||
*/
|
||||
clickLetter (e) {
|
||||
var showLetter = e.currentTarget.dataset.letter;
|
||||
this.setData({
|
||||
showLetter : showLetter,
|
||||
isShowLetter: true,
|
||||
scrollTopId : showLetter,
|
||||
})
|
||||
var that = this;
|
||||
setTimeout(function () {
|
||||
that.setData({
|
||||
isShowLetter: false
|
||||
})
|
||||
}, 1000)
|
||||
},
|
||||
|
||||
/**
|
||||
* 选择城市
|
||||
*/
|
||||
bindCity(e) {
|
||||
let stairid = e.currentTarget.dataset.citycode,
|
||||
city = e.currentTarget.dataset.city
|
||||
|
||||
this.setData({
|
||||
address: {
|
||||
city_code: stairid,
|
||||
city: city
|
||||
}
|
||||
})
|
||||
|
||||
// 获取区级列表
|
||||
this.regilist(stairid)
|
||||
},
|
||||
|
||||
/**
|
||||
* 地区列表
|
||||
*/
|
||||
regilist(areaCode) {
|
||||
wx.$api.index.newidxCity(areaCode).then(res=>{
|
||||
res.data.unshift({ code: '0', name:'全部'})
|
||||
this.setData({
|
||||
regiList : res.data
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 选择市区返回
|
||||
*/
|
||||
regionOpt (e) {
|
||||
let area_name = e.currentTarget.dataset.city
|
||||
var pages = getCurrentPages();
|
||||
var prevPage = pages[pages.length - 2];
|
||||
|
||||
if(area_name === '全部') area_name = this.data.address.city
|
||||
|
||||
prevPage.setData({
|
||||
city: area_name
|
||||
})
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 选择定位城市返回
|
||||
*/
|
||||
nowLocation () {
|
||||
var pages = getCurrentPages();
|
||||
var prevPage = pages[pages.length - 2];
|
||||
|
||||
prevPage.setData({
|
||||
cityName: this.data.defaultcity,
|
||||
city : this.data.defaultregi
|
||||
})
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击当前回到顶部
|
||||
*/
|
||||
hotCity () {
|
||||
this.setData({
|
||||
scrollTop: 0,
|
||||
})
|
||||
}
|
||||
})
|
||||
4
pages/switchcity/switchcity.json
Normal file
4
pages/switchcity/switchcity.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "切换城市"
|
||||
}
|
||||
66
pages/switchcity/switchcity.wxml
Normal file
66
pages/switchcity/switchcity.wxml
Normal file
@@ -0,0 +1,66 @@
|
||||
<!-- <view class="searchLetter touchClass">
|
||||
<view class="thishotText" bindtap="hotCity">
|
||||
<view style="margin-top:0;">当前</view>
|
||||
<view style="margin-top:0;">热门</view>
|
||||
</view>
|
||||
<view wx:for="{{searchLetter}}" style="color:#1c74c6;font-size:20rpx;" wx:key="index" data-letter="{{item.name}}"
|
||||
catchtouchend="clickLetter">{{item.name}}</view>
|
||||
</view> -->
|
||||
|
||||
<!-- <view class="weui-search-bar">
|
||||
<view class="weui-search-bar__form">
|
||||
<view class="weui-search-bar__box">
|
||||
<icon class="weui-icon-search_in-box" type="search" size="20"></icon>
|
||||
<input type="text" class="weui-search-bar__input" placeholder="请输入城市名称" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="weui-search-bar__cancel-btn" bindtap='方法名a'>搜索</view>
|
||||
</view> -->
|
||||
|
||||
<block wx:if="{{isShowLetter}}">
|
||||
<view class="showSlectedLetter">
|
||||
{{showLetter}}
|
||||
</view>
|
||||
</block>
|
||||
<view class="hotcity">
|
||||
<view class="hotcity-location" wx:if="{{defaultcity != '' && defaultcity != null}}" bindtap="nowLocation">
|
||||
<image src="/static/icon/location.png"></image>当前定位:<text>{{defaultcity}}{{defaultregi}}</text></view>
|
||||
<view class="hotcity-location" wx:else>
|
||||
当前定位:
|
||||
<button class="location-btn" size="mini" open-type="openSetting">
|
||||
请开启定位服务
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- <view class="hotcity-choice">{{regionShow ? '请选择区域' : '请选择城市'}}</view> -->
|
||||
</view>
|
||||
|
||||
<view class="newLetter">
|
||||
<text>黑龙江省</text>
|
||||
<text>{{address.city}}</text>
|
||||
<text class="active">{{address.area ? address.area : '请选择区域'}}</text>
|
||||
</view>
|
||||
|
||||
<scroll-view class="scrollLeft" scroll-y="true" scroll-into-view="{{scrollTopId}}"
|
||||
scroll-top="{{scrollTop}}">
|
||||
<view class="selection {{address.city_code == item.code ? 'active' : ''}}" wx:for="{{cityList}}" wx:key="cityList" data-cityCode="{{item.code}}" data-city="{{item.name}}" data-index="{{index}}" bindtap="bindCity">
|
||||
<view class="item_city">
|
||||
{{item.name}}<image class="checkImg {{address.city_code == item.code ? 'active' : ''}}" src="/static/icon/Check.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
|
||||
<!-- 区域选择 -->
|
||||
<!-- {{regionShow ? 'active' : ''}}" -->
|
||||
<view class="region">
|
||||
<scroll-view scroll-y="true" style="height:{{winHeight - 88}}px;"
|
||||
scroll-into-view="{{scrollTopId}}" scroll-top="{{scrollTop}}">
|
||||
<view class="selection {{address.area_code == item.code ? 'active' : ''}}" wx:for="{{regiList}}" wx:key="regiList" data-cityCode="{{item.code}}"
|
||||
data-city="{{item.name}}" bindtap="regionOpt">
|
||||
<view class="item_city">
|
||||
{{item.name}}<image class="checkImg {{address.area_code == item.code ? 'active' : ''}}" src="/static/icon/Check.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
399
pages/switchcity/switchcity.wxss
Normal file
399
pages/switchcity/switchcity.wxss
Normal file
@@ -0,0 +1,399 @@
|
||||
page {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.hotcity-top {
|
||||
border-bottom: 20rpx #f5f5f5 solid;
|
||||
}
|
||||
|
||||
.searchLetter {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
width: 50rpx;
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: #666;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.searchLetter view {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.touchClass {
|
||||
background-color: #fff;
|
||||
color: #fff;
|
||||
padding-top: 46rpx;
|
||||
}
|
||||
|
||||
.showSlectedLetter {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: -100rpx;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 52rpx;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.selection {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.selection.active .item_city {
|
||||
color: #e83339;
|
||||
}
|
||||
|
||||
.item_letter {
|
||||
display: flex;
|
||||
background-color: #f5f5f5;
|
||||
height: 60rpx;
|
||||
padding-left: 34rpx;
|
||||
align-items: center;
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item_city {
|
||||
position: relative;
|
||||
display: flex;
|
||||
height: 100rpx;
|
||||
padding-left: 34rpx;
|
||||
align-items: center;
|
||||
border-bottom: 1rpx solid #eaeaea;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.checkImg {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
position: absolute;
|
||||
right: 20rpx;
|
||||
top: 38rpx;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.checkImg.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.thisCityName {
|
||||
display: inline-block;
|
||||
border: 1rpx solid #1c74c6;
|
||||
border-radius: 8rpx;
|
||||
padding: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: #1c74c6;
|
||||
text-align: center;
|
||||
min-width: 149.5rpx;
|
||||
margin: 20rpx 0 20rpx 30rpx;
|
||||
}
|
||||
|
||||
.thishotText {
|
||||
color: #1c74c6;
|
||||
font-size: 20rpx;
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
.slectCity {
|
||||
border-color: #1c74c6 !important;
|
||||
}
|
||||
|
||||
.slectCity view {
|
||||
color: #1c74c6 !important;
|
||||
}
|
||||
|
||||
.weui-grid {
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 10rpx 0;
|
||||
width: 149.5rpx;
|
||||
box-sizing: border-box;
|
||||
border: 1rpx solid #ececec;
|
||||
border-radius: 8rpx;
|
||||
margin: 10rpx 12rpx;
|
||||
}
|
||||
|
||||
.weui-grid__label {
|
||||
display: block;
|
||||
text-align: center;
|
||||
color: #333;
|
||||
font-size: 24rpx;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
/* 热门城市 */
|
||||
|
||||
.searchLetter {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
width: 50rpx;
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: #666;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.searchLetter view {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.touchClass {
|
||||
background-color: #fff;
|
||||
color: #fff;
|
||||
padding-top: 46rpx;
|
||||
}
|
||||
|
||||
.showSlectedLetter {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: -100rpx;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 52rpx;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* 公共标题 */
|
||||
.hotcity {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
background-color: #fff;
|
||||
font-size: 28rpx;
|
||||
height: 90rpx;
|
||||
}
|
||||
|
||||
.hotcity-location {
|
||||
color: #999;
|
||||
padding: 10px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
line-height: 54rpx;
|
||||
}
|
||||
|
||||
.hotcity-location text {
|
||||
color: #1c74c6;
|
||||
display: inline-block;
|
||||
padding: 0 10rpx;
|
||||
font-size: 26rpx;
|
||||
height: 54rpx;
|
||||
line-height: 54rpx;
|
||||
border-radius: 6rpx;
|
||||
margin-left: 10rpx;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.hotcity-location image {
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
margin: 10rpx 10rpx 0 0;
|
||||
}
|
||||
|
||||
.hotcity-choice {
|
||||
padding: 10px 10px 0 10px;
|
||||
box-sizing: border-box;
|
||||
color: #1c74c6;
|
||||
border-top: 1rpx solid #ededed;
|
||||
}
|
||||
|
||||
|
||||
/* 区域选择 */
|
||||
.region {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 178rpx;
|
||||
width: 100%;
|
||||
height: calc(100% - 178rpx);
|
||||
padding-left: 280rpx;
|
||||
box-sizing: border-box;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.region.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.region .item_city {
|
||||
padding-left: 10rpx;
|
||||
}
|
||||
|
||||
.city-name {
|
||||
background: #f5f5f5;
|
||||
line-height: 60rpx;
|
||||
padding: 0 20rpx;
|
||||
box-sizing: border-box;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.region .item_city {
|
||||
padding: 0 0 0 20rpx;
|
||||
box-sizing: border-box;
|
||||
font-weight: normal;
|
||||
font-size: 24rpx;
|
||||
height: 102rpx;
|
||||
}
|
||||
|
||||
/* 开启定位 */
|
||||
.location-btn[size="mini"] {
|
||||
background-color: #ee8e44;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
line-height: 54rpx;
|
||||
margin: 0 0 0 20rpx;
|
||||
}
|
||||
|
||||
/* 搜索框 */
|
||||
.weui-search-bar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
padding: 0 10px;
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
background-color: #f5f5f5;
|
||||
border-top: 1rpx solid #f1f1f1;
|
||||
border-bottom: 1rpx solid #f1f1f1;
|
||||
}
|
||||
|
||||
.weui-icon-search_in-box {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 6px;
|
||||
}
|
||||
|
||||
.weui-search-bar__form {
|
||||
-webkit-box-flex: 1;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
margin-top: 7px;
|
||||
-webkit-flex: auto;
|
||||
flex: auto;
|
||||
border-radius: 5px;
|
||||
background: #FFFFFF;
|
||||
border: 1rpx solid #f1f1f1;
|
||||
}
|
||||
|
||||
.weui-search-bar__box {
|
||||
position: relative;
|
||||
padding-left: 30px;
|
||||
padding-right: 30px;
|
||||
height: 32px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.weui-search-bar__input {
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
font-size: 14px;
|
||||
padding-left: 10rpx;
|
||||
}
|
||||
|
||||
.weui-search-bar__cancel-btn {
|
||||
margin-left: 10px;
|
||||
line-height: 50px;
|
||||
color: #09BB07;
|
||||
white-space: nowrap;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
|
||||
.scrollLeft {
|
||||
position: fixed;
|
||||
top: 178rpx;
|
||||
height: calc(100% - 178rpx);
|
||||
left: 0;
|
||||
width: 260rpx;
|
||||
z-index: 1001;
|
||||
border-right: 1rpx solid #f1f1f1;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
|
||||
.newLetter {
|
||||
position: fixed;
|
||||
top: 90rpx;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
background-color: #fff;
|
||||
z-index: 1001;
|
||||
font-size: 28rpx;
|
||||
padding: 0 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.newLetter::before {
|
||||
position: absolute;
|
||||
content: '';
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 2rpx;
|
||||
background: #f1f1f1;
|
||||
}
|
||||
|
||||
.newLetter::after {
|
||||
position: absolute;
|
||||
content: '';
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 2rpx;
|
||||
background: #f1f1f1;
|
||||
}
|
||||
|
||||
.newLetter text {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
margin-right: 20rpx;
|
||||
padding: 0 10rpx;
|
||||
}
|
||||
|
||||
.newLetter text.active {
|
||||
color: #e83339;
|
||||
}
|
||||
|
||||
.newLetter text.active::before {
|
||||
position: absolute;
|
||||
content: '';
|
||||
left: 0;
|
||||
bottom: -2rpx;
|
||||
width: 100%;
|
||||
height: 4rpx;
|
||||
background: #e83339;
|
||||
}
|
||||
Reference in New Issue
Block a user