地址识别bug
This commit is contained in:
parent
ea3eeac57b
commit
9ba35a12b4
|
|
@ -1277,7 +1277,7 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'toast',
|
type: 'toast',
|
||||||
title: removedNoise ? '已识别到部分地址' : '已识别到部分地址,请核对'
|
title: removedNoise ? '已识别到部分地址,请核对' : '已识别到部分地址,请核对'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1290,7 +1290,7 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'toast',
|
type: 'toast',
|
||||||
title: removedNoise ? '识别成功' : '识别成功,请核对'
|
title: removedNoise ? '识别成功,请核对' : '识别成功,请核对'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -915,40 +915,54 @@ export default {
|
||||||
|
|
||||||
// 处理地址选择结果
|
// 处理地址选择结果
|
||||||
handleAddressSelected(addressData) {
|
handleAddressSelected(addressData) {
|
||||||
if (!addressData) return;
|
if (!addressData) return
|
||||||
|
|
||||||
let address = '';
|
// 详细地址优先取 address,不再优先取完整地址 name
|
||||||
if (addressData.name) {
|
let detailAddress = ''
|
||||||
address = addressData.name;
|
if (addressData.address) {
|
||||||
} else if (addressData.address) {
|
detailAddress = String(addressData.address).trim()
|
||||||
address = addressData.address;
|
} 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
detailAddress = detailAddress.replace(/^[\s,-]+/, '').trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!address) return;
|
this.formData.address = detailAddress
|
||||||
|
|
||||||
this.formData.address = address;
|
|
||||||
|
|
||||||
if (addressData.location) {
|
if (addressData.location) {
|
||||||
const [longitude, latitude] = addressData.location.split(',');
|
const [longitude, latitude] = String(addressData.location).split(',')
|
||||||
this.formData.longitude = longitude || '';
|
this.formData.longitude = longitude || ''
|
||||||
this.formData.latitude = latitude || '';
|
this.formData.latitude = latitude || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addressData.pname || addressData.cityname || addressData.adname) {
|
if (addressData.pname || addressData.cityname || addressData.adname) {
|
||||||
const locationParts = [];
|
const locationParts = []
|
||||||
if (addressData.pname) locationParts.push(addressData.pname);
|
if (addressData.pname) locationParts.push(addressData.pname)
|
||||||
if (addressData.cityname) locationParts.push(addressData.cityname);
|
if (addressData.cityname) locationParts.push(addressData.cityname)
|
||||||
if (addressData.adname) locationParts.push(addressData.adname);
|
if (addressData.adname) locationParts.push(addressData.adname)
|
||||||
this.formData.dependency = locationParts.join('-');
|
this.formData.dependency = locationParts.join('-')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveFormDataToLocal();
|
this.formData.dependency_province = addressData.provinceCode || ''
|
||||||
this.$forceUpdate();
|
this.formData.dependency_city = addressData.cityCode || ''
|
||||||
|
this.formData.dependency_code = addressData.districtCode || ''
|
||||||
|
|
||||||
// uni.showToast({
|
this.saveFormDataToLocal()
|
||||||
// title: '地址已选择',
|
this.$forceUpdate()
|
||||||
// icon: 'none'
|
|
||||||
// });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1293,37 +1307,90 @@ export default {
|
||||||
this.hideLocationPopup();
|
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() {
|
getAddressInfo() {
|
||||||
this.saveFormDataToLocal();
|
this.saveFormDataToLocal()
|
||||||
|
|
||||||
// 构建URL参数
|
const dependency = String(this.formData.dependency || '').trim()
|
||||||
let params = 'source=sj_info'; // 用于地址返回
|
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参数
|
const hasDependency = !!dependency
|
||||||
if (this.formData.dependency) {
|
const hasAddress = !!address
|
||||||
|
const hasLocation = !!(longitude && latitude)
|
||||||
|
|
||||||
const locationStr = encodeURIComponent(this.formData.dependency);
|
let params = 'source=sj_info'
|
||||||
params += `&dependency=${locationStr}`;
|
|
||||||
|
|
||||||
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 (this.formData.longitude && this.formData.latitude) {
|
if (hasAddress) {
|
||||||
params += `&longitude=${this.formData.longitude}&latitude=${this.formData.latitude}`;
|
params += `&address=${encodeURIComponent(address)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('跳转URL参数:', params);
|
// 已有坐标时,继续用已有坐标定位
|
||||||
|
if (hasLocation) {
|
||||||
|
params += `&longitude=${longitude}&latitude=${latitude}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完全空白进入时:
|
||||||
|
// 已授权 -> 搜索页按当前定位初始化
|
||||||
|
// 未授权/拒绝 -> 搜索页静默失败后保持所在地、详细地址都为空
|
||||||
|
if (!hasDependency && !hasAddress && !hasLocation) {
|
||||||
|
params += '&init_current_location=1&silent_locate=1'
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('跳转URL参数:', params)
|
||||||
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/address/search?${params}`
|
url: `/pages/address/search?${params}`
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 打开获取消息方式选择器
|
// 打开获取消息方式选择器
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue