地址识别bug
This commit is contained in:
parent
ea3eeac57b
commit
9ba35a12b4
|
|
@ -1277,7 +1277,7 @@
|
|||
|
||||
return {
|
||||
type: 'toast',
|
||||
title: removedNoise ? '已识别到部分地址' : '已识别到部分地址,请核对'
|
||||
title: removedNoise ? '已识别到部分地址,请核对' : '已识别到部分地址,请核对'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1290,7 +1290,7 @@
|
|||
|
||||
return {
|
||||
type: 'toast',
|
||||
title: removedNoise ? '识别成功' : '识别成功,请核对'
|
||||
title: removedNoise ? '识别成功,请核对' : '识别成功,请核对'
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -915,40 +915,54 @@ export default {
|
|||
|
||||
// 处理地址选择结果
|
||||
handleAddressSelected(addressData) {
|
||||
if (!addressData) return;
|
||||
if (!addressData) return
|
||||
|
||||
let address = '';
|
||||
if (addressData.name) {
|
||||
address = addressData.name;
|
||||
} else if (addressData.address) {
|
||||
address = addressData.address;
|
||||
// 详细地址优先取 address,不再优先取完整地址 name
|
||||
let detailAddress = ''
|
||||
if (addressData.address) {
|
||||
detailAddress = String(addressData.address).trim()
|
||||
} else if (addressData.name) {
|
||||
detailAddress = String(addressData.name).trim()
|
||||
|
||||
const regionParts = []
|
||||
if (addressData.pname) regionParts.push(addressData.pname)
|
||||
if (addressData.cityname && addressData.cityname !== addressData.pname) regionParts.push(addressData.cityname)
|
||||
if (addressData.adname) regionParts.push(addressData.adname)
|
||||
|
||||
const regionText = regionParts.join('')
|
||||
const regionTextWithDash = regionParts.join('-')
|
||||
|
||||
if (regionText && detailAddress.indexOf(regionText) === 0) {
|
||||
detailAddress = detailAddress.slice(regionText.length).trim()
|
||||
} else if (regionTextWithDash && detailAddress.indexOf(regionTextWithDash) === 0) {
|
||||
detailAddress = detailAddress.slice(regionTextWithDash.length).trim()
|
||||
}
|
||||
|
||||
if (!address) return;
|
||||
detailAddress = detailAddress.replace(/^[\s,-]+/, '').trim()
|
||||
}
|
||||
|
||||
this.formData.address = address;
|
||||
this.formData.address = detailAddress
|
||||
|
||||
if (addressData.location) {
|
||||
const [longitude, latitude] = addressData.location.split(',');
|
||||
this.formData.longitude = longitude || '';
|
||||
this.formData.latitude = latitude || '';
|
||||
const [longitude, latitude] = String(addressData.location).split(',')
|
||||
this.formData.longitude = longitude || ''
|
||||
this.formData.latitude = latitude || ''
|
||||
}
|
||||
|
||||
if (addressData.pname || addressData.cityname || addressData.adname) {
|
||||
const locationParts = [];
|
||||
if (addressData.pname) locationParts.push(addressData.pname);
|
||||
if (addressData.cityname) locationParts.push(addressData.cityname);
|
||||
if (addressData.adname) locationParts.push(addressData.adname);
|
||||
this.formData.dependency = locationParts.join('-');
|
||||
const locationParts = []
|
||||
if (addressData.pname) locationParts.push(addressData.pname)
|
||||
if (addressData.cityname) locationParts.push(addressData.cityname)
|
||||
if (addressData.adname) locationParts.push(addressData.adname)
|
||||
this.formData.dependency = locationParts.join('-')
|
||||
}
|
||||
|
||||
this.saveFormDataToLocal();
|
||||
this.$forceUpdate();
|
||||
this.formData.dependency_province = addressData.provinceCode || ''
|
||||
this.formData.dependency_city = addressData.cityCode || ''
|
||||
this.formData.dependency_code = addressData.districtCode || ''
|
||||
|
||||
// uni.showToast({
|
||||
// title: '地址已选择',
|
||||
// icon: 'none'
|
||||
// });
|
||||
this.saveFormDataToLocal()
|
||||
this.$forceUpdate()
|
||||
},
|
||||
|
||||
|
||||
|
|
@ -1293,37 +1307,90 @@ export default {
|
|||
this.hideLocationPopup();
|
||||
},
|
||||
|
||||
buildRegionTextForSearch() {
|
||||
const dependency = String(this.formData.dependency || '').trim()
|
||||
if (!dependency) return ''
|
||||
|
||||
const parts = dependency.split('-')
|
||||
const province = parts[0] || ''
|
||||
const city = parts[1] || ''
|
||||
const district = parts[2] || ''
|
||||
|
||||
let regionText = ''
|
||||
if (province) regionText += province
|
||||
if (city && city !== province) regionText += city
|
||||
if (district) regionText += district
|
||||
|
||||
return regionText
|
||||
},
|
||||
|
||||
getAddressValueForSearch() {
|
||||
const rawAddress = String(this.formData.address || '').trim()
|
||||
if (!rawAddress) return ''
|
||||
|
||||
const dependencyText = String(this.formData.dependency || '').trim()
|
||||
const regionText = this.buildRegionTextForSearch()
|
||||
|
||||
let detail = rawAddress
|
||||
|
||||
// 兼容老数据里 address 被存成完整地址的情况
|
||||
if (regionText && detail.indexOf(regionText) === 0) {
|
||||
detail = detail.slice(regionText.length).trim()
|
||||
} else if (dependencyText && detail.indexOf(dependencyText) === 0) {
|
||||
detail = detail.slice(dependencyText.length).trim()
|
||||
}
|
||||
|
||||
detail = detail.replace(/^[\s,-]+/, '').trim()
|
||||
|
||||
return detail || rawAddress
|
||||
},
|
||||
|
||||
// 获取详细地址
|
||||
getAddressInfo() {
|
||||
this.saveFormDataToLocal();
|
||||
this.saveFormDataToLocal()
|
||||
|
||||
// 构建URL参数
|
||||
let params = 'source=sj_info'; // 用于地址返回
|
||||
const dependency = String(this.formData.dependency || '').trim()
|
||||
const dependencyCode = String(this.formData.dependency_code || '').trim()
|
||||
const address = this.getAddressValueForSearch()
|
||||
const longitude = String(this.formData.longitude || '').trim()
|
||||
const latitude = String(this.formData.latitude || '').trim()
|
||||
|
||||
// 如果有门店所在地,添加dependency参数
|
||||
if (this.formData.dependency) {
|
||||
const hasDependency = !!dependency
|
||||
const hasAddress = !!address
|
||||
const hasLocation = !!(longitude && latitude)
|
||||
|
||||
const locationStr = encodeURIComponent(this.formData.dependency);
|
||||
params += `&dependency=${locationStr}`;
|
||||
let params = 'source=sj_info'
|
||||
|
||||
if (this.formData.dependency_code) {
|
||||
params += `&dependency_code=${this.formData.dependency_code}`;
|
||||
// 已选所在地时,继续把地区传过去
|
||||
if (hasDependency) {
|
||||
params += `&dependency=${encodeURIComponent(dependency)}`
|
||||
if (dependencyCode) {
|
||||
params += `&dependency_code=${dependencyCode}`
|
||||
}
|
||||
}
|
||||
|
||||
console.log('传递的地区信息:', this.formData.dependency);
|
||||
console.log('编码后的地区信息:', locationStr);
|
||||
// 已有详细地址时,把纯详细地址传过去,不带省市区
|
||||
if (hasAddress) {
|
||||
params += `&address=${encodeURIComponent(address)}`
|
||||
}
|
||||
|
||||
// 如果有已选择的地址坐标,也传递过去作为初始位置
|
||||
if (this.formData.longitude && this.formData.latitude) {
|
||||
params += `&longitude=${this.formData.longitude}&latitude=${this.formData.latitude}`;
|
||||
// 已有坐标时,继续用已有坐标定位
|
||||
if (hasLocation) {
|
||||
params += `&longitude=${longitude}&latitude=${latitude}`
|
||||
}
|
||||
|
||||
console.log('跳转URL参数:', params);
|
||||
// 完全空白进入时:
|
||||
// 已授权 -> 搜索页按当前定位初始化
|
||||
// 未授权/拒绝 -> 搜索页静默失败后保持所在地、详细地址都为空
|
||||
if (!hasDependency && !hasAddress && !hasLocation) {
|
||||
params += '&init_current_location=1&silent_locate=1'
|
||||
}
|
||||
|
||||
console.log('跳转URL参数:', params)
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/address/search?${params}`
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
// 打开获取消息方式选择器
|
||||
|
|
|
|||
Loading…
Reference in New Issue