fix delivery fee

This commit is contained in:
Kroytz committed 2026-07-15 23:49:28 +08:00
1 parent 88563423fa
commit be9601ff91
7 files changed
+33 -51

No files matched your search

-5
View File
@@ -5,11 +5,6 @@ export function addressDelete(data) {
return api.post(`/address/del/${data.id}`, undefined, { login: true })
}
// 设置默认地址
export function shopGetDistanceFromLocation(data) {
return api.post(`/address/getDistanceFromLocation`, data, { login: true })
}
// 添加或修改地址
export function getAddressAddAndEdit(data) {
return api.post(`/address/addAndEdit`, data, { login: true })
@@ -41,14 +41,13 @@ import {
import { useMainStore } from '@/store/store'
import { storeToRefs } from 'pinia'
import { onLoad,onShow } from '@dcloudio/uni-app'
import { formatDateTime,prePage } from '@/utils/util'
import {
addressAll,
addressDelete,
shopGetDistanceFromLocation
} from '@/api/address'
import { formatDateTime,prePage } from '@/utils/util'
import {
addressAll,
addressDelete
} from '@/api/address'
const main = useMainStore()
const { isLogin,addresses,store } = storeToRefs(main)
const { isLogin,addresses } = storeToRefs(main)
const title = ref('我的地址')
const scene = ref('menu')
@@ -118,36 +117,16 @@ const chooseAddress = async(address) => {
return;
}
console.log('scene.value:',scene.value)
if (scene.value == 'menu' || scene.value == 'pay') {
let data = await shopGetDistanceFromLocation({
lat: address.latitude,
lng: address.longitude,
lat2: main.store.lat,
lng2: main.store.lng
});
if (!data) {
return;
}
if (parseFloat(data) > store.value.distance) {
uni.showToast({
title: '不在配送范围!',
icon: 'error'
})
return;
}
main.SET_ADDRESS(address)
main.SET_ORDER_TYPE('takeout')
main.store.far = data
main.store.far_text = data + 'km'
main.SET_STORE(main.store)
main.SET_LOCATION({
latitude: address.lat,
longitude: address.lng
});
console.log('scene.value:',scene.value)
if (scene.value == 'menu' || scene.value == 'pay') {
main.SET_ADDRESS(address)
main.SET_ORDER_TYPE('takeout')
main.SET_LOCATION({
latitude: address.latitude,
longitude: address.longitude
});
if (scene.value == 'menu') {
uni.switchTab({
url: '/pages/menu/menu'
@@ -84,6 +84,8 @@ const { orderType,address, store,location,isLogin,member,mycoupon } = storeToRef
const active = ref(false)
const deliveryFee = ref(0)
const outOfRange = ref(false)
const deliveryDistance = ref(0)
const maxDistance = ref(0)
const title = ref('确认订单')
const jsStr = ref('')
const cart = ref([])
@@ -165,12 +167,16 @@ watch([address, store, orderType], async () => {
if (orderType.value !== 'takeout' || !store.value.id) {
deliveryFee.value = 0
outOfRange.value = false
deliveryDistance.value = 0
maxDistance.value = 0
return
}
// 未选地址时显示默认配送费
if (!address.value || !address.value.longitude) {
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
outOfRange.value = false
deliveryDistance.value = 0
maxDistance.value = parseFloat(store.value.distance) || 0
return
}
try {
@@ -181,9 +187,13 @@ watch([address, store, orderType], async () => {
})
outOfRange.value = !!res.outOfRange
deliveryFee.value = parseFloat(res.deliveryPrice) || 0
deliveryDistance.value = parseFloat(res.distanceKm) || 0
maxDistance.value = parseFloat(res.maxDistanceKm) || 0
} catch (e) {
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
outOfRange.value = false
deliveryDistance.value = 0
maxDistance.value = parseFloat(store.value.distance) || 0
}
}, { immediate: true })
@@ -366,7 +376,7 @@ const submit = () => {
const pay = async() => {
// 外卖时校验收货地址是否在配送范围
if (orderType.value == 'takeout' && outOfRange.value) {
uToast.value.show({message:'当前收货地址不在配送范围内',type: 'error'});
uToast.value.show({message:`当前地址距门店${deliveryDistance.value}km,配送范围${maxDistance.value}km`,type: 'error'});
return;
}
let that = this;
@@ -25,7 +25,7 @@
<uv-swiper class="index-banner__swiper" height="300" imgMode="aspectFill" keyName="image" :list="listAds" indicatorMode="dot" indicatorStyle="bottom"></uv-swiper>
<view class="index-banner__intro">
<view class="index-banner__greet">您好,{{ isLogin ? member.nickname : '游客' }}</view>
<view class="index-banner__note">java-springboot-意向点餐外卖系统</view>
<view class="index-banner__note">意向点餐外卖系统</view>
</view>
</view>
<view class="index-content">
+1 -7
View File
@@ -263,7 +263,7 @@ import {
} from '@/api/market'
const main = useMainStore()
const { orderType,address, store,location,isLogin } = storeToRefs(main)
const title = ref('食刻点单')
const title = ref('米糖烘焙')
const text = ref('滚动通知')
const keyword = ref('')
@@ -699,12 +699,6 @@ const toPay = () => {
uToast.value.show({message:'本店不支持外卖',type: 'error'});
return;
}
// 判断当前是否在配送范围内(基于用户定位距离粗略判断,最终以下单时收货地址校验为准)
if (orderType.value == 'takeout' && store.value.dis && store.value.distance < (store.value.dis / 1000)) {
uToast.value.show({message:'选中的地址不在配送范围',type: 'error'});
return;
}
uni.showLoading({
title: '加载中'
})