更新代客下单
This commit is contained in:
@@ -21,6 +21,9 @@ import {
|
||||
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import { canUseLimitTimeDiscount, returnPrice } from '@/utils/order-utils'
|
||||
import yskUtils from 'ysk-utils'
|
||||
// const limitUtils = yskUtils.limitUtils
|
||||
import limitUtils from './limit'
|
||||
|
||||
const shopUser = useUserStoreHook();
|
||||
export interface CartsState {
|
||||
@@ -37,7 +40,6 @@ interface PointDeductionRule {
|
||||
maxDeductionAmount: number;
|
||||
}
|
||||
|
||||
|
||||
export const useCartsStore = defineStore("carts", () => {
|
||||
// ------------------------------ 1. 移到内部的工具函数(核心修复) ------------------------------
|
||||
// 适配工具库 BaseCartItem 接口的商品数据转换函数(原外部函数,现在内部)
|
||||
@@ -61,13 +63,12 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return {
|
||||
id: item.id,
|
||||
product_id: item.product_id,
|
||||
salePrice: item.salePrice || 0,
|
||||
number: item.number || 0,
|
||||
product_type: productType,
|
||||
is_temporary: !!item.is_temporary,
|
||||
is_gift: !!item.is_gift,
|
||||
returnNum: item.returnNum || 0,
|
||||
memberPrice: item.memberPrice || 0,
|
||||
memberPrice: item.is_time_discount == 1 ? item.limitDiscountPrice : (item.memberPrice || 0),
|
||||
discountSaleAmount: item.discount_sale_amount || 0,
|
||||
packFee: item.packFee || 0,
|
||||
packNumber: item.pack_number || 0,
|
||||
@@ -79,9 +80,9 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
}
|
||||
: undefined,
|
||||
skuData,
|
||||
is_time_discount: item.isTimeDiscount,
|
||||
isTimeDiscount: item.isTimeDiscount,
|
||||
salePrice: item.limitDiscountPrice
|
||||
is_time_discount: item.is_time_discount,
|
||||
isTimeDiscount: item.is_time_discount,
|
||||
salePrice: item.limitDiscountPrice || 0
|
||||
};
|
||||
};
|
||||
|
||||
@@ -97,18 +98,21 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
// console.log('list=====================================', list.value);
|
||||
// console.log('giftList=====================================', giftList.value);
|
||||
// console.log('oldOrder.value.detailMap=====================================', oldOrder.value.detailMap);
|
||||
|
||||
console.log('getAllGoodsList.[]===================', [...currentGoods, ...giftGoods, ...oldOrderGoods])
|
||||
// console.log('getAllGoodsList.[]===================', [...currentGoods, ...giftGoods, ...oldOrderGoods])
|
||||
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
|
||||
};
|
||||
|
||||
const limitDiscountRes = ref(null)
|
||||
const limitDiscountRes = ref<Record<string, any> | null>(null);
|
||||
|
||||
// ------------------------------ 2. Store 内部原有响应式变量 ------------------------------
|
||||
// 选择用户
|
||||
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
|
||||
function changeUser(user: any) {
|
||||
vipUser.value = user;
|
||||
vipUser.value = {
|
||||
...user,
|
||||
isMemberPrice: shopUser.userInfo.isMemberPrice
|
||||
};
|
||||
getGoods({})
|
||||
payParamsInit()
|
||||
}
|
||||
|
||||
@@ -169,9 +173,10 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
})
|
||||
|
||||
// 获取满减活动
|
||||
fullReductionActivities.value = await limitTimeDiscountApi.getDiscountActivity({
|
||||
const fullReductionRes = await limitTimeDiscountApi.getDiscountActivity({
|
||||
shopId: localStorage.getItem("shopId")
|
||||
})
|
||||
});
|
||||
fullReductionActivities.value = fullReductionRes?.data || [];
|
||||
|
||||
if (limitDiscountRes.value !== null) {
|
||||
checkLinkFinished().then(() => {
|
||||
@@ -195,13 +200,41 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
...query,
|
||||
});
|
||||
|
||||
const shopInfo = JSON.parse(localStorage.getItem('userInfo'))
|
||||
goods.value = res.records.map(item => {
|
||||
const shopInfoStr = localStorage.getItem('userInfo') || '{}';
|
||||
const shopInfo = JSON.parse(shopInfoStr);
|
||||
|
||||
interface ProductItem {
|
||||
id: string | number;
|
||||
lowMemberPrice?: number;
|
||||
lowPrice?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface LimitDiscountResult {
|
||||
discountPriority?: 'limit-time' | 'vip-price' | string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface GoodsWithDiscount extends ProductItem {
|
||||
isLimitDiscount: boolean;
|
||||
limitDiscountPrice: number;
|
||||
}
|
||||
|
||||
const shopInfoTyped = shopInfo as Record<string, any>;
|
||||
const ldRes = limitDiscountRes.value as LimitDiscountResult | null;
|
||||
|
||||
goods.value = (res.records as ProductItem[]).map((item: ProductItem): GoodsWithDiscount => {
|
||||
return {
|
||||
...item,
|
||||
isLimitDiscount: limitDiscountRes.value !== null && canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfo, vipUser.value),
|
||||
limitDiscountPrice: limitDiscountRes.value !== null && returnPrice({ goods: { ...item, memberPrice: item.lowMemberPrice, salePrice: item.lowPrice }, shopInfo: shopInfo, limitTimeDiscountRes: limitDiscountRes.value, shopUserInfo: vipUser.value, idKey: 'id' })
|
||||
}
|
||||
isLimitDiscount: ldRes !== null && limitUtils.canUseLimitTimeDiscount(item, ldRes, shopInfoTyped, vipUser.value, 'id'),
|
||||
limitDiscountPrice: limitUtils.returnPrice({
|
||||
goods: { ...item, memberPrice: item.lowMemberPrice, salePrice: item.lowPrice },
|
||||
shopInfo: shopInfoTyped,
|
||||
limitTimeDiscountRes: ldRes,
|
||||
shopUserInfo: vipUser.value,
|
||||
idKey: 'id'
|
||||
})
|
||||
} as GoodsWithDiscount;
|
||||
});
|
||||
|
||||
console.log('代客下单页面商品缓存.goods.value', goods.value);
|
||||
@@ -292,8 +325,7 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
pointsPerYuan: 100,
|
||||
maxDeductionAmount: Infinity
|
||||
})
|
||||
|
||||
const fullReductionActivities = ref([])
|
||||
const fullReductionActivities = ref<any[]>([])
|
||||
|
||||
//使用积分数量
|
||||
const userPoints = ref(0);
|
||||
@@ -364,8 +396,8 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
// 订单费用汇总(调用内部的 getAllGoodsList)
|
||||
const orderCostSummary = computed(() => {
|
||||
allGoods.value = getAllGoodsList();
|
||||
console.log(' allGoods.value+++++++++++++++++++++++++', allGoods.value);
|
||||
console.log(' orderExtraConfig.value', orderExtraConfig.value);
|
||||
console.log('allGoods.value+++++++++++++++++++++++++', allGoods.value);
|
||||
console.log('orderExtraConfig.value', orderExtraConfig.value);
|
||||
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
|
||||
allGoods.value,
|
||||
dinnerType.value,
|
||||
@@ -614,8 +646,6 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
giftList.value = [];
|
||||
cartOrder.value = {};
|
||||
userPoints.value = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
interface GroupSnap {
|
||||
|
||||
Reference in New Issue
Block a user