nk-shop2.0/pages/select_address/select_address.vue

344 lines
8.6 KiB
Vue
Raw Normal View History

2023-11-16 19:09:57 +08:00
<template>
<view class="">
<u-sticky customNavHeight="0">
<view class="head_top">
<u-search placeholder="搜索小区、办公楼等" :showAction="false"></u-search>
<view style="height: 20rpx;"></view>
2023-11-18 19:02:06 +08:00
<u-tabs :list="tabsList" itemStyle="font-size: 32rpx;height: 74rpx;" :current="current" @change="changeCurrent"
lineColor="#FF6D20" lineWidth="105rpx" height="7rpx"></u-tabs>
2023-11-16 19:09:57 +08:00
</u-tabs>
</view>
</u-sticky>
<view style="background-color: #f4f4f4;height: 30rpx;"></view>
<view class="address-box" v-if="current==0" style="padding: 0;">
<map
style="width: 750rpx;height: 750rpx;"
:longitude="longitude"
:latitude="latitude"
show-location
@controltap="handleMapTap"
></map>
<!-- <Amap></Amap> -->
<view class="head_item" style="padding: 20rpx;">
2023-11-16 19:09:57 +08:00
<view class="re-location">
<view class="re-title">当前位置: </view>
<view>{{street}}</view>
</view>
2023-11-18 19:02:06 +08:00
<view class="re-btn" @click="reGetLocation">
<image class="re-address-img" src="@/static/images/re_address.png"></image>重新定位
</view>
2023-11-16 19:09:57 +08:00
</view>
</view>
<view class="address-box" v-if="current==1">
<view class="head_item_tips">
<view>泸州区县</view>
</view>
<view class="area">
2023-11-18 19:02:06 +08:00
<view class="area-item" :class="{'area-item-on': item.code==area_change}" v-for="(item, index) in areaList"
:key="index" @click="changeArea(item)">
2023-11-17 15:38:38 +08:00
{{item.name}}
</view>
2023-11-16 19:09:57 +08:00
</view>
<view class="head_item_tips">
<view>选择街道/</view>
</view>
2023-11-17 15:38:38 +08:00
<view class="street">
2023-11-18 19:02:06 +08:00
<view class="letter-item" v-for="key in mapKey" :key="key">
<view class="letter">{{key}}</view>
2023-11-17 15:38:38 +08:00
<view class="item-box">
2023-11-18 19:02:06 +08:00
<view class="street-item" v-for="item in mapList[key]" :key="item.code" @click="changeStreet(item)">
2023-11-17 15:38:38 +08:00
{{item.name}}
</view>
</view>
</view>
</view>
2023-11-16 19:09:57 +08:00
</view>
</view>
</template>
<script>
import {
2023-11-18 19:02:06 +08:00
getGeocoder,
merClassifly,
2023-11-16 19:09:57 +08:00
getProductslist
} from '@/api/store.js';
2023-11-17 15:38:38 +08:00
import {
getArea,
getStreet
} from "@/api/article.js";
import { Toast } from '@/libs/uniApi';
// import Amap from "./map.nvue";
2023-11-16 19:09:57 +08:00
export default {
// components:{
// Amap
// },
2023-11-16 19:09:57 +08:00
data() {
return {
tabsList: [{
name: '地图定位',
2023-11-16 19:09:57 +08:00
}, {
name: '泸州区县',
}, ],
current: 0,
latitude: '28.87',
longitude: '105.44',
2023-11-16 19:09:57 +08:00
town: '',
street_id: '',
2023-11-17 15:38:38 +08:00
street: '',
areaList: [],
streetList: [],
2023-11-18 19:02:06 +08:00
mapList: {},
2023-11-17 15:38:38 +08:00
area_change: '',
street_change: '',
2023-11-16 19:09:57 +08:00
}
},
onLoad() {
this.getLoaction();
2023-11-17 15:38:38 +08:00
this.loadArea();
2023-11-16 19:09:57 +08:00
},
onShow() {},
2023-11-18 19:02:06 +08:00
computed: {
mapKey() {
return Object.keys(this.mapList).sort()
}
},
2023-11-16 19:09:57 +08:00
methods: {
2023-11-18 19:02:06 +08:00
changeCurrent(e) {
2023-11-16 19:09:57 +08:00
this.current = e.index;
},
2023-11-18 19:02:06 +08:00
getLoaction() {
2023-11-16 19:09:57 +08:00
this.street = '定位中'
uni.getLocation({
2023-11-18 19:02:06 +08:00
type: 'wgs84',
timeout: '10',
success: (res) => {
let latitude, longitude;
latitude = res.latitude.toString();
longitude = res.longitude.toString();
this.latitude = res.latitude.toFixed(6);
this.longitude = res.longitude.toFixed(6);
2023-11-16 19:09:57 +08:00
this.$store.commit('setLocation', {
2023-11-18 19:02:06 +08:00
lat: res.latitude.toFixed(6),
2023-11-16 19:09:57 +08:00
long: res.longitude.toFixed(6),
});
2023-11-18 19:02:06 +08:00
getGeocoder({
lat: latitude,
long: longitude
}).then(res => {
this.town = res.data.address_reference.town.title
this.street_id = res.data.address_reference.town.id
this.street = res.data.address_reference.town.title;
}).catch(err => {
uni.showToast({
title: err,
icon: 'none'
})
2023-11-16 19:09:57 +08:00
this.street = '定位失败'
2023-11-18 19:02:06 +08:00
})
},
fail: (err) => {
2023-11-16 19:09:57 +08:00
console.log('定位失败');
2023-11-18 19:02:06 +08:00
this.isshow = false
2023-11-16 19:09:57 +08:00
uni.setStorageSync("RejectTarget", true)
Toast('定位失败,请检查定位权限是否开启')
this.street = '定位失败'
2023-11-18 19:02:06 +08:00
// uni.showToast({
// title: "获取定位超时",
// icon: 'none',
// duration: 2000
// });
}
2023-11-16 19:09:57 +08:00
});
2023-11-17 15:38:38 +08:00
},
2023-11-18 19:02:06 +08:00
reGetLocation() {
2023-11-17 15:38:38 +08:00
this.getLoaction()
},
2023-11-18 19:02:06 +08:00
loadArea() {
2023-11-17 15:38:38 +08:00
getArea({
city_code: 510500
2023-11-18 19:02:06 +08:00
}).then((res) => {
2023-11-17 15:38:38 +08:00
this.areaList = res.data;
this.changeArea(this.areaList[0]);
})
},
2023-11-18 19:02:06 +08:00
loadStreet(area_code) {
2023-11-17 15:38:38 +08:00
this.street_change = '';
getStreet({
area_code
2023-11-18 19:02:06 +08:00
}).then((res) => {
2023-11-17 15:38:38 +08:00
this.streetList = res.data;
2023-11-18 19:02:06 +08:00
this.initPinyin();
2023-11-17 15:38:38 +08:00
})
},
2023-11-18 19:02:06 +08:00
initPinyin() {
this.mapList = {};
this.streetList.forEach((item) => {
let str = item.pinyin?.toUpperCase();
str = str ? str : '#';
if (this.mapList[str]) {
this.mapList[str].push(item);
} else {
this.mapList[str] = [];
this.mapList[str].push(item)
}
})
2023-11-18 19:02:06 +08:00
},
changeArea(item) {
2023-11-17 15:38:38 +08:00
this.area_change = item.code;
this.loadStreet(this.area_change);
2023-11-18 19:02:06 +08:00
},
// 选择位置
2023-11-18 19:02:06 +08:00
changeStreet(item){
uni.navigateBack({
success: () => {
uni.$emit('changeAddress', {
area: this.area_change,
street: item
})
}
})
},
// 点击地图
handleMapTap(e){
console.log('点击', e);
2023-11-16 19:09:57 +08:00
}
},
onPullDownRefresh() {
uni.stopPullDownRefresh()
}
}
</script>
<style lang="scss">
2023-11-18 19:02:06 +08:00
page {
2023-11-16 19:09:57 +08:00
background-color: #fff;
}
2023-11-18 19:02:06 +08:00
2023-11-16 19:09:57 +08:00
.head_top {
background-color: #fff;
padding: 28rpx;
}
2023-11-18 19:02:06 +08:00
.address-box {
2023-11-16 19:09:57 +08:00
// background-color: red;
border-radius: 21rpx 21rpx 0rpx 0rpx;
padding: 30rpx 28rpx;
2023-11-18 19:02:06 +08:00
.head_item {
2023-11-16 19:09:57 +08:00
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 28rpx;
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
2023-11-18 19:02:06 +08:00
.re-location {
2023-11-16 19:09:57 +08:00
display: flex;
2023-11-18 19:02:06 +08:00
.re-title {
2023-11-16 19:09:57 +08:00
flex-shrink: 0;
padding-right: 14rpx;
}
}
2023-11-18 19:02:06 +08:00
.re-address-img {
2023-11-16 19:09:57 +08:00
width: 38.55rpx;
height: 38.55rpx;
margin-right: 14rpx;
}
2023-11-18 19:02:06 +08:00
.re-btn {
2023-11-16 19:09:57 +08:00
display: flex;
align-items: center;
flex-shrink: 0;
padding-left: 14rpx;
}
}
2023-11-18 19:02:06 +08:00
.head_item_tips {
2023-11-16 19:09:57 +08:00
height: 44rpx;
font-size: 32rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #737373;
}
2023-11-18 19:02:06 +08:00
.address-list {
2023-11-16 19:09:57 +08:00
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
height: 80rpx;
line-height: 75rpx;
2023-11-18 19:02:06 +08:00
border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
2023-11-16 19:09:57 +08:00
}
2023-11-18 19:02:06 +08:00
.area {
2023-11-16 19:09:57 +08:00
display: flex;
flex-wrap: wrap;
padding-top: 30rpx;
2023-11-18 19:02:06 +08:00
.area-item {
2023-11-16 19:09:57 +08:00
// width: 158rpx;
height: 64rpx;
// background: #F4F4F4;
background-color: #fff;
border-radius: 11rpx 11rpx 11rpx 11rpx;
border: 2rpx solid #B3B3B3;
display: flex;
align-items: center;
justify-content: center;
padding: 0 20rpx;
font-size: 28rpx;
font-family: PingFang SC-Medium, PingFang SC;
font-weight: 500;
color: #737373;
margin-bottom: 22rpx;
margin-right: 22rpx;
}
2023-11-18 19:02:06 +08:00
.area-item-on {
2023-11-17 15:38:38 +08:00
// background-color: #F4F4F4;
color: #ff6d20;
// font-weight: bold;
border: 2rpx solid #ff6d20;
}
}
2023-11-18 19:02:06 +08:00
.street {
2023-11-17 15:38:38 +08:00
padding-top: 28rpx;
2023-11-18 19:02:06 +08:00
.letter-item {
2023-11-17 15:38:38 +08:00
display: flex;
2023-11-18 19:02:06 +08:00
.letter {
2023-11-17 15:38:38 +08:00
flex-shrink: 0;
margin-right: 28rpx;
font-size: 25rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
2023-11-18 19:02:06 +08:00
width: 40rpx;
text-align: center;
2023-11-17 15:38:38 +08:00
color: #737373;
}
2023-11-18 19:02:06 +08:00
.item-box {
flex: 1;
.street-item {
width: 100%;
padding-bottom: 28rpx;
font-size: 28rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 400;
color: #333333;
}
2023-11-17 15:38:38 +08:00
}
2023-11-16 19:09:57 +08:00
}
}
}
</style>