对接新版结算

This commit is contained in:
gyq
2025-10-13 11:15:47 +08:00
parent b3b788d8d4
commit aabbeced98
19 changed files with 10770 additions and 719 deletions

View File

@@ -4,21 +4,24 @@
<div class="left">
<div class="t1">
<span class="title">应收:</span>
<span class="num">{{ money }}</span>
<div class="clear" v-if="money != props.amount" @click="emit('reset')">
<span class="num">{{ formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount || 0) }}</span>
<!-- <div class="clear" v-if="money != props.amount" @click="emit('reset')">
<span style="margin-left: 10px;">清除优惠</span>
<el-icon style="margin-left: 6px">
<CircleClose />
</el-icon>
</div>
</div> -->
</div>
<div class="t2">
<span>原价:{{ originOrderAmount }}</span>
<span>餐位费:{{ formatDecimal(+goodsStore.tableInfo.tableFee || 0) }}</span>
<span>打包费:{{ formatDecimal(+goodsStore.cartInfo.packFee || 0) }}</span>
<span>优惠:{{ formatDecimal(props.amount - money) }}</span>
<span v-if="discountRateVlaue">
<span>折扣:{{ discountRateVlaue }}</span>
<span>原价:{{ goodsStore.cartInfo.costSummary.goodsOriginalAmount }}</span>
<span>餐位费:{{ formatDecimal(goodsStore.cartInfo.costSummary.goodsOriginalAmount.seatFee || 0)
}}</span>
<span>打包费:{{ formatDecimal(goodsStore.cartInfo.costSummary.goodsOriginalAmount.packFee || 0)
}}</span>
<span>优惠:{{ formatDecimal(goodsStore.cartInfo.costSummary.goodsOriginalAmount -
goodsStore.cartInfo.costSummary.finalPayAmount) }}</span>
<span v-if="goodsStore.cartInfo.costSummary.goodsDiscountAmount">
<span>折扣:{{ goodsStore.cartInfo.costSummary.goodsDiscountAmount }}</span>
</span>
</div>
</div>
@@ -44,7 +47,8 @@
</div> -->
</div>
<div class="input_wrap">
<div class="input" style="flex: 1">付款{{ money }}</div>
<div class="input" style="flex: 1">付款{{ formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount
|| 0) }}</div>
<el-button type="primary" style="width: 120px;border-radius: 6px; height: 60px;"
@click="showCouponHandle">添加优惠</el-button>
</div>
@@ -119,8 +123,8 @@
<el-pagination layout="prev, pager, next, total" background style="margin-top: 20px"
:total="Number(buyerTable.total)" v-model:current-page="buyerTable.page" @current-change="getBuyerList" />
</el-dialog>
<el-dialog v-model="showCoupon" :title="`添加优惠(¥${originOrderAmount}`" @open="couponDialogOpen"
@closed="resetCouponFormHandle" top="5vh" width="80%">
<el-dialog v-model="showCoupon" :title="`添加优惠(¥${formatDecimal(goodsStore.cartInfo.costSummary.goodsRealAmount)}`"
@open="couponDialogOpen" @closed="resetCouponFormHandle" top="5vh" width="80%">
<div class="coupom_dialog">
<el-form ref="couponFormRef" :model="couponForm" label-width="100" label-position="left">
<el-form-item label="选择会员">
@@ -146,8 +150,7 @@
<el-button type="primary"
:disabled="!couponFormUser.id && (!couponResList1.length && !couponResList2.length)"
@click="showCounponModalHandle">选择优惠券</el-button>
<div>
<div class="title">优惠券</div>
<div style="padding-top: 20px;">
<el-table :data="couponResList1" border stripe>
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="抵扣" prop="discountAmount"></el-table-column>
@@ -161,14 +164,14 @@
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
<!-- <el-table-column label="操作" width="110" align="center">
<el-table-column label="操作" width="110" align="center">
<template v-slot="scope">
<el-button type="danger" @click="delCoupon(scope.$index, 1)">删除</el-button>
</template>
</el-table-column> -->
</el-table-column>
</el-table>
</div>
<div>
<!-- <div>
<div class="title">商品券</div>
<el-table :data="couponResList2" border stripe>
<el-table-column label="名称" prop="name"></el-table-column>
@@ -187,19 +190,19 @@
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
<!-- <el-table-column label="操作" width="110" align="center">
<el-table-column label="操作" width="110" align="center">
<template v-slot="scope">
<el-button type="danger" @click="delCoupon(scope.$index, 2)">删除</el-button>
</template>
</el-table-column> -->
</el-table-column>
</el-table>
</div>
</div> -->
</div>
</el-form-item>
<el-form-item label="积分抵扣">
<div class="flex">
<el-input v-model="couponForm.pointsNum"
:disabled="!couponFormUser.id || !pointOptions.usable || couponForm.amount < pointOptions.minPaymentAmount"
:disabled="!couponFormUser.id || !pointOptions.usable || goodsStore.cartInfo.costSummary.finalPayAmount < pointOptions.minPaymentAmount"
:placeholder="pointOptions.usable ? '请输入需要抵扣的积分' : pointOptions.unusableReason"
v-loading="pointOptions.loading" @input="pointInput">
<template #prepend>现有积分{{ couponFormUser.accountPoints || 0 }}</template>
@@ -208,7 +211,8 @@
<el-button type="danger" @click="clearPoint">清除</el-button>
</div>
<div class="point_tips err"
v-if="couponFormUser.id && couponForm.amount < pointOptions.minPaymentAmount">注意订单金额不足{{
v-if="couponFormUser.id && goodsStore.cartInfo.costSummary.finalPayAmount < pointOptions.minPaymentAmount">
注意订单金额不足{{
formatDecimal(+pointOptions.minPaymentAmount) }}无法使用积分抵扣
</div>
</el-form-item>
@@ -217,10 +221,11 @@
<div class="dialog_footer">
<div class="result">
优惠完
<span class="i"></span> <span class="n">{{ formatDecimal(+couponForm.amount) }}</span>
<span class="i"></span> <span class="n">{{
formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount) }}</span>
</div>
<div class="btn">
<el-button @click="showCoupon = false">取消</el-button>
<el-button @click="cancelAllDiscount">取消</el-button>
<el-button type="primary" @click="discountConfirm">确定</el-button>
</div>
</div>
@@ -279,9 +284,9 @@ const props = defineProps({
const discountAmount = ref(null)
watch(props, () => {
money.value = formatDecimal(props.amount)
originOrderAmount.value = formatDecimal(props.amount - (goodsStore.tableInfo.tableFee || 0) -
(goodsStore.cartInfo.packFee || 0))
money.value = formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount)
// originOrderAmount.value = formatDecimal(props.amount - (goodsStore.tableInfo.tableFee || 0) -
// (goodsStore.cartInfo.packFee || 0))
})
const originOrderAmount = ref(0)
@@ -397,11 +402,16 @@ async function vipPayAjax(row) {
// 切换支付类型
async function payTypeChange(index, item) {
try {
console.log(item);
// await staffPermission('yun_xu_shou_kuan')
// if (item.disabled) return
payActive.value = index;
payType.value = item.payType;
upadatePayData()
if (item.payType == "scanCode") {
scanModalRef.value.show();
}
@@ -424,6 +434,28 @@ async function payTypeChange(index, item) {
}
}
// 更新支付参数
function upadatePayData() {
payData.value.checkOrderPay = {
orderId: goodsStore.orderListInfo.id,
vipPrice: store.shopInfo.isMemberPrice ? goodsStore.showVipPrice : 0, // 是否使用会员价
allPack: goodsStore.allSelected, // 是否整单打包
userId: goodsStore.vipUserInfo.userId || '',
seatNum: goodsStore.tableInfo.num, // 用餐人数
originAmount: formatDecimal(goodsStore.cartInfo.costSummary.goodsRealAmount), // 订单原金额(包含打包费+餐位费) 不含折扣价格
discountRatio: 1, // 折扣比例(计算时 向上取整保留 两位小数)
discountAmount: discountRateNumber.value, // 手动优惠金额
productCouponDiscountAmount: goodsStore.cartInfo.costSummary.productCouponDeduction, //商品优惠券抵扣金额
otherCouponDiscountAmount: goodsStore.cartInfo.costSummary.fullCouponDeduction, //其他优惠券抵扣金额
couponList: couponResList1.value.map(item => item.id), // 用户使用的卡券
orderAmount: goodsStore.cartInfo.costSummary.finalPayAmount, // 订单金额
roundAmount: goodsStore.cartInfo.costSummary.goodsDiscountAmount, // 抹零金额 减免多少钱
pointsDiscountAmount: goodsStore.cartInfo.costSummary.pointDeductionAmount, // 积分抵扣金额(tb_points_basic_setting表)
pointsNum: goodsStore.cartInfo.costSummary.pointUsed, // 使用的积分数量 (扣除各类折扣 enable_deduction后使用)
isPrint: 1
}
}
// 结算支付
async function confirmOrder() {
try {
@@ -433,6 +465,11 @@ async function confirmOrder() {
})
if (payLoading.value) return
// await staffPermission("yun_xu_shou_kuan");
upadatePayData()
payType.value = payList.value[payActive.value].payType
if (payList.value[payActive.value].payType == "arrears") {
showBuyerHandle();
return
@@ -533,7 +570,7 @@ async function queryPayTypeAjax() {
const res = await getPayType();
res.map((item) => {
if (props.amount <= 0 && item.payType == "scanCode") {
if (goodsStore.cartInfo.costSummary.finalPayAmount <= 0 && item.payType == "scanCode") {
item.disabled = true;
} else {
item.disabled = false;
@@ -569,6 +606,7 @@ const pointOptions = ref({
usable: true,
unusableReason: '',
amount: 0,
equivalentPoints: '',
loading: false
})
@@ -589,12 +627,23 @@ const resetCouponForm = ref('')
function clearCouponUser() {
couponFormUser.value = ''
couponFormUserList.value = []
goodsStore.showVipPrice = 0
goodsStore.vipUserInfo = ''
couponForm.value.pointsNum = ''
couponForm.value.discountRatio = ''
discountRateNumber.value = 0
updateCartCalc()
resetCouponFormHandle()
}
// 折扣格式化
const discountRateNumber = ref(0)
const discountInput = _.debounce(function (e) {
couponForm.value.amount = couponForm.value.originAmount
// couponForm.value.amount = couponForm.value.originAmount
couponForm.value.discountRatio = inputFilterFloat(e)
if (couponForm.value.discountRatio > 9.9) {
couponForm.value.discountRatio = 9.9
@@ -604,18 +653,43 @@ const discountInput = _.debounce(function (e) {
}
if (couponForm.value.discountRatio) {
couponForm.value.amount = formatDecimal(couponForm.value.amount * (couponForm.value.discountRatio / couponFormDiscountRate.value))
discountRateNumber.value = formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount - goodsStore.cartInfo.costSummary.finalPayAmount * (couponForm.value.discountRatio / couponFormDiscountRate.value))
} else {
couponForm.value.amount = formatDecimal(+couponForm.value.originAmount)
discountRateNumber.value = formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount - goodsStore.cartInfo.costSummary.finalPayAmount)
}
// 将优惠券/积分所有设置初始化
couponResList1.value = []
couponResList2.value = []
updateCartCalc()
// // 将优惠券/积分所有设置初始化
// couponResList1.value = []
// couponResList2.value = []
// couponForm.value.pointsNum = ''
// pointOptions.value.amount = 0
}, 500)
// 取消所有优惠
function cancelAllDiscount() {
showCoupon.value = false
couponForm.value.pointsNum = ''
pointOptions.value.amount = 0
}, 500)
couponResList1.value = []
couponForm.value.discountRatio = ''
discountRateNumber.value = ''
updateCartCalc()
}
// 同意更新商品计算
function updateCartCalc() {
goodsStore.calcCartInfo({
pointsPerYuan: pointOptions.value.equivalentPoints,
maxDeductionAmount: pointOptions.value.max,
userPoints: couponForm.value.pointsNum,
backendCoupons: couponResList1.value,
fixedAmount: discountRateNumber.value
})
}
// 清除积分
function clearPoint() {
@@ -624,6 +698,8 @@ function clearPoint() {
couponForm.value.amount = +couponForm.value.amount + +pointOptions.value.amount
pointOptions.value.amount = 0
}
updateCartCalc()
}
// 积分输入格式化
@@ -655,6 +731,8 @@ const pointInput = _.debounce(function (e) {
pointOptions.value.loading = true
calcPointMoney()
}
updateCartCalc()
}, 500)
@@ -662,12 +740,14 @@ const pointInput = _.debounce(function (e) {
const calcPointMoney = async () => {
try {
const res = await calcDeductionAmount({
shopUserId: couponFormUser.value.id,
orderAmount: couponForm.value.amount,
shopUserId: goodsStore.vipUserInfo.id,
orderAmount: goodsStore.cartInfo.costSummary.finalPayAmount,
points: couponForm.value.pointsNum
})
pointOptions.value.amount = formatDecimal(+res)
couponForm.value.amount = couponForm.value.amount - res
updateCartCalc()
} catch (error) {
console.log(error);
}
@@ -706,6 +786,7 @@ function couponDialogOpen() {
// 关闭后初始化dialog
function resetCouponFormHandle() {
couponForm.value = { ...resetCouponForm.value }
cancelAllDiscount()
}
// 选择会员完成后
@@ -721,10 +802,10 @@ async function selectUserHandle(row) {
goodsStore.calcCartInfo()
emit('reset')
// emit('reset')
couponForm.value.discountRatio = ''
discountInput('')
// couponForm.value.discountRatio = ''
// discountInput('')
if (showCoupon.value) {
setTimeout(() => {
@@ -766,8 +847,8 @@ function resetCoupon() {
async function pointOptionsAjax() {
try {
const res = await calcUsablePoints({
shopUserId: couponFormUser.value.id,
orderAmount: couponForm.value.amount
shopUserId: goodsStore.vipUserInfo.id,
orderAmount: goodsStore.cartInfo.costSummary.finalPayAmount
})
pointOptions.value.min = res.minDeductionPoints // 最少使用积分
@@ -775,6 +856,7 @@ async function pointOptionsAjax() {
pointOptions.value.usable = res.usable // 是否可用
pointOptions.value.unusableReason = res.unusableReason // 不可用的原因
pointOptions.value.minPaymentAmount = res.minPaymentAmount // 最少使用的金额
pointOptions.value.equivalentPoints = res.equivalentPoints
} catch (error) {
console.log(error);
}
@@ -794,51 +876,52 @@ function showCounponModalHandle() {
const couponResList2Amount = ref(0)
// 选择完优惠券的回调事件
function CouponModalSuccess(res) {
console.log(res);
couponResType.value = res.type
clearPoint()
couponResList1.value = res
updateCartCalc()
// couponResType.value = res.type
// clearPoint()
if (res.type == 2) {
couponResList2Amount.value = 0
couponResList1.value = []
couponForm.value.fullCouponDiscountAmount = 0
couponResList2.value = res.couponList
// if (res.type == 2) {
// couponResList2Amount.value = 0
// couponResList1.value = []
// couponForm.value.fullCouponDiscountAmount = 0
// couponResList2.value = res.couponList
// 商品券
const discountOrders = applyCoupons([...props.orderList], couponResList2.value)
// // 商品券
// const discountOrders = applyCoupons([...props.orderList], couponResList2.value)
// 计算所有的优惠金额
discountOrders.forEach(item => {
if (item.isCoupon) {
if (item.discount) {
couponResList2Amount.value += item.discount
}
}
})
// // 计算所有的优惠金额
// discountOrders.forEach(item => {
// if (item.isCoupon) {
// if (item.discount) {
// couponResList2Amount.value += item.discount
// }
// }
// })
couponForm.value.productCouponDiscountAmount = couponResList2Amount.value
}
// couponForm.value.productCouponDiscountAmount = couponResList2Amount.value
// }
if (res.type == 1) {
if (couponForm.value.amount < res.couponList[0].fullAmount) {
ElMessage.error(`订单金额不足¥${formatDecimal(res.couponList[0].fullAmount, 2, true)},无法使用优惠券`)
return
}
couponResList1.value = res.couponList
couponForm.value.fullCouponDiscountAmount = res.couponList[0].discountAmount
}
// if (res.type == 1) {
// if (couponForm.value.amount < res.couponList[0].fullAmount) {
// ElMessage.error(`订单金额不足¥${formatDecimal(res.couponList[0].fullAmount, 2, true)},无法使用优惠券`)
// return
// }
// couponResList1.value = res.couponList
// couponForm.value.fullCouponDiscountAmount = res.couponList[0].discountAmount
// }
let rate = 1
if (couponForm.value.discountRatio) {
rate = couponForm.value.discountRatio / couponFormDiscountRate.value
}
// let rate = 1
// if (couponForm.value.discountRatio) {
// rate = couponForm.value.discountRatio / couponFormDiscountRate.value
// }
// 满减券切勿使用discount计算
couponForm.value.amount = formatDecimal((originOrderAmount.value * rate) - (couponResList1.value.length ? couponResList1.value[0].discountAmount : 0) - couponResList2Amount.value)
// // 满减券切勿使用discount计算
// couponForm.value.amount = formatDecimal((originOrderAmount.value * rate) - (couponResList1.value.length ? couponResList1.value[0].discountAmount : 0) - couponResList2Amount.value)
if (couponForm.value.amount < 0) {
couponForm.value.amount = 0
}
// if (couponForm.value.amount < 0) {
// couponForm.value.amount = 0
// }
}
// 多个优惠券抵扣多个商品,优先已价格最低的抵扣
@@ -877,6 +960,9 @@ function delCoupon(index, t) {
couponForm.value.amount = +couponForm.value.amount + +price
couponResList2.value.splice(index, 1)
}
updateCartCalc()
console.log(couponForm.value.amount);
}
@@ -942,29 +1028,29 @@ async function payCardInit() {
discountAmount.value = null
roundAmount.value = 0
discountRateVlaue.value = 0
money.value = `${formatDecimal(props.amount)}`;
money.value = `${formatDecimal(goodsStore.cartInfo.costSummary.finalPayAmount)}`;
originOrderAmount.value = formatDecimal(props.amount - (goodsStore.tableInfo.tableFee || 0) -
(goodsStore.cartInfo.packFee || 0))
payData.value = {
shopId: store.shopInfo.id,
buyerRemark: "", // 订单备注
checkOrderPay: {
orderId: goodsStore.orderListInfo.id,
vipPrice: store.shopInfo.isMemberPrice ? goodsStore.showVipPrice : 0, // 是否使用会员价
allPack: goodsStore.allSelected, // 是否整单打包
userId: goodsStore.vipUserInfo.userId || '',
seatNum: goodsStore.tableInfo.num, // 用餐人数
originAmount: formatDecimal(+goodsStore.cartInfo.totalAmount), // 订单原金额(包含打包费+餐位费) 不含折扣价格
discountRatio: '', // 折扣比例(计算时 向上取整保留 两位小数)
discountAmount: 0, // 手动优惠金额
productCouponDiscountAmount: 0, // 商品优惠券抵扣金额
fullCouponDiscountAmount: 0, // 满减优惠券抵扣金额
couponList: [], // 用户使用的卡券
orderAmount: formatDecimal(+goodsStore.cartInfo.totalAmount), // 订单金额
roundAmount: 0, // 抹零金额 减免多少钱
pointsDiscountAmount: 0, // 积分抵扣金额(tb_points_basic_setting表)
pointsNum: 0, // 使用的积分数量 (扣除各类折扣 enable_deduction后使用)
isPrint: 1
// orderId: goodsStore.orderListInfo.id,
// vipPrice: store.shopInfo.isMemberPrice ? goodsStore.showVipPrice : 0, // 是否使用会员价
// allPack: goodsStore.allSelected, // 是否整单打包
// userId: goodsStore.vipUserInfo.userId || '',
// seatNum: goodsStore.tableInfo.num, // 用餐人数
// originAmount: formatDecimal(+goodsStore.cartInfo.totalAmount), // 订单原金额(包含打包费+餐位费) 不含折扣价格
// discountRatio: '', // 折扣比例(计算时 向上取整保留 两位小数)
// discountAmount: 0, // 手动优惠金额
// productCouponDiscountAmount: 0, // 商品优惠券抵扣金额
// fullCouponDiscountAmount: 0, // 满减优惠券抵扣金额
// couponList: [], // 用户使用的卡券
// orderAmount: formatDecimal(+goodsStore.cartInfo.totalAmount), // 订单金额
// roundAmount: 0, // 抹零金额 减免多少钱
// pointsDiscountAmount: 0, // 积分抵扣金额(tb_points_basic_setting表)
// pointsNum: 0, // 使用的积分数量 (扣除各类折扣 enable_deduction后使用)
// isPrint: 1
},
};