Browse Source

fix(地址管理): 修复地址定位问题并优化地址解析逻辑

修复地址缺少位置信息时的处理流程,添加重新定位功能
优化地址解析逻辑,支持直辖市和更智能的地址识别
调整地址编辑页面样式和交互流程
master
前端-胡立永 14 hours ago
parent
commit
295a45af90
6 changed files with 169 additions and 46 deletions
  1. +116
    -31
      pages/newOrder/address.vue
  2. +6
    -4
      pages/newOrder/addressList.vue
  3. +25
    -0
      pages/newOrder/petList.vue
  4. +17
    -8
      pages/newOrder/serviceNew.vue
  5. +2
    -0
      store/index.js
  6. +3
    -3
      utils/getUrl.js

+ 116
- 31
pages/newOrder/address.vue View File

@ -66,6 +66,7 @@
data(){ data(){
return{ return{
loading:false, loading:false,
needRelocate: false, //
addressInfo:{ addressInfo:{
name:"", name:"",
phone:"", phone:"",
@ -88,6 +89,7 @@
}, },
onLoad(option) { onLoad(option) {
this.optionType=option.optionType; this.optionType=option.optionType;
this.needRelocate = option.needRelocate === 'true'; //
if(this.optionType=='edit'){ if(this.optionType=='edit'){
this.addressId=option.addressId; this.addressId=option.addressId;
this.getAddressDetails(option.addressId); this.getAddressDetails(option.addressId);
@ -113,20 +115,31 @@
latitude, latitude,
longitude, longitude,
} = res; } = res;
//
const needClearLocation = this.needRelocate || !latitude || !longitude;
this.addressInfo = { this.addressInfo = {
name, name,
phone, phone,
emergencyPhone, emergencyPhone,
province,
city,
district,
province: needClearLocation ? '' : province,
city: needClearLocation ? '' : city,
district: needClearLocation ? '' : district,
detailAddress, detailAddress,
openId, openId,
isDefault, isDefault,
latitude,
longitude,
selectAddress: `${province}${city}${district}`,
latitude: needClearLocation ? '' : latitude,
longitude: needClearLocation ? '' : longitude,
selectAddress: needClearLocation ? '' : `${province}${city}${district}`,
}; };
//
if(needClearLocation) {
setTimeout(() => {
this.$modal.showToast('请重新选择所在地区进行定位');
}, 500);
}
}else{ }else{
this.$modal.showToast('获取地址详情失败') this.$modal.showToast('获取地址详情失败')
} }
@ -142,41 +155,27 @@
this.addressInfo.latitude = res.latitude this.addressInfo.latitude = res.latitude
this.addressInfo.longitude = res.longitude this.addressInfo.longitude = res.longitude
var reg = /.+?(省|市|自治区|自治州|县|区)/g;
//
let address = '' let address = ''
if (!res.address && res.name) { //
if (!res.address && res.name) {
address = res.name address = res.name
}
if (res.address || res.name) {
address = res.address + res.name
} else if (res.address || res.name) {
address = (res.address || '') + (res.name || '')
} }
if(!address){ if(!address){
return return
} }
let arr = address.match(reg)
this.addressInfo.province = arr[0] || ''
this.addressInfo.city = arr[1] || ''
this.addressInfo.district = arr[2] || ''
let detail = arr[2] || arr[1] || arr[0] || ''
this.addressInfo.detailAddress = address.substring(address.indexOf(detail) + detail.length)
this.addressInfo.selectAddress = `${arr[0] || ''}${arr[1] || ''}${arr[2] || ''}`
//
const addressInfo = this.parseAddress(address);
// if (!res.address && res.name) { //
// return this.addressInfo.selectAddress = res.name
// }
// if (res.address || res.name) {
// return this.addressInfo.selectAddress = res.address + res.name
// }
// this.addressInfo.selectAddress = '' //
this.addressInfo.province = addressInfo.province
this.addressInfo.city = addressInfo.city
this.addressInfo.district = addressInfo.district
this.addressInfo.detailAddress = addressInfo.detailAddress
this.addressInfo.selectAddress = addressInfo.selectAddress
}, },
fail(e) { fail(e) {
console.log("获取位置信息失败!", e) console.log("获取位置信息失败!", e)
@ -299,6 +298,92 @@
console.log('groupChange', n); console.log('groupChange', n);
this.addressInfo.isDefault=+(!this.addressInfo.isDefault) this.addressInfo.isDefault=+(!this.addressInfo.isDefault)
}, },
//
parseAddress(address) {
if (!address) {
return {
province: '',
city: '',
district: '',
detailAddress: '',
selectAddress: ''
};
}
//
const municipalities = ['北京市', '上海市', '天津市', '重庆市'];
//
const provinceReg = /(.*?(?:省|自治区|特别行政区))/;
//
const cityReg = /(.*?(?:市|自治州|地区|盟))/;
//
const districtReg = /(.*?(?:区|县|市|旗|自治县|自治旗))/;
let province = '';
let city = '';
let district = '';
let detailAddress = '';
let remainingAddress = address;
//
const municipality = municipalities.find(m => address.includes(m));
if (municipality) {
province = municipality;
city = municipality;
remainingAddress = address.substring(address.indexOf(municipality) + municipality.length);
//
const districtMatch = remainingAddress.match(districtReg);
if (districtMatch) {
district = districtMatch[1];
detailAddress = remainingAddress.substring(districtMatch[0].length).trim();
} else {
detailAddress = remainingAddress.trim();
}
} else {
//
//
const provinceMatch = remainingAddress.match(provinceReg);
if (provinceMatch) {
province = provinceMatch[1];
remainingAddress = remainingAddress.substring(provinceMatch[0].length);
}
//
const cityMatch = remainingAddress.match(cityReg);
if (cityMatch) {
city = cityMatch[1];
remainingAddress = remainingAddress.substring(cityMatch[0].length);
}
//
const districtMatch = remainingAddress.match(districtReg);
if (districtMatch) {
district = districtMatch[1];
remainingAddress = remainingAddress.substring(districtMatch[0].length);
}
detailAddress = remainingAddress.trim();
}
//
if (!province && city) {
province = city;
}
const selectAddress = `${province}${city !== province ? city : ''}${district}`;
return {
province,
city,
district,
detailAddress,
selectAddress
};
}
} }
} }
</script> </script>


