fix:修复bug

This commit is contained in:
2026-03-18 09:24:35 +08:00
parent 60df817de5
commit 741769cbeb
14 changed files with 263 additions and 180 deletions
+152 -151
View File
@@ -170,7 +170,7 @@ function handleClickSegmented(index: number) {
deliveryMethod.value = index
// 重置配送类型为预约配送
deliveryTimeType.value = 2
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
}
@@ -205,7 +205,7 @@ function selectedTipChange(item: any) {
if(item.value === selectedTipIndex.value) return
diyTipValue.value = ''
selectedTipIndex.value = item.value
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
// 批量订单:选择某个店铺的小费
@@ -213,7 +213,7 @@ function selectedTipChangeForMerchant(merchantId: string, item: any) {
if(item.value === merchantTipIndexMap.value[merchantId]) return
merchantDiyTipValueMap.value[merchantId] = ''
merchantTipIndexMap.value[merchantId] = item.value
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
// 单个订单的自定义小费确认(金额,单位:美元)
@@ -227,7 +227,7 @@ function handleConfirmTip() {
if (selectedTipIndex.value !== 0) {
selectedTipIndex.value = 0
}
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
// 批量订单:确认某个店铺的自定义小费(金额,单位:美元)
@@ -240,7 +240,7 @@ function handleConfirmTipForMerchant(merchantId: string) {
if (merchantTipIndexMap.value[merchantId] !== 0) {
merchantTipIndexMap.value[merchantId] = 0
}
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
// 是否选择了配送周卡
@@ -249,7 +249,7 @@ const isWeeklyDelivery = ref(false);
const toggleWeeklyDelivery = (value: boolean) => {
if(value === isWeeklyDelivery.value) return
isWeeklyDelivery.value = value;
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
};
// 价格明细
@@ -297,50 +297,67 @@ const formData = ref<CreateOrderCartBo>({
})
// 是否需要餐具
const needTableware = ref(false)
onLoad((options: any)=> {
async function safeAwait<T>(label: string, task: () => Promise<T>): Promise<T | undefined> {
try {
return await task()
} catch (e) {
console.error(`[checkout] ${label} failed`, e)
return undefined
}
}
onLoad(async (options: any)=> {
loading.value = true
// 判断是批量下单还是普通下单
if(options.type == 'batch' && options.cartIds) {
// 批量下单模式
orderType.value = 'batch'
batchCartIds.value = options.cartIds.split(',')
console.log("下单类型",options.type);
// 默认取用户信息中的手机号作为收货手机号
formData.value.phone = userStore.userInfo.phone || ''
contact.value.areaCode = userStore.userInfo.areaCode || ''
// 获取用户地址列表
getAddressList()
// 查询批量购物车详情
getBatchCartInfo()
// 查询用户默认信用卡
appUserCardSelectDefault()
} else if(options.storeId) {
// 普通下单模式
orderType.value = 'normal'
storeId.value = options.storeId as string
formData.value.orderRemark = options.orderRemark as string
needTableware.value = options.needTableware === 'true'
try {
// 判断是批量下单还是普通下单
if(options.type == 'batch' && options.cartIds) {
// 批量下单模式
orderType.value = 'batch'
batchCartIds.value = options.cartIds.split(',')
console.log("下单类型",options.type);
// 默认取用户信息中的手机号作为收货手机号
formData.value.phone = userStore.userInfo.phone || ''
contact.value.areaCode = userStore.userInfo.areaCode || ''
// 获取用户地址列表
getAddressList()
// 查询当前店铺购物车详情
getCartInfo()
// 获取商家详情信息
getStoreDetail()
// 查询用户默认信用卡
appUserCardSelectDefault()
// 默认取用户信息中的手机号作为收货手机号
formData.value.phone = userStore.userInfo.phone || ''
contact.value.areaCode = userStore.userInfo.areaCode || ''
// 严格按顺序执行
await safeAwait('getAddressList', getAddressList)
await safeAwait('getBatchCartInfo', getBatchCartInfo)
await safeAwait('appUserCardSelectDefault', appUserCardSelectDefault)
} else if(options.storeId) {
// 普通下单模式
orderType.value = 'normal'
storeId.value = options.storeId as string
formData.value.orderRemark = options.orderRemark as string
needTableware.value = options.needTableware === 'true'
// 默认取用户信息中的手机号作为收货手机号
formData.value.phone = userStore.userInfo.phone || ''
contact.value.areaCode = userStore.userInfo.areaCode || ''
// 严格按顺序执行
await safeAwait('getAddressList', getAddressList)
await safeAwait('getCartInfo', getCartInfo)
await safeAwait('getStoreDetail', getStoreDetail)
await safeAwait('appUserCardSelectDefault', appUserCardSelectDefault)
}
} finally {
loading.value = false
}
})
onShow(()=> {
// 刷新购物车列表
getAddressList()
onShow(async ()=> {
// 刷新地址,并在必要时重新计算价格
await safeAwait('getAddressList', getAddressList)
const hasCart =
orderType.value === 'batch'
? (batchCartIds.value?.length || 0) > 0
: (cartDataList.value?.length || 0) > 0
if (hasCart) {
await safeAwait('appMerchantOrderCalculatePriceCart', appMerchantOrderCalculatePriceCart)
}
})
// 页面加载状态
@@ -360,24 +377,21 @@ onMounted(() => {
});
const cartDataList = ref<MerchantCartVo[]>([])
function getCartInfo() {
appMerchantCartListByMerchantIdPost({
async function getCartInfo() {
const res: any = await appMerchantCartListByMerchantIdPost({
params: {
merchantId: storeId.value,
}
}).then((res: any)=> {
console.log('购物车列表', res)
cartDataList.value = res.data
// 购物车有菜品,查询菜品会员折扣价
if(cartDataList.value.length > 0) {
appMerchantCartCalculateSavings()
// 查询购物车下单价格
appMerchantOrderCalculatePriceCart()
}
}).finally(()=> {
loading.value = false
})
console.log('购物车列表', res)
cartDataList.value = res.data
// 购物车有菜品,查询菜品会员折扣价 + 计算价格(严格串行)
if(cartDataList.value.length > 0) {
await appMerchantCartCalculateSavings()
await appMerchantOrderCalculatePriceCart()
}
}
// 批量下单:查询购物车详情
@@ -430,30 +444,26 @@ async function getBatchCartInfo() {
cartDataList.value = results.filter(item => item !== null);
console.log('批量模式-最终购物车数据', cartDataList.value);
// 查询菜品会员折扣价
// 批量模式:查询菜品会员折扣价 + 计算价格(严格串行)
if(cartIds.length > 0) {
appMerchantCartCalculateSavings()
// 注意:价格计算会在地址加载完成后自动调用
// 这里不需要立即调用 appMerchantOrderCalculatePriceCart()
await appMerchantCartCalculateSavings()
await appMerchantOrderCalculatePriceCart()
}
} catch (error) {
console.error('获取批量购物车详情失败', error)
cartDataList.value = [];
} finally {
loading.value = false
}
}
// 查询菜品会员折扣价
const cartSavingsData = ref({})
function appMerchantCartCalculateSavings() {
async function appMerchantCartCalculateSavings() {
const cartIds = orderType.value == 'batch' ? batchCartIds.value : cartDataList.value.map(item => item.id)
appMerchantCartCalculateSavingsPost({
const res: any = await appMerchantCartCalculateSavingsPost({
body: cartIds
}).then(res=> {
console.log('菜品会员折扣价', res)
cartSavingsData.value = res.data
})
console.log('菜品会员折扣价', res)
cartSavingsData.value = res.data
}
// 获取商家详情信息
@@ -470,58 +480,56 @@ const storeIsSelfPickup = computed(()=> {
const storeDetail = ref<MerchantVo>({})
// 用户距离商家的距离信息
const storeDistance = ref(null)
function getStoreDetail() {
appMerchantDetailMerchantIdGet({
async function getStoreDetail() {
const res: any = await appMerchantDetailMerchantIdGet({
params: {
merchantId: storeId.value,
}
}).then((res: any) => {
console.log('商家详情', res)
storeDetail.value = res.data as MerchantVo
// 配送时间(是否支持配送)
if(+storeDetail.value.deliveryService === 1) {
// 配送时间
deliveryMinutes.value = res.data.deliveryTime || 0
}
if(+storeDetail.value.selfPickup === 1) {
// 自提时间
selfPickupMinutes.value = res.data.pickupTime
}
// 商户的经纬度存在,并且用户的经纬度也存在
if(res.data.latitude && res.data.longitude && userStore.userLocation.latitude && userStore.userLocation.longitude) {
let distance = getDistanceInMiles(res.data.latitude, res.data.longitude, userStore.userLocation.latitude, userStore.userLocation.longitude)
console.log('距离商家距离', distance)
storeDistance.value = distance
}
// 判断配送和自取的开通状态
const hasDelivery = +storeDetail.value.deliveryService === 1
const hasPickup = +storeDetail.value.selfPickup === 1
if (!hasDelivery && !hasPickup) {
// 两个都没开通,不显示切换组件
showDeliverySwitch.value = false
} else if (!hasDelivery && hasPickup) {
// 只开通自取,默认选中自取
deliveryMethod.value = 1
showDeliverySwitch.value = true
} else if (hasDelivery && !hasPickup) {
// 只开通配送,默认选中配送
deliveryMethod.value = 0
showDeliverySwitch.value = true
} else {
// 两个都开通,默认选中配送
deliveryMethod.value = 0
showDeliverySwitch.value = true
}
}).catch((error) => {
console.error('获取商家详情失败:', error);
})
console.log('商家详情', res)
storeDetail.value = res.data as MerchantVo
// 配送时间(是否支持配送)
if(+storeDetail.value.deliveryService === 1) {
// 配送时间
deliveryMinutes.value = res.data.deliveryTime || 0
}
if(+storeDetail.value.selfPickup === 1) {
// 自提时间
selfPickupMinutes.value = res.data.pickupTime
}
// 商户的经纬度存在,并且用户的经纬度也存在
if(res.data.latitude && res.data.longitude && userStore.userLocation.latitude && userStore.userLocation.longitude) {
let distance = getDistanceInMiles(res.data.latitude, res.data.longitude, userStore.userLocation.latitude, userStore.userLocation.longitude)
console.log('距离商家距离', distance)
storeDistance.value = distance
}
// 判断配送和自取的开通状态
const hasDelivery = +storeDetail.value.deliveryService === 1
const hasPickup = +storeDetail.value.selfPickup === 1
if (!hasDelivery && !hasPickup) {
// 两个都没开通,不显示切换组件
showDeliverySwitch.value = false
} else if (!hasDelivery && hasPickup) {
// 只开通自取,默认选中自取
deliveryMethod.value = 1
showDeliverySwitch.value = true
} else if (hasDelivery && !hasPickup) {
// 只开通配送,默认选中配送
deliveryMethod.value = 0
showDeliverySwitch.value = true
} else {
// 两个都开通,默认选中配送
deliveryMethod.value = 0
showDeliverySwitch.value = true
}
}
const priceData = ref({})
function appMerchantOrderCalculatePriceCart() {
async function appMerchantOrderCalculatePriceCart() {
// 优先使用新选择的地址id
const targetAddressId = selectedAddressId.value || currentAddressId.value
// if(!targetAddressId) return
@@ -561,7 +569,7 @@ function appMerchantOrderCalculatePriceCart() {
}
})
appMerchantOrderCalculatePriceCartBatchPost({
const res: any = await appMerchantOrderCalculatePriceCartBatchPost({
body: {
addressId: targetAddressId,
cartIds: cartIds,
@@ -571,10 +579,9 @@ function appMerchantOrderCalculatePriceCart() {
phone: formData.value.phone,
areaCode: contact.value.areaCode,
}
}).then(res=> {
console.log('批量购物车下单价格', res)
priceData.value = res.data
})
console.log('批量购物车下单价格', res)
priceData.value = res.data
} else {
// 普通模式使用单店铺计算价格接口
// 计算小费金额(美元)
@@ -588,7 +595,7 @@ function appMerchantOrderCalculatePriceCart() {
}
}
appMerchantOrderCalculatePriceCartPost({
const res: any = await appMerchantOrderCalculatePriceCartPost({
body: {
addressId: targetAddressId,
cartIds: cartIds,
@@ -599,10 +606,9 @@ function appMerchantOrderCalculatePriceCart() {
phone: formData.value.phone,
areaCode: contact.value.areaCode,
}
}).then(res=> {
console.log('购物车下单价格', res)
priceData.value = res.data
})
console.log('购物车下单价格', res)
priceData.value = res.data
}
}
@@ -620,36 +626,30 @@ const addressInfo = computed(()=> {
return addressesList.value.find(item => String(item.id) === String(targetId)) || {};
});
function getAddressList() {
appUserAddressListPost({
async function getAddressList() {
const res: any = await appUserAddressListPost({
params: {
pageNum: 1,
pageSize: 100,
}
}).then(res => {
console.log('获取用户地址列表', res)
addressesList.value = res.rows
if(addressesList.value.length > 0) {
currentAddressId.value = addressesList.value[0].id
let data = addressesList.value[0]
// 回显送达偏好(deliveryType: 1-亲自送达 2-放门口)
if(+data.deliveryType === 1) {
visitMethod.value.label = t('components.visit.leaveItToMePersonally')
visitMethod.value.value = 0
}
if(+data.deliveryType === 2) {
visitMethod.value.label = t('components.visit.putItAtTheDoor')
visitMethod.value.value = 1
}
// 如果是批量模式,地址加载完成后重新计算价格
if(orderType.value === 'batch') {
appMerchantOrderCalculatePriceCart()
}
}
})
console.log('获取用户地址列表', res)
addressesList.value = res.rows
if(addressesList.value.length > 0) {
currentAddressId.value = addressesList.value[0].id
let data = addressesList.value[0]
// 回显送达偏好(deliveryType: 1-亲自送达 2-放门口)
if(+data.deliveryType === 1) {
visitMethod.value.label = t('components.visit.leaveItToMePersonally')
visitMethod.value.value = 0
}
if(+data.deliveryType === 2) {
visitMethod.value.label = t('components.visit.putItAtTheDoor')
visitMethod.value.value = 1
}
}
}
function chooseAddress() {
@@ -675,17 +675,18 @@ function chooseAddress() {
}
// 重新计算价格
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
},
},
})
}
function appUserCardSelectDefault() {
appUserCardSelectDefaultPost({}).then(res=> {
return appUserCardSelectDefaultPost({}).then((res: any)=> {
console.log('查询用户默认信用卡', res)
payMethodOptions.value.cardId = res.data?.cardId || ''
payMethodOptions.value.cardNumber = res.data?.cardNumber || ''
return res
})
}
@@ -1078,7 +1079,7 @@ function navigateToCoupon(merchantId?: string) {
couponInfo.value = data
}
// 重新计算价格
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
},
},
@@ -1093,7 +1094,7 @@ function handleClose(merchantId?: string) {
couponInfo.value = null
}
// 重新计算价格
appMerchantOrderCalculatePriceCart()
void appMerchantOrderCalculatePriceCart()
}
</script>