From 5ef346e40f5b531739df4ce45b649062c51d7b38 Mon Sep 17 00:00:00 2001 From: linxi <957440651@qq.com> Date: Thu, 2 Apr 2026 19:04:22 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A5058=20=E3=80=90=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E3=80=91=E4=BD=93=E9=AA=8C=E5=BA=97?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=EF=BC=8C=E4=BD=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=8B=E6=96=B9=E5=A2=9E=E5=8A=A0=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg_product/views/experienceProjectDetail.vue | 87 +++++++++++++++++-- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/pkg_product/views/experienceProjectDetail.vue b/pkg_product/views/experienceProjectDetail.vue index 73d35a3..69ca3d5 100644 --- a/pkg_product/views/experienceProjectDetail.vue +++ b/pkg_product/views/experienceProjectDetail.vue @@ -44,14 +44,20 @@ - - - {{ project.cityName }}{{ project.address }} - + /> --> + + + {{ project.cityName }}{{ project.address }} + + + + + 距该地{{ distanceText }} + @@ -182,7 +188,10 @@ export default { videoContext: null, swiperAutoplay: true, isVideoPlaying: false, - projectList: [] + projectList: [], + userLatitude: null, + userLongitude: null, + distanceText: '' } }, computed: { @@ -214,6 +223,7 @@ export default { this.validFrom = query.validFrom || '' this.validTo = query.validTo || '' this.usageNotice = decode(query.usageNotice || '') + this.getUserLocation() if (query.detailList) { try { const list = JSON.parse(decode(query.detailList)) @@ -280,6 +290,7 @@ export default { this.project.address = data.address || this.project.address this.project.latitude = data.latitude || this.project.latitude this.project.longitude = data.longitude || this.project.longitude + this.updateDistance() this.project.phone = data.phone || this.project.phone this.project.wechat = data.wechat || this.project.wechat this.project.qualification = data.qualification || this.project.qualification @@ -316,6 +327,50 @@ export default { uni.hideLoading() }) }, + getUserLocation() { + uni.getLocation({ + type: 'gcj02', + success: res => { + this.userLatitude = Number(res.latitude) + this.userLongitude = Number(res.longitude) + this.updateDistance() + } + }) + }, + calculateDistance(lat1, lon1, lat2, lon2) { + if (!lat1 || !lon1 || !lat2 || !lon2) { + return '' + } + const R = 6371 + const dLat = (lat2 - lat1) * Math.PI / 180 + const dLon = (lon2 - lon1) * Math.PI / 180 + const a = + Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * + Math.sin(dLon / 2) * Math.sin(dLon / 2) + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) + const d = R * c + return d.toFixed(1) + 'km' + }, + updateDistance() { + const storeLatitude = Number(this.project.latitude) + const storeLongitude = Number(this.project.longitude) + if ( + this.userLatitude == null || + this.userLongitude == null || + !storeLatitude || + !storeLongitude + ) { + this.distanceText = '' + return + } + this.distanceText = this.calculateDistance( + this.userLatitude, + this.userLongitude, + storeLatitude, + storeLongitude + ) + }, handleNavigate() { if (!this.project.latitude || !this.project.longitude) { uni.showToast({ @@ -443,17 +498,33 @@ export default { .store-meta { margin-top: 32rpx; padding-top: 32rpx; - border-top: 1rpx solid #f0f0f0; + // border-top: 1rpx solid #f0f0f0; display: flex; align-items: center; justify-content: space-between; } .meta-left { flex: 1; - display: flex; + // display: flex; align-items: center; padding-right: 32rpx; } +.meta-info { + display: flex; + flex-direction: column; + row-gap: 8rpx; +} +.distance-row { + margin-left: 4rpx; + display: flex; + align-items: center; + column-gap: 8rpx; +} +.distance-text { + font-size: 22rpx; + color: #666; + margin-top: 8rpx; +} .meta-text { margin-left: 12rpx; font-size: 26rpx;