+ 6
- 4
pages/newOrder/addressList.vue View File

@ -127,14 +127,16 @@
if(!params.latitude || !params.longitude) { if(!params.latitude || !params.longitude) {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '该地址缺少位置信息,请先编辑地址完善位置信息',
content: '该地址缺少位置信息,需要重新定位,请点击确定重新选择位置',
showCancel: true, showCancel: true,
cancelText: '取消', cancelText: '取消',
confirmText: '去编辑',
confirmText: '重新定位',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
//
this.editAddress(params);
//
uni.navigateTo({
url: `/pages/newOrder/address?optionType=edit&addressId=${params.id}&needRelocate=true`
});
} }
} }
}); });


+ 25
- 0
pages/newOrder/petList.vue View File

@ -193,6 +193,31 @@ export default {
this.getCalendarDate(); this.getCalendarDate();
}, },
methods: { methods: {
//
isAddPrice(){
let currentAddress = this.$globalData.newOrderData.currentAddress || {}
let defaultPrice = 1
try{
defaultPrice = this.price_config.cityConfig.priceRates.default
}catch(e){
defaultPrice = 1
}
if(!this.price_config.cityConfig || !currentAddress.province || !currentAddress.city){
return defaultPrice
}
let addressList = this.price_config.cityConfig.priceRates || []
for(let key in addressList){
if((currentAddress.province + currentAddress.city).includes(key)){
return addressList[key]
}
}
return defaultPrice
},
getPetList() { getPetList() {
this.petList = [] this.petList = []
getPetList().then(res => { getPetList().then(res => {


+ 17
- 8
pages/newOrder/serviceNew.vue View File

@ -53,19 +53,19 @@
</view> </view>
<view class="companion-info-content"> <view class="companion-info-content">
<view class="companion-info-item"> <view class="companion-info-item">
<text class="companion-info-label">等级:</text>
<text class="companion-info-value">{{ showLevelInfo.paramValue }}</text>
<view class="companion-info-label">等级:</view>
<view class="companion-info-value">{{ showLevelInfo.paramValue }}</view>
</view> </view>
<view class="companion-info-item"> <view class="companion-info-item">
<text class="companion-info-label">价格:</text>
<text class="companion-info-value">{{ companionLevelPrice() }}</text>
<view class="companion-info-label">价格:</view>
<view class="companion-info-value">{{ (companionLevelPrice() + basePrice()).toFixed(2) }}</view>
</view> </view>
<view class="companion-info-item"> <view class="companion-info-item">
<text class="companion-info-label">分类标准:</text>
<text class="companion-info-value"
<view class="companion-info-label">分类标准:</view>
<view class="companion-info-value"
v-html="showLevelInfo.paramValueArea" v-html="showLevelInfo.paramValueArea"
> >
</text>
</view>
</view> </view>
</view> </view>
<view class="companion-info-close" @click="closeCompanionInfo"> <view class="companion-info-close" @click="closeCompanionInfo">
@ -283,6 +283,13 @@
this.$store.commit('getUserInfo') this.$store.commit('getUserInfo')
}, },
methods:{ methods:{
basePrice(){
let priceConfig = this.$store.state.price_config
let normal = priceConfig.basePrice && priceConfig.basePrice.normal
let normalNumber = normal * this.$store.state.memberRate * this.isAddPrice()
return isNaN(normalNumber) ? 0 : normalNumber
},
companionLevelPrice(){ companionLevelPrice(){
let price = Number(this.showLevelInfo.paramValueText) * this.isAddPrice() let price = Number(this.showLevelInfo.paramValueText) * this.isAddPrice()
@ -515,11 +522,13 @@
.companion-info-content { .companion-info-content {
.companion-info-item { .companion-info-item {
margin-bottom: 40rpx; margin-bottom: 40rpx;
display: flex;
.companion-info-label { .companion-info-label {
font-size: 28rpx; font-size: 28rpx;
color: #666; color: #666;
margin-right: 10rpx;
width: 136rpx;
flex-shrink: 0;
} }
.companion-info-value { .companion-info-value {


+ 2
- 0
store/index.js View File

@ -90,6 +90,8 @@ const store = new Vuex.Store({
if (state.price_config && key) { if (state.price_config && key) {
state.memberRate = state.price_config.memberDiscount[key] || 1 state.memberRate = state.price_config.memberDiscount[key] || 1
console.log('state.memberRate', state.memberRate);
} }
} }
}) })


+ 3
- 3
utils/getUrl.js View File

@ -1,16 +1,16 @@
let current ="trial";
let current ="release";
const accountInfo = wx.getAccountInfoSync(); const accountInfo = wx.getAccountInfoSync();
// current = accountInfo.miniProgram.envVersion; // current = accountInfo.miniProgram.envVersion;
const api={ const api={
develop:"http://127.0.0.1:8002",
develop:"http://127.0.0.1:8080",
// develop:"http://h5.xzaiyp.top", // develop:"http://h5.xzaiyp.top",
// develop:"https://api.catmdogd.com/prod-api", // develop:"https://api.catmdogd.com/prod-api",
// develop:"https://api-test.catmdogd.com/test-api", // develop:"https://api-test.catmdogd.com/test-api",
trial:"https://pet-admin.hhlm1688.com/api", trial:"https://pet-admin.hhlm1688.com/api",
// release:"https://api.catmdogd.com",
release:"https://api.catmdogd.com/prod-api",
} }
const currentUrl = api[current]; const currentUrl = api[current];

Loading…
Cancel
Save