连云港陪玩陪聊
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chunwan/pages/index/city.vue

153 lines
3.5 KiB

3 months ago
<template>
<view class="city">
<view class="city-hd">
<view class="a" @click="openPage(1)">
2 months ago
{{city}}<image src="@/static/city-arrow.png"></image>
3 months ago
</view>
<view class="b" @click="openPage(2)">请输入</view>
</view>
<view class="city-bd">
2 months ago
<view class="fl">当前定位<text>{{jingweiInfo.formatted}}</text></view>
<view class="fr" @click="getLocation()">
3 months ago
<image src="@/static/city-reset.png"></image>重新定位
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
2 months ago
jingweiInfo: {},
city:""
3 months ago
};
},
2 months ago
onReady() {
2 months ago
const that = this;
that.jingweiInfo = uni.getStorageSync("jingweiInfo");
1 month ago
that.city = this.jingweiInfo.new_city?this.jingweiInfo.new_city:this.jingweiInfo.city;
2 months ago
console.log(uni.getStorageSync("jingweiInfo"))
1 month ago
uni.$on("clickTap", res=>{
console.log(res)
2 months ago
that.jingweiInfo.formatted = res.name
that.jingweiInfo.latitude = res.latitude
that.jingweiInfo.longitude = res.longitude
});
uni.$on("watchCity", res=>{
1 month ago
that.city = res.name
2 months ago
});
2 months ago
},
3 months ago
methods: {
2 months ago
getLocation() {
const that = this;
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
success(res1) {
let latitude = res1.latitude,longitude = res1.longitude;
let url = `https://restapi.amap.com/v3/geocode/regeo?output=json&location=${longitude},${latitude}&key=4a6e2ba8eac3864f0d88f9b5abd026e6&radius=1000`
uni.request({
url,
success(res) {
console.log("地址解析")
if(res.data.regeocode.addressComponent){
let city = res.data.regeocode.addressComponent.city.length==0?res.data.regeocode.addressComponent.province:res.data.regeocode.addressComponent.city
that.city = that.city = res.data.regeocode.formatted_address.split(res.data.regeocode.addressComponent.township)[1]
uni.setStorageSync("jingweiInfo",{...res1,...res.data.regeocode.addressComponent,formatted: that.city});
}
}
})
}
})
},
3 months ago
openPage(index){
if(index == 1){
uni.navigateTo({
url: "/pages/index/cityList"
})
}else if(index == 2){
uni.navigateTo({
2 months ago
url: "/pages/index/citySearch?city="+this.city
3 months ago
})
2 months ago
// uni.chooseLocation({
// keyword: "",
// latitude: this.jingweiInfo.latitude,
// longitude: this.jingweiInfo.longitude,
// success(res) {
// console.log(res)
// }
// })
3 months ago
}
}
}
}
</script>
<style scoped lang="scss">
.city{
2 months ago
min-height: 100vh;
background-color: #fff;
3 months ago
padding: 0 25rpx;
overflow: hidden;
&-hd{
margin-top: 30rpx;
height: 90rpx;
background: #F5F5F5;
border-radius: 90rpx;
border: 1px solid #EAEAEA;
padding: 0 30rpx;
box-sizing: border-box;
display: flex;
align-items: center;
.a{
font-weight: 500;
font-size: 28rpx;
color: #222222;
display: flex;
align-items: center;
image{
width: 22rpx;
height: 22rpx;
margin-left: 13rpx;
}
}
.b{
flex: 1;
font-weight: 500;
font-size: 28rpx;
color: #999999;
margin-left: 50rpx;
}
}
&-bd{
margin-top: 40rpx;
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 500;
font-size: 26rpx;
color: #222222;
.fl{
flex: 1;
max-width: 500rpx;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
text{
color: #999999;
}
}
.fr{
display: flex;
align-items: center;
image{
width: 30rpx;
height: 30rpx;
margin-right: 10rpx;
}
}
}
}
</style>