修改临停缴费页面的选择车辆的布局

This commit is contained in:
赵毅 2025-09-04 11:59:16 +08:00
parent 68839c2447
commit 997502ef01
2 changed files with 48 additions and 36 deletions

View File

@ -179,6 +179,8 @@ page {
/* 车辆下拉列表样式 */ /* 车辆下拉列表样式 */
.car-dropdown { .car-dropdown {
width: 33%; width: 33%;
height: 600rpx;
overflow-y: auto;
background-color: #ffffff; background-color: #ffffff;
border-top: 1rpx solid #f0f0f0; border-top: 1rpx solid #f0f0f0;
position: absolute; position: absolute;

View File

@ -1,9 +1,9 @@
<template> <template>
<view class="monthly-payment-container"> <view class="monthly-payment-container">
<!-- 顶部标题 --> <!-- 顶部标题 -->
<view class="header"> <view class="header" @tap="toggleDropdown">
<text class="header-title">{{ headerTitle }}</text> <text class="header-title">{{ headerTitle }}</text>
<u-icon :name="isDropdownOpen ? 'arrow-up' : 'arrow-down'" size="28" @tap="toggleDropdown"></u-icon> <u-icon :name="isDropdownOpen ? 'arrow-up' : 'arrow-down'" size="28"></u-icon>
</view> </view>
<!-- 下拉停车场列表 --> <!-- 下拉停车场列表 -->
<view v-if="isDropdownOpen" class="parking-list"> <view v-if="isDropdownOpen" class="parking-list">
@ -25,7 +25,7 @@
</view> </view>
<view class="parking-item-right"> <view class="parking-item-right">
<text class="parking-name">{{ park.parking_name }}</text> <text class="parking-name">{{ park.parking_name }}</text>
<text class="parking-distance">{{ getParkDistance(park.lng, park.lat) }}km</text> <text class="parking-distance">{{ park.distance }}km</text>
<text class="parking-address">{{ park.address }}</text> <text class="parking-address">{{ park.address }}</text>
</view> </view>
<view class="parking-selected" v-if="park.isSelected"></view> <view class="parking-selected" v-if="park.isSelected"></view>
@ -194,6 +194,7 @@ export default {
methods: { methods: {
// //
toggleDropdown() { toggleDropdown() {
this.isCarDropdownOpen = false
this.isDropdownOpen = !this.isDropdownOpen; this.isDropdownOpen = !this.isDropdownOpen;
}, },
@ -433,39 +434,48 @@ export default {
// //
getParkList() { getParkList() {
request(apiArr.parkList, "POST", {}).then((res) => { request(apiArr.parkList, "POST", {}).then((res) => {
this.parkingLots = res.parking_list; //
}) this.parkingLots = res.parking_list.map(park => {
},
//
getParkDistance(parkLng, parkLat) {
try { try {
let locationData = uni.getStorageSync('location'); let locationData = uni.getStorageSync('location');
if (!locationData) { if (locationData) {
return '未知';
}
let location = locationData; let location = locationData;
const userLat = location.lat; const userLat = location.lat;
const userLng = location.lng; const userLng = location.lng;
const parkLat = park.lat;
const parkLng = park.lng;
// 使Haversine // 使Haversine
const R = 6371; // const R = 6371; //
const dLat = (parkLat - userLat) * Math.PI / 180; const dLat = (parkLat - userLat) * Math.PI / 180;
const dLng = (parkLng - userLng) * Math.PI / 180; const dLng = (parkLng - userLng) * Math.PI / 180;
const a = const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(userLat * Math.PI / 180) * Math.cos(parkLat * Math.PI / 180) * Math.cos(userLat * Math.PI / 180) * Math.cos(parkLat * Math.PI / 180) *
Math.sin(dLng / 2) * Math.sin(dLng / 2); Math.sin(dLng / 2) * Math.sin(dLng / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = R * c; const distance = (R * c).toFixed(1);
// //
return distance.toFixed(1); return { ...park, distance };
} catch (error) {
console.error('计算距离时出错:', error);
return '未知';
} }
return park;
} catch (error) {
console.error('计算停车场距离时出错:', error);
return park;
}
});
//
this.parkingLots.sort((a, b) => {
//
if (a.distance !== undefined && b.distance !== undefined) {
return a.distance - b.distance;
}
if (a.distance !== undefined) return -1;
if (b.distance !== undefined) return 1;
return 0;
});
})
}, },
}, },
onShow() { onShow() {