fix: 代客下单修改
This commit is contained in:
@@ -3,7 +3,9 @@ import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket";
|
||||
import orderApi from "@/api/order/order";
|
||||
import { useUserStoreHook } from "@/store/modules/user";
|
||||
import productApi from "@/api/product/index";
|
||||
|
||||
import * as UTILS from "@/utils/coupon-utils.js";
|
||||
import { BigNumber } from "bignumber.js";
|
||||
import _ from "lodash";
|
||||
// 导入工具库及相关类型
|
||||
import {
|
||||
OrderPriceCalculator,
|
||||
@@ -212,6 +214,7 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
pointsPerYuan: 100,
|
||||
maxDeductionAmount: Infinity
|
||||
})
|
||||
//使用积分数量
|
||||
const userPoints = ref(0);
|
||||
// 订单额外配置(现在依赖响应式的 merchantReduction)
|
||||
const orderExtraConfig = computed<OrderExtraConfig>(() => ({
|
||||
@@ -231,26 +234,50 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return [];
|
||||
});
|
||||
|
||||
const coupons = ref<BackendCoupon[]>([]);
|
||||
function setCoupons(cps: BackendCoupon[]) {
|
||||
console.log('setCoupons', cps);
|
||||
let goodsCoupon = cps.filter((v) => v.type == 2);
|
||||
let otherCoupon = cps.filter((v) => v.type != 2);
|
||||
const canDikouGoodsArr = UTILS.returnCanDikouGoods(allGoods.value, [], vipUser.value);
|
||||
//商品订单金额
|
||||
const goodsOrderPrice = new BigNumber(orderCostSummary.value.goodsOriginalAmount)
|
||||
.minus(orderCostSummary.value.goodsDiscountAmount)
|
||||
.toFixed(2);
|
||||
goodsCoupon = goodsCoupon.map((v) => {
|
||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, vipUser.value, goodsOrderPrice, [], shopUser.userInfo);
|
||||
return {
|
||||
...v,
|
||||
discount,
|
||||
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
||||
};
|
||||
});
|
||||
otherCoupon = otherCoupon.map((v) => {
|
||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, vipUser.value, goodsOrderPrice, goodsCoupon, shopUser.userInfo);
|
||||
return {
|
||||
...v,
|
||||
discount,
|
||||
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
||||
};
|
||||
});
|
||||
coupons.value = cps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 优惠券列表
|
||||
const backendCoupons = computed<BackendCoupon[]>(() => {
|
||||
return coupons.value;
|
||||
});
|
||||
const coupons = ref<BackendCoupon[]>([]);
|
||||
|
||||
|
||||
// 商品加入购物车顺序
|
||||
const cartOrder = ref<Record<string, number>>({});
|
||||
|
||||
let allGoods = ref<BaseCartItem[]>([]);
|
||||
// 订单费用汇总(调用内部的 getAllGoodsList)
|
||||
const orderCostSummary = computed(() => {
|
||||
const allGoods = getAllGoodsList();
|
||||
allGoods.value = getAllGoodsList();
|
||||
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
|
||||
allGoods,
|
||||
allGoods.value,
|
||||
dinnerType.value,
|
||||
backendCoupons.value,
|
||||
coupons.value,
|
||||
activityList.value,
|
||||
orderExtraConfig.value,
|
||||
cartOrder.value,
|
||||
@@ -714,6 +741,12 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
WebSocketManager.sendMessage(msg);
|
||||
}
|
||||
|
||||
function payParamsInit() {
|
||||
coupons.value = []
|
||||
clearMerchantReduction()
|
||||
userPoints.value = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
disconnect,
|
||||
dinnerType,
|
||||
@@ -764,8 +797,11 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
clearMerchantReduction,
|
||||
seatFeeConfig,
|
||||
pointDeductionRule,
|
||||
//使用积分数量
|
||||
userPoints,
|
||||
setCoupons
|
||||
coupons,
|
||||
setCoupons,
|
||||
payParamsInit
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user