|
@ -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> |
|
|