From 7993549bfd65bf54ad0b721b1328d7d348ff8272 Mon Sep 17 00:00:00 2001 From: linxi <957440651@qq.com> Date: Thu, 2 Apr 2026 17:56:22 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A5066=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=88=B8?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=9C=AA=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E4=B8=8E=E8=AF=A5=E4=BD=93=E9=AA=8C=E5=BA=97?= =?UTF-8?q?=E7=9A=84=E8=B7=9D=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/order/MyOrder/index.vue | 89 ++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/pages/order/MyOrder/index.vue b/pages/order/MyOrder/index.vue index a1b6548..794632d 100644 --- a/pages/order/MyOrder/index.vue +++ b/pages/order/MyOrder/index.vue @@ -592,7 +592,9 @@ export default { keyword: '', _orderId: '', showDatePicker: false, - dateRange: [] + dateRange: [], + userLatitude: null, + userLongitude: null } }, components: { @@ -645,6 +647,7 @@ export default { onLoad() { this.type = this.type || parseInt(this.$yroute.query.type) || 0 this.orderTypeTabIndex = parseInt(this.$yroute.query.tabIndex) || 0 + this.initUserLocation() this.orderTypeTabChange({ ...this.orderTypeTabList[this.orderTypeTabIndex], index: this.orderTypeTabIndex @@ -662,6 +665,89 @@ export default { } }, methods: { + initUserLocation() { + uni.getLocation({ + type: 'gcj02', + success: res => { + this.userLatitude = Number(res.latitude) + this.userLongitude = Number(res.longitude) + this.updateOrderDistances() + } + }) + }, + getOrderLocation(order) { + const info = order + const latitude = Number(info.merLatitude || 0) + const longitude = Number( info.merLongitude || 0) + if (!Number.isFinite(latitude) || !Number.isFinite(longitude) || latitude === 0 || longitude === 0) { + return null + } + return { latitude, longitude } + }, + hasValidDistance(distance) { + if (distance == null) { + return false + } + const text = String(distance).trim().toLowerCase() + if (!text || text === '0' || text === '0km' || text === '0.0km') { + return false + } + return true + }, + 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' + }, + updateOrderDistances() { + if (!this.orderList.length || this.userLatitude == null || this.userLongitude == null) { + return + } + this.orderList = this.orderList.map(order => { + if (!order.experienceOrderInfo) { + return order + } + const oldDistance = order.distance || (order.experienceOrderInfo && order.experienceOrderInfo.distance) + if (this.hasValidDistance(oldDistance)) { + return order + } + const location = this.getOrderLocation(order) + console.log(location); + if (!location) { + return order + } + const distance = this.calculateDistance( + this.userLatitude, + this.userLongitude, + location.latitude, + location.longitude + ) + if (!distance) { + return order + } + const experienceOrderInfo = order.experienceOrderInfo + ? { + ...order.experienceOrderInfo, + distance + } + : order.experienceOrderInfo + return { + ...order, + distance, + experienceOrderInfo + } + }) + }, handleDateSelected(dateRange) { const params = { @@ -1027,6 +1113,7 @@ export default { item.showMore = false; }) } + this.updateOrderDistances() this.page++; this.loaded = res.data.length < this.limit this.loading = false