Merge branch 'ymf' of https://newgitea.sxczgkj.cn/czg_team/cashier-web into gyq
This commit is contained in:
@@ -31,10 +31,14 @@
|
||||
<!-- 打包费 -->
|
||||
<template v-if="carts.packNum > 0">
|
||||
<div class="cart-title"><span>打包费</span></div>
|
||||
<extra-fee name="打包费" :number="carts.packNum" :price="carts.packFee"></extra-fee>
|
||||
<extra-fee
|
||||
name="打包费"
|
||||
:number="carts.packNum"
|
||||
:price="carts.orderCostSummary.packFee"
|
||||
></extra-fee>
|
||||
</template>
|
||||
<!-- 餐位费 -->
|
||||
<template v-if="perpole >= 1">
|
||||
<template v-if="perpole >= 1 && carts.dinnerType == 'dine-in'">
|
||||
<div class="cart-title"><span>餐位费</span></div>
|
||||
<extra-fee name="餐位费" :number="perpole" :price="canWeiFee"></extra-fee>
|
||||
</template>
|
||||
|
||||
@@ -36,15 +36,15 @@
|
||||
<span class="u-font-14">不使用</span>
|
||||
</el-radio>
|
||||
<el-radio :value="0" :disabled="!pointsRes.usable">
|
||||
<span class="u-font-14">全部抵扣</span>
|
||||
<span class="u-font-14">使用</span>
|
||||
</el-radio>
|
||||
<el-radio :value="1" :disabled="!pointsRes.usable">
|
||||
<!-- <el-radio :value="1" :disabled="!pointsRes.usable">
|
||||
<span class="u-font-14">部分抵扣</span>
|
||||
</el-radio>
|
||||
</el-radio> -->
|
||||
</el-radio-group>
|
||||
<el-input-number
|
||||
class="u-m-l-10"
|
||||
v-if="score.sel == 1"
|
||||
v-if="score.sel != -1"
|
||||
v-model="usePointsNumber"
|
||||
step-strictly
|
||||
:step="pointsRes.equivalentPoints"
|
||||
@@ -168,11 +168,11 @@
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">商品优惠券</span>
|
||||
<span class="u-m-l-10 value">¥{{ productCouponDiscountAmount }}</span>
|
||||
<span class="u-m-l-10 value">-¥{{ productCouponDiscountAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">满减优惠券</span>
|
||||
<span class="u-m-l-10 value">¥{{ fullCouponDiscountAmount }}</span>
|
||||
<span class="title">其他优惠券</span>
|
||||
<span class="u-m-l-10 value">-¥{{ fullCouponDiscountAmount }}</span>
|
||||
</div>
|
||||
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
@@ -253,11 +253,7 @@ function refGuaZhangConfirm(guazhangRen) {
|
||||
function refGuaZhangShow() {
|
||||
refGuaZhang.value.open();
|
||||
}
|
||||
//商品列表
|
||||
let goodsArr = [];
|
||||
|
||||
//优惠券
|
||||
let $goodsPayPriceMap = {};
|
||||
const refCoupon = ref();
|
||||
let quansSelArr = ref([]);
|
||||
function openCoupon() {
|
||||
@@ -276,10 +272,6 @@ function refCouponConfirm(e, goodsList) {
|
||||
title: v.name,
|
||||
};
|
||||
});
|
||||
goodsArr = goodsList;
|
||||
usePointsNumber.value = 0;
|
||||
pointsDiscountAmount.value = 0;
|
||||
score.sel = -1;
|
||||
console.log("refCouponConfirm", e);
|
||||
carts.setCoupons(e);
|
||||
|
||||
@@ -294,7 +286,6 @@ function delQuan(row) {
|
||||
}
|
||||
carts.setCoupons(quansSelArr.value);
|
||||
}
|
||||
function couponChange(data) {}
|
||||
|
||||
//打折
|
||||
const refDiscount = ref();
|
||||
@@ -316,25 +307,40 @@ function discountConfirm(e) {
|
||||
usePointsNumber.value = 0;
|
||||
}
|
||||
|
||||
//计算商家减免前金额
|
||||
// 计算商家减免前金额(使用bignumber.js确保精度)
|
||||
function returnMerchantReductionDiscount() {
|
||||
const {
|
||||
goodsOriginalAmount, // 商品原价总和
|
||||
goodsDiscountAmount, // 减去商品折扣
|
||||
couponDeductionAmount, // 减去优惠券抵扣
|
||||
pointDeductionAmount, // 减去积分抵扣
|
||||
merchantReductionActualAmount, // 减去商家实际减免金额
|
||||
seatFee, // 加上餐位费(不参与减免)
|
||||
packFee, // 加上打包费(不参与减免)
|
||||
goodsDiscountAmount, // 商品折扣
|
||||
couponDeductionAmount, // 优惠券抵扣
|
||||
pointDeductionAmount, // 积分抵扣
|
||||
seatFee, // 餐位费(不参与减免)
|
||||
packFee, // 打包费(不参与减免)
|
||||
additionalFee,
|
||||
} = carts.orderCostSummary;
|
||||
const total =
|
||||
goodsOriginalAmount - // 商品原价总和
|
||||
goodsDiscountAmount - // 减去商品折扣
|
||||
couponDeductionAmount; // 减去优惠券抵扣
|
||||
|
||||
return total <= 0 ? 0 : total;
|
||||
// 将所有金额转换为BigNumber实例
|
||||
const originalAmount = new BigNumber(goodsOriginalAmount);
|
||||
const discountAmount = new BigNumber(goodsDiscountAmount);
|
||||
const couponAmount = new BigNumber(couponDeductionAmount);
|
||||
const pointAmount = new BigNumber(pointDeductionAmount);
|
||||
const seat = new BigNumber(seatFee);
|
||||
const pack = new BigNumber(packFee);
|
||||
const additional = new BigNumber(additionalFee);
|
||||
|
||||
// 按照原逻辑进行精确计算
|
||||
const total = originalAmount
|
||||
.minus(discountAmount) // 减去商品折扣
|
||||
.minus(couponAmount) // 减去优惠券抵扣
|
||||
.minus(pointAmount) // 减去积分抵扣
|
||||
.plus(seat) // 加上餐位费
|
||||
.plus(pack) // 加上打包费
|
||||
.plus(additional); // 加上附加费
|
||||
|
||||
// 确保结果不小于0,返回数字类型
|
||||
return total.lte(0) ? 0 : total.toNumber();
|
||||
}
|
||||
|
||||
function discountShow(e) {
|
||||
refDiscount.value.open({
|
||||
// amount: carts.goodsTotal - productCouponDiscountAmount.value,
|
||||
@@ -399,29 +405,28 @@ const pointsRes = ref({ usable: true, maxUsablePoints: 0, minDeductionPoints: 0
|
||||
const usePointsNumber = ref(0);
|
||||
//积分可抵扣最大金额
|
||||
const scoreMaxMoney = computed(() => {
|
||||
return carts.orderCostSummary.finalPayAmount - carts.orderCostSummary.pointDeductionAmount;
|
||||
return (
|
||||
carts.orderCostSummary.finalPayAmount +
|
||||
carts.orderCostSummary.pointDeductionAmount -
|
||||
carts.orderCostSummary.merchantReduction.actualAmount
|
||||
);
|
||||
});
|
||||
const pointsDiscountAmount = ref(0);
|
||||
watch(
|
||||
() => scoreMaxMoney.value,
|
||||
(newval) => {
|
||||
pointsInit();
|
||||
(newval, oldval) => {
|
||||
if (newval != oldval) {
|
||||
pointsInit();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 返回积分抵扣前金额
|
||||
function returnPointsDiscountAmount() {
|
||||
const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1;
|
||||
return total <= 0 ? 0 : total;
|
||||
}
|
||||
|
||||
async function pointsInit() {
|
||||
if (!props.user.id) {
|
||||
return;
|
||||
}
|
||||
const res = await PointsApi.calcOrderUsablePoints({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: returnPointsDiscountAmount(),
|
||||
orderAmount: scoreMaxMoney.value,
|
||||
});
|
||||
pointsRes.value = res;
|
||||
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
||||
@@ -431,41 +436,17 @@ async function pointsInit() {
|
||||
|
||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||
if (res.usable) {
|
||||
pointsToMoney();
|
||||
} else {
|
||||
score.sel = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// 根据积分计算可抵扣金额
|
||||
async function pointsToMoney() {
|
||||
try {
|
||||
const res = await PointsApi.calcPointsToMoney({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: returnPointsDiscountAmount(),
|
||||
points: usePointsNumber.value,
|
||||
});
|
||||
if (!res) {
|
||||
score.sel = -1;
|
||||
return;
|
||||
}
|
||||
pointsDiscountAmount.value = res;
|
||||
} catch (e) {
|
||||
score.sel = -1;
|
||||
}
|
||||
}
|
||||
|
||||
const emits = defineEmits(["chooseUser", "paysuccess"]);
|
||||
function chooseUser() {
|
||||
emits("chooseUser");
|
||||
}
|
||||
const coupDiscount = computed(() => {
|
||||
const total =
|
||||
props.orderInfo.fullCouponDiscountAmount * 1 + props.orderInfo.productCouponDiscountAmount * 1;
|
||||
if (total <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return total.toFixed(2);
|
||||
});
|
||||
|
||||
const score = reactive({
|
||||
list: [],
|
||||
sel: -1,
|
||||
@@ -480,7 +461,6 @@ watch(
|
||||
(newval) => {
|
||||
console.log(newval);
|
||||
usePointsNumber.value = 0;
|
||||
pointsDiscountAmount.value = 0;
|
||||
pointsInit();
|
||||
}
|
||||
);
|
||||
@@ -521,7 +501,7 @@ function returnPayParams() {
|
||||
orderId: props.orderInfo.id,
|
||||
// discountRatio: (checkOrderPay.discount / 100).toFixed(2),
|
||||
discountRatio: 0,
|
||||
seatNum: props.perpole * 1,
|
||||
seatNum: carts.dinnerType == "dine-in" ? props.perpole * 1 : 0,
|
||||
originAmount: carts.orderCostSummary.goodsRealAmount,
|
||||
discountAmount: discountAmount.value,
|
||||
productCouponDiscountAmount: carts.orderCostSummary.productCouponDeduction,
|
||||
@@ -667,16 +647,6 @@ const productCouponDiscountAmount = computed(() => {
|
||||
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
|
||||
return carts.orderCostSummary.productCouponDeduction;
|
||||
});
|
||||
//除开客座费,打包费总金额
|
||||
const totalMoney = computed(() => {
|
||||
return (
|
||||
carts.goodsTotal -
|
||||
productCouponDiscountAmount.value -
|
||||
discountAmount.value -
|
||||
fullCouponDiscountAmount.value -
|
||||
pointsDiscountAmount.value
|
||||
).toFixed(2);
|
||||
});
|
||||
|
||||
const totalPrice = computed(() => {
|
||||
// 使用bignumber.js处理高精度计算
|
||||
@@ -693,7 +663,10 @@ const totalPrice = computed(() => {
|
||||
.minus(merchantReduction)
|
||||
.minus(pointDeduction)
|
||||
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
|
||||
|
||||
const n = total.toNumber();
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return total.toNumber();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-dialog width="900px" :title="title" v-model="show" top="20px" @close="reset">
|
||||
<el-dialog width="1000px" :title="title" v-model="show" top="20px" @close="reset">
|
||||
<div class="u-p-15">
|
||||
<div class="">
|
||||
<el-tabs v-model="activeName" @tab-click="tabClick">
|
||||
@@ -69,6 +69,12 @@
|
||||
></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="id" width="100" label="ID">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.id }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column type="index" width="50" label="#"></el-table-column>
|
||||
<el-table-column prop="name" label="券名称"></el-table-column>
|
||||
|
||||
@@ -280,6 +286,7 @@ async function getcoup() {
|
||||
|
||||
let noUseGoodsCoupon = [];
|
||||
let noUseDiscountCoupon = [];
|
||||
console.log("orderPrice", orderPrice.value);
|
||||
for (let i = 0; i < couponList.length; i++) {
|
||||
const coupon = couponList[i];
|
||||
const selCoupon =
|
||||
@@ -289,7 +296,7 @@ async function getcoup() {
|
||||
const canuseResult = UTILS.returnCouponCanUse({
|
||||
canDikouGoodsArr,
|
||||
coupon,
|
||||
orderPrice: orderPrice.value,
|
||||
goodsOrderPrice: orderPrice.value,
|
||||
user: props.user,
|
||||
selCoupon,
|
||||
shopInfo: shopUser.userInfo,
|
||||
@@ -323,7 +330,7 @@ async function getcoup() {
|
||||
v,
|
||||
props.user,
|
||||
orderPrice.value,
|
||||
quansSelArr.value,
|
||||
quansSelArr.value.filter((v) => v.type != 2),
|
||||
shopUser.userInfo
|
||||
);
|
||||
return {
|
||||
@@ -339,7 +346,7 @@ async function getcoup() {
|
||||
v,
|
||||
props.user,
|
||||
orderPrice.value,
|
||||
quansSelArr.value,
|
||||
quansSelArr.value.filter((v) => v.type == 2),
|
||||
shopUser.userInfo
|
||||
);
|
||||
return {
|
||||
@@ -426,6 +433,15 @@ function updateSelCoupon() {
|
||||
};
|
||||
});
|
||||
otherCoupon = otherCoupon.map((v) => {
|
||||
const canuseResult = UTILS.returnCouponCanUse({
|
||||
canDikouGoodsArr,
|
||||
coupon: v,
|
||||
orderPrice: orderPrice.value,
|
||||
user: props.user,
|
||||
selCoupon: goodsCoupon,
|
||||
shopInfo: shopUser.userInfo,
|
||||
});
|
||||
|
||||
const discount = UTILS.returnCouponDiscount(
|
||||
canDikouGoodsArr,
|
||||
v,
|
||||
@@ -436,12 +452,35 @@ function updateSelCoupon() {
|
||||
);
|
||||
return {
|
||||
...v,
|
||||
canuseResult,
|
||||
discount,
|
||||
discountAmount: discount ? discount.discountPrice : v.discountAmount,
|
||||
};
|
||||
});
|
||||
couponSel.value = otherCoupon[0];
|
||||
if (!otherCoupon[0].canuseResult.canUse) {
|
||||
couponSel.value = { id: "" };
|
||||
ElMessageBox.confirm(
|
||||
`选择该券后优惠券${otherCoupon[0].name}不可用,不可用原因:${otherCoupon[0].canuseResult.reason}`,
|
||||
"提示",
|
||||
{
|
||||
type: "warning",
|
||||
showCancelButton: true,
|
||||
cancelButtonText: "取消当前券的选择",
|
||||
confirmButtonText: "剔除不可用的优惠券",
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
couponSel.value = { id: "" };
|
||||
goodsCouponSel.value = goodsCoupon[0];
|
||||
})
|
||||
.catch(() => {
|
||||
goodsCouponSel.value = { id: "" };
|
||||
couponSel.value = otherCoupon[0];
|
||||
});
|
||||
return;
|
||||
}
|
||||
goodsCouponSel.value = goodsCoupon[0];
|
||||
couponSel.value = otherCoupon[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user