fix: 修复购物车订单计算报错问题
This commit is contained in:
parent
6f64dafab7
commit
bb47531a2b
|
|
@ -13,7 +13,7 @@ import {
|
|||
BackendCoupon,
|
||||
ActivityConfig,
|
||||
OrderExtraConfig, MerchantReductionConfig, MerchantReductionType,
|
||||
GoodsType,
|
||||
GoodsType, FullReductionActivity
|
||||
} from "@/utils/goods";
|
||||
|
||||
const shopUser = useUserStoreHook();
|
||||
|
|
@ -217,7 +217,7 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
})
|
||||
//使用积分数量
|
||||
const userPoints = ref(0);
|
||||
const testFullReductionActivity = {
|
||||
const testFullReductionActivity: FullReductionActivity = {
|
||||
"id": 231,
|
||||
"shopId": 26,
|
||||
"status": 2, // 2=进行中
|
||||
|
|
@ -229,8 +229,8 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
"useType": "dine,pickup,deliv,express", // 支持所有就餐类型
|
||||
"useDays": "周一,周二,周三,周四,周五,周六,周日", // 全周期
|
||||
"useTimeType": "all", // 全时段
|
||||
"useStartTime": null,
|
||||
"useEndTime": null,
|
||||
"useStartTime": '',
|
||||
"useEndTime": '',
|
||||
"couponShare": 0, // 与优惠券不同享
|
||||
"discountShare": 0, // 与限时折扣不同享
|
||||
"vipPriceShare": 0, // 与会员价不同享
|
||||
|
|
@ -242,7 +242,7 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
"discountAmount": 10 // 减10元
|
||||
}
|
||||
],
|
||||
"isDel": false
|
||||
"isDel": false,
|
||||
};
|
||||
// 订单额外配置(现在依赖响应式的 merchantReduction)
|
||||
const orderExtraConfig = computed<OrderExtraConfig>(() => ({
|
||||
|
|
@ -255,7 +255,9 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
userPoints: userPoints.value,
|
||||
isMember: useVipPrice.value,
|
||||
memberDiscountRate: shopUser.userInfo.memberDiscountRate || 1,
|
||||
fullReductionActivities: [testFullReductionActivity]
|
||||
fullReductionActivities: [testFullReductionActivity],
|
||||
currentDinnerType: dinnerType.value
|
||||
|
||||
}));
|
||||
|
||||
// 营销活动列表
|
||||
|
|
@ -304,6 +306,7 @@ export const useCartsStore = defineStore("carts", () => {
|
|||
const orderCostSummary = computed(() => {
|
||||
allGoods.value = getAllGoodsList();
|
||||
console.log(' allGoods.value', allGoods.value);
|
||||
console.log(' orderExtraConfig.value', orderExtraConfig.value);
|
||||
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
|
||||
allGoods.value,
|
||||
dinnerType.value,
|
||||
|
|
|
|||
|
|
@ -237,7 +237,8 @@ export interface OrderExtraConfig {
|
|||
memberDiscountRate?: number; // 会员折扣率(如0.95=95折,无会员价时用)
|
||||
newUserDiscount?: number; // 新用户减免金额(元,默认0)
|
||||
fullReductionActivities: FullReductionActivity[]; // 当前店铺的满减活动列表(后端返回结构)
|
||||
currentDinnerType: "dine" | "pickup" | "deliv" | "express"; // 当前就餐类型(匹配useType)
|
||||
currentDinnerType: "dine-in" | "take-out" | "take-away" | "post"; // 当前就餐类型(匹配useType)
|
||||
|
||||
}
|
||||
|
||||
/** 订单费用汇总(修改:补充商家减免类型和明细) */
|
||||
|
|
@ -312,7 +313,7 @@ export interface FullReductionActivity {
|
|||
export interface OrderExtraConfig {
|
||||
// ... 原有字段不变 ...
|
||||
fullReductionActivities: FullReductionActivity[]; // 当前店铺的满减活动列表(后端返回结构)
|
||||
currentDinnerType: "dine" | "pickup" | "deliv" | "express"; // 当前就餐类型(匹配useType)
|
||||
currentDinnerType: "dine-in" | "take-out" | "take-away" | "post"; // 当前就餐类型(匹配useType)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -398,7 +399,7 @@ export function filterOptimalFullReductionActivity(
|
|||
currentDinnerType: string,
|
||||
currentTime: Date = new Date()
|
||||
): FullReductionActivity | undefined {
|
||||
if (!activities.length) return undefined;
|
||||
if (!activities || !activities.length) return undefined;
|
||||
console.log("原始满减活动列表:", activities);
|
||||
// 第一步:基础筛选(未删除+当前店铺+活动进行中+就餐类型匹配)
|
||||
const baseEligible = activities.filter(activity => {
|
||||
|
|
@ -1060,7 +1061,6 @@ export function calculateOrderCostSummary(
|
|||
let usedFullReductionActivity: FullReductionActivity | undefined;
|
||||
let usedFullReductionThreshold: FullReductionThreshold | undefined;
|
||||
let fullReductionAmount = 0;
|
||||
|
||||
// 2.1 筛选最优满减活动(后端活动列表、当前店铺、就餐类型、时间)
|
||||
usedFullReductionActivity = filterOptimalFullReductionActivity(
|
||||
config.fullReductionActivities,
|
||||
|
|
|
|||
Loading…
Reference in New Issue