From 9ba35a12b4d8db67ee5b1bfa3f985b5c9b4e522d Mon Sep 17 00:00:00 2001 From: BAKEYi <16298417+bakeyi@user.noreply.gitee.com> Date: Wed, 1 Apr 2026 17:01:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E8=AF=86=E5=88=ABbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/address/search.vue | 4 +- pages/ruzhu/sj-info.vue | 169 +++++++++++++++++++++++++++------------ 2 files changed, 120 insertions(+), 53 deletions(-) diff --git a/pages/address/search.vue b/pages/address/search.vue index 3931abb..fb7a849 100644 --- a/pages/address/search.vue +++ b/pages/address/search.vue @@ -1277,7 +1277,7 @@ return { type: 'toast', - title: removedNoise ? '已识别到部分地址' : '已识别到部分地址,请核对' + title: removedNoise ? '已识别到部分地址,请核对' : '已识别到部分地址,请核对' } } @@ -1290,7 +1290,7 @@ return { type: 'toast', - title: removedNoise ? '识别成功' : '识别成功,请核对' + title: removedNoise ? '识别成功,请核对' : '识别成功,请核对' } }, diff --git a/pages/ruzhu/sj-info.vue b/pages/ruzhu/sj-info.vue index 72cf473..72f1407 100644 --- a/pages/ruzhu/sj-info.vue +++ b/pages/ruzhu/sj-info.vue @@ -915,40 +915,54 @@ export default { // 处理地址选择结果 handleAddressSelected(addressData) { - if (!addressData) return; - - let address = ''; - if (addressData.name) { - address = addressData.name; - } else if (addressData.address) { - address = addressData.address; + if (!addressData) return + + // 详细地址优先取 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() + } + + detailAddress = detailAddress.replace(/^[\s,-]+/, '').trim() } - - if (!address) return; - - 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(); - - // uni.showToast({ - // title: '地址已选择', - // icon: 'none' - // }); + + this.formData.dependency_province = addressData.provinceCode || '' + this.formData.dependency_city = addressData.cityCode || '' + this.formData.dependency_code = addressData.districtCode || '' + + this.saveFormDataToLocal() + this.$forceUpdate() }, @@ -1292,38 +1306,91 @@ export default { this.saveFormDataToLocal(); 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(); - - // 构建URL参数 - let params = 'source=sj_info'; // 用于地址返回 - - // 如果有门店所在地,添加dependency参数 - if (this.formData.dependency) { + this.saveFormDataToLocal() - const locationStr = encodeURIComponent(this.formData.dependency); - params += `&dependency=${locationStr}`; - - if (this.formData.dependency_code) { - params += `&dependency_code=${this.formData.dependency_code}`; + 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() + + const hasDependency = !!dependency + const hasAddress = !!address + const hasLocation = !!(longitude && latitude) + + let params = 'source=sj_info' + + // 已选所在地时,继续把地区传过去 + 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) { - params += `&longitude=${this.formData.longitude}&latitude=${this.formData.latitude}`; + // 已有详细地址时,把纯详细地址传过去,不带省市区 + if (hasAddress) { + 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({ url: `/pages/address/search?${params}` - }); + }) }, // 打开获取消息方式选择器