|
@@ -6,7 +6,7 @@
|
|
|
<!-- 定位城市 -->
|
|
<!-- 定位城市 -->
|
|
|
<view class="city-list-content" id="location_city">
|
|
<view class="city-list-content" id="location_city">
|
|
|
<view class="city-title">定位城市</view>
|
|
<view class="city-title">定位城市</view>
|
|
|
- <view class="city-list city-list-inline" @tap="location">
|
|
|
|
|
|
|
+ <view class="city-list city-list-inline" @tap="changeLocation">
|
|
|
<view class="location-city">{{locationCity}}</view>
|
|
<view class="location-city">{{locationCity}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="location-city-btn" @click="back">
|
|
<view class="location-city-btn" @click="back">
|
|
@@ -62,6 +62,18 @@
|
|
|
getCity:{
|
|
getCity:{
|
|
|
type:Function,
|
|
type:Function,
|
|
|
default:function(){}
|
|
default:function(){}
|
|
|
|
|
+ },
|
|
|
|
|
+ lat:{
|
|
|
|
|
+ type:Number,
|
|
|
|
|
+ default:0
|
|
|
|
|
+ },
|
|
|
|
|
+ lng:{
|
|
|
|
|
+ type:Number,
|
|
|
|
|
+ default:0
|
|
|
|
|
+ },
|
|
|
|
|
+ city:{
|
|
|
|
|
+ type:String,
|
|
|
|
|
+ default:""
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
computed:{
|
|
computed:{
|
|
@@ -174,6 +186,33 @@
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
+ getLocationByCoords(lng, lat){
|
|
|
|
|
+ let That = this;
|
|
|
|
|
+ uni.chooseLocation({
|
|
|
|
|
+ success(res){
|
|
|
|
|
+ console.log(res);
|
|
|
|
|
+ uni.setStorage({
|
|
|
|
|
+ key:"location",
|
|
|
|
|
+ data:[res.longitude,res.latitude]
|
|
|
|
|
+ })
|
|
|
|
|
+ console.log(res.address);
|
|
|
|
|
+ That.locationCity = res && res.address;
|
|
|
|
|
+ That.locationName = res && res.name;
|
|
|
|
|
+ That.selectedCity({city:That.locationCity,name:That.locationName});
|
|
|
|
|
+ },
|
|
|
|
|
+ fail(){
|
|
|
|
|
+ That.locationCity = "定位失败,请点击重试";
|
|
|
|
|
+ That.locationName = "";
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ changeLocation(){
|
|
|
|
|
+ if(this.lat && this.lng){
|
|
|
|
|
+ this.getLocationByCoords(this.lng, this.lat)
|
|
|
|
|
+ }else{
|
|
|
|
|
+ this.location();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
// 滚动条Y距离
|
|
// 滚动条Y距离
|
|
|
scroll(e){
|
|
scroll(e){
|
|
|
this.scrollY = e.detail && e.detail.scrollTop;
|
|
this.scrollY = e.detail && e.detail.scrollTop;
|
|
@@ -195,7 +234,13 @@
|
|
|
this.initCityList();
|
|
this.initCityList();
|
|
|
},
|
|
},
|
|
|
mounted(){
|
|
mounted(){
|
|
|
- this.location();
|
|
|
|
|
|
|
+ // 优先使用传入的经纬度,如果没有再调用定位
|
|
|
|
|
+ console.log(this.lat,this.lng,'经纬度为2222')
|
|
|
|
|
+ if(this.lat && this.lng){
|
|
|
|
|
+ this.getLocationByCoords(this.lng, this.lat)
|
|
|
|
|
+ }else{
|
|
|
|
|
+ this.location();
|
|
|
|
|
+ }
|
|
|
this.initTop();
|
|
this.initTop();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|