对接新版结算

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

@@ -33,6 +33,21 @@
<span class="title">{{ item.payName }}</span>
</div>
</div>
<div class="quick_charge">
<div class="item" :class="{active:chargeActive == index }" v-for="(item,index) in chargeList" :key="item.id" @click="changeCharge(index,item)">
<div class="row">
<span class="icon"></span>
<span class="num">{{ item.amount }}</span>
</div>
<div class="row">
<span class="t1">{{ item.rewardAmount }}</span>
<span class="t1">{{ item.rewardPoints }}积分</span>
</div>
<div class="row">
<span class="t2">{{item.couponCount}}张券</span>
</div>
</div>
</div>
<div class="input_wrap">
<div class="input" style="flex: 1">储值:{{ money }}</div>
</div>
@@ -60,13 +75,14 @@
</div>
</div>
<scanModal ref="scanModalRef" fast :amount="money" :money="money" :selecttype="props.type"
:orderId="props.userInfo.id" @success="scanCodeSuccess" />
:orderId="props.userInfo.id" :chargeId="chargeId" @success="scanCodeSuccess" />
<takeFoodCode ref="takeFoodCodeRef" title="支付密码" :type="2" input-type="password" placeholder="请输入支付密码"
@success="passwordSuccess" />
</template>
<script setup>
import { onMounted, ref } from "vue";
import { shopRecharge } from '@/api/market.js'
import { getPayType } from '@/api/account.js'
import { cashPayVip } from "@/api/order.js";
import { clearNoNum } from "@/utils";
@@ -134,7 +150,8 @@ async function passwordSuccess(e = '') {
// pwd: e ? md5(e) : '',
pwd: e,
orderId: '',
allPack: ''
allPack: '',
rechargeDetailId: chargeId.value
});
payLoading.value = false;
ElMessage.success("充值成功");
@@ -196,12 +213,16 @@ async function confirmOrder() {
// 输入
function amountInput(num) {
money.value = clearNoNum({ value: (money.value += num) });
chargeActive.value = null
chargeId.value = ''
}
// 删除
function delHandle() {
if (!money.value) return;
money.value = money.value.substring(0, money.value.length - 1);
chargeActive.value = null
chargeId.value = ''
money.value = money.value.substring(0, money.value.length - 1);
if (!money.value) {
money.value = "0";
}
@@ -225,15 +246,49 @@ async function queryPayTypeAjax() {
}
}
// 初始化
function reset() {
money.value = 0;
payActive.value = 0;
chargeActive.value = null;
}
// 获取智慧充值的配置信息
const chargeActive = ref(null);
const chargeList = ref([])
const chargeId = ref('')
function changeCharge(index,item) {
chargeActive.value = index
chargeId.value = item.id
money.value = ''
money.value = clearNoNum({ value: (money.value += item.amount) })
}
async function shopRechargeAjax() {
try {
const res = await shopRecharge()
res.rechargeDetailList.map((item) => {
item.couponCount = 0
item.couponInfoList.map(val => {
item.couponCount += val.num;
})
})
chargeList.value = res.rechargeDetailList
console.log(chargeList.value)
} catch (err) {
console.log(err)
}
}
defineExpose({ reset });
onMounted(() => {
queryPayTypeAjax();
shopRechargeAjax()
});
</script>
@@ -300,7 +355,7 @@ onMounted(() => {
gap: var(--el-font-size-base);
.item {
height: 130px;
height: 80px;
flex: 1;
display: flex;
flex-direction: column;
@@ -330,9 +385,56 @@ onMounted(() => {
width: $size;
height: $size;
}
}
}
.title {
padding-top: 10px;
.quick_charge {
width: 100%;
height: 100px;
overflow-x: auto;
margin-top: var(--el-font-size-base);
display: flex;
.item {
$activeColor: #FF6300;
display: flex;
gap: 2px;
flex-direction: column;
justify-content: center;
background-color: #F5F5F5;
border-radius: 8px;
padding: var(--el-font-size-base);
margin-right: var(--el-font-size-base);
border: 2px solid #F5F5F5;
&.active {
border-color: $activeColor;
.row {
.icon {
color: $activeColor;
}
.num {
color: $activeColor;
}
.t1 {
color: $activeColor;
}
}
}
.row {
display: flex;
align-items: center;
.icon {
font-size: 12px;
position: relative;
top: 3px;
}
.num {
font-size: 20px;
font-weight: bold;
}
.t2 {
color: #666;
}
}
}
}
@@ -345,7 +447,7 @@ onMounted(() => {
.input {
display: flex;
align-items: center;
height: 60px;
height: 50px;
border-radius: 6px;
border: 1px solid var(--primary-color);
font-size: calc(var(--el-font-size-base) + 6px);
@@ -363,7 +465,7 @@ onMounted(() => {
display: flex;
.left {
--item-height: calc((100vh - 440px) / 4);
--item-height: calc((100vh - 440px) / 5);
flex: 1;
display: grid;
grid-template-columns: 1fr 1fr 1fr;

View File

@@ -1,58 +1,100 @@
<template>
<el-dialog v-model="showDialog" title="选择优惠券" top="12vh" width="80%" @closed="resetHandle">
<el-radio-group v-model="query.type" @change="typeChange">
<el-radio-button label="优惠券" :value="1"></el-radio-button>
<el-radio-button label="商品券" :value="2"></el-radio-button>
<el-radio-group v-model="querForm.statusActiveIndex" @change="typeChange">
<el-radio-button :label="`商品兑换券(${goodsCoupon.length}`" :value="0"></el-radio-button>
<el-radio-button :label="`折扣优惠券(${discountCoupon.length}`" :value="1"></el-radio-button>
</el-radio-group>
<div class="table">
<el-table ref="tableRef1" :data="tableData.list" border stripe v-loading="tableData.loading"
v-show="query.type == 1" height="300px">
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="抵扣" prop="discountAmount"></el-table-column>
<el-table-column label="限制" prop="fullAmount">
<template v-slot="scope">
{{ scope.row.fullAmount }}{{ scope.row.discountAmount }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template v-slot="scope">
<el-button type="primary" @click="selectCoupon(scope.row)">选择</el-button>
</template>
</el-table-column>
</el-table>
<el-table ref="tableRef2" :data="tableData.list" border stripe row-key="id" v-loading="tableData.loading"
v-show="query.type == 2" height="300px">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="商品信息">
<template v-slot="scope">
{{ scope.row.productName }} {{ scope.row.lowPrice }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
</el-table>
<div style="height: 50vh;overflow-y: auto;">
<div class="table" v-if="querForm.statusActiveIndex == 0">
<div class="title">可用优惠券</div>
<el-table ref="tableRef1" :data="list.canUseCoupons" border stripe v-loading="tableData.loading"
row-key="id">
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="抵扣" prop="discountAmount"></el-table-column>
<el-table-column label="限制" prop="fullAmount">
<template v-slot="scope">
{{ scope.row.fullAmount }}{{ scope.row.discountAmount }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
<el-table-column label="选择" width="100" align="center">
<template #default="scope">
<el-checkbox v-model="scope.row.selected" :true-value="1" :false-value="0"
:disabled="scope.row.disabled" @change="selectCoupon($event, scope.row)"></el-checkbox>
</template>
</el-table-column>
</el-table>
<div class="title">不可用优惠券</div>
<el-table ref="tableRef2" :data="list.noCanUseCoupons" border v-loading="tableData.loading">
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="不可用原因">
<template v-slot="scope">
{{ scope.row.canuseResult.reason }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
</el-table>
</div>
<div class="table" v-if="querForm.statusActiveIndex == 1">
<div class="title">可用优惠券</div>
<el-table ref="tableRef1" :data="list.canUseDiscountCoupon" border stripe v-loading="tableData.loading">
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="抵扣" prop="discountAmount"></el-table-column>
<el-table-column label="限制" prop="fullAmount">
<template v-slot="scope">
{{ scope.row.fullAmount }}{{ scope.row.discountAmount }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
<el-table-column label="选择" width="100" align="center">
<template #default="scope">
<el-checkbox v-model="scope.row.selected" :true-value="1" :false-value="0"
:disabled="scope.row.disabled" @change="selectCoupon($event, scope.row)"></el-checkbox>
</template>
</el-table-column>
</el-table>
<div class="title">不可用优惠券</div>
<el-table ref="tableRef2" :data="list.noUseDiscountCoupon" border v-loading="tableData.loading">
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="不可用原因">
<template v-slot="scope">
{{ scope.row.canuseResult.reason }}
</template>
</el-table-column>
<el-table-column label="描述" prop="useRestrictions">
<template v-slot="scope">
<div v-html="scope.row.useRestrictions"></div>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div class="dialog_footer" v-if="query.type == 2">
<div class="dialog_footer">
<el-button @click="showDialog = false">取消</el-button>
<el-button type="primary" @click="selectCoupon()">确认</el-button>
<el-button type="primary" @click="selectCouponConfirm">确认</el-button>
</div>
</el-dialog>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { ref, reactive, computed } from 'vue'
import { useGoods } from '@/store/goods.js'
import { findCoupon } from '@/api/account.js'
import { ElMessage } from 'element-plus'
import * as UTILS from '@/utils/coupon-utils.js';
import { useUser } from "@/store/user.js";
const props = defineProps({
orderList: {
@@ -63,6 +105,7 @@ const props = defineProps({
const emits = defineEmits(['success'])
const store = useUser()
const goodsStore = useGoods()
const tableRef1 = ref(null)
const tableRef2 = ref(null)
@@ -85,11 +128,15 @@ function resetHandle() {
function typeChange() {
tableData.loading = false
tableData.list = []
// tableData.list = []
list.canUseCoupons = []
list.noCanUseCoupons = []
list.canUseDiscountCoupon = []
list.noUseDiscountCoupon = []
findCouponAjax()
if (query.type == 2) {
tableRef2.value.clearSelection()
}
// if (query.type == 2) {
// tableRef2.value.clearSelection()
// }
}
function groupByPropertyAndCount(arr, property) {
@@ -117,92 +164,320 @@ function groupByPropertyAndCount(arr, property) {
}
// 选择优惠券
function selectCoupon(row) {
if (query.value.type == 1) {
emits('success', { type: query.value.type, couponList: [{ ...row }] })
} else {
let goods = [
...goodsStore.cartList,
...goodsStore.orderList.map(item => item.goods).flat()
]
let arr = tableRef2.value.getSelectionRows()
if (!arr.length) {
ElMessage.error('请选择优惠券')
return
}
let obj = groupByPropertyAndCount(arr, 'proId')
let goodsObj = groupByPropertyAndCount(goods, 'product_id')
console.log(obj);
console.log(goodsObj);
for (let val of goodsObj) {
for (let item of obj) {
if (val.value == item.value) {
if (item.count > val.count) {
ElMessage.error('超出订单数量,请重新选择')
return
}
const goodsCoupon = ref([]) // 商品券
const discountCoupon = ref([]) // 其他优惠券
function selectCoupon($event, e) {
console.log($event);
console.log(e);
if (querForm.value.statusActiveIndex == 0) {
goodsCoupon.value = []
if ($event) {
goodsCoupon.value.push(e)
list.canUseCoupons.map(item => {
if (item.id != e.id) {
item.disabled = true
}
})
} else {
list.canUseCoupons.map(item => {
if (item.id != e.id) {
item.disabled = false
}
})
}
} else {
discountCoupon.value = []
if ($event) {
discountCoupon.value.push(e)
list.canUseDiscountCoupon.map(item => {
if (item.id != e.id) {
item.disabled = true
}
})
} else {
list.canUseDiscountCoupon.map(item => {
if (item.id != e.id) {
item.disabled = false
}
})
}
}
updateSelCoupon();
// if (query.value.type == 1) {
// emits('success', { type: query.value.type, couponList: [{ ...row }] })
// } else {
// let goods = [
// ...goodsStore.cartList,
// ...goodsStore.orderList.map(item => item.goods).flat()
// ]
// let arr = tableRef2.value.getSelectionRows()
// if (!arr.length) {
// ElMessage.error('请选择优惠券')
// return
// }
// let obj = groupByPropertyAndCount(arr, 'proId')
// let goodsObj = groupByPropertyAndCount(goods, 'product_id')
// console.log(obj);
// console.log(goodsObj);
// for (let val of goodsObj) {
// for (let item of obj) {
// if (val.value == item.value) {
// if (item.count > val.count) {
// ElMessage.error('超出订单数量,请重新选择')
// return
// }
// }
// }
// }
// emits('success', { type: query.value.type, couponList: arr })
// }
// showDialog.value = false
}
function updateSelCoupon() {
const newval = [...goodsCoupon.value, ...discountCoupon.value];
const user = goodsStore.vipUserInfo;
let shopInfo = store.shopInfo;
if (!shopInfo.isMemberPrice) {
shopInfo = {};
}
const canDikouGoodsArr = UTILS.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
if (newval.length >= 2) {
let goodsCoupon = newval.filter((v) => v.type == 2);
let otherCoupon = newval.filter((v) => v.type != 2);
goodsCoupon = goodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsStore.cartInfo.costSummary.goodsRealAmount,
[],
shopInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
otherCoupon = otherCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsStore.cartInfo.costSummary.goodsRealAmount,
goodsCoupon,
shopInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
console.log('otherCoupon[0]===', otherCoupon[0]);
console.log('goodsCoupon[0]===', goodsCoupon[0]);
discountCoupon.value = [otherCoupon[0]];
goodsCoupon.value = [goodsCoupon[0]];
}
}
// 确认选择优惠券,然后关闭弹窗
function selectCouponConfirm() {
showDialog.value = false
const data = [...goodsCoupon.value, ...discountCoupon.value]
emits('success', data)
goodsCoupon.value = []
discountCoupon.value = []
}
const querForm = ref({
searchValue: '',
shopId: '',
shopName: '',
statusActiveIndex: 0
});
const list = reactive({
page: 1,
size: 10,
status: 'nomore',
data: [],
noCanUseCoupons: [],
canUseCoupons: [],
noUseDiscountCoupon: [],
canUseDiscountCoupon: []
});
const couponSel = ref({
id: ''
});
const goodsCouponSel = ref({
id: ''
});
const quansSelArr = computed(() => {
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
});
// 格式化优惠券
function formatCoupon() {
let canUseGoodsCoupon = [];
let canUseDiscountCoupon = [];
let noUseGoodsCoupon = [];
let noUseDiscountCoupon = [];
const user = goodsStore.vipUserInfo;
let shopInfo = store.shopInfo;
if (!shopInfo.isMemberPrice) {
shopInfo = {};
}
const goodsOrderPrice = goodsStore.cartInfo.costSummary.goodsRealAmount;
console.log('goodsOrderPrice==========', goodsOrderPrice);
const canDikouGoodsArr = UTILS.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
for (let i = 0; i < couponList.value.length; i++) {
const coupon = couponList.value[i];
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
goodsOrderPrice,
user,
selCoupon: quansSelArr.value,
shopInfo
});
const { canUse, reason } = canuseResult;
if (coupon.type == 2) {
if (canUse || goodsCouponSel.value.id == coupon.id) {
canUseGoodsCoupon.push(coupon);
} else {
noUseGoodsCoupon.push({
...coupon,
canuseResult
});
}
} else {
if (canUse || couponSel.value.id == coupon.id) {
canUseDiscountCoupon.push(coupon);
} else {
noUseDiscountCoupon.push({
...coupon,
canuseResult
});
}
}
emits('success', { type: query.value.type, couponList: arr })
}
showDialog.value = false
//商品券
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
};
});
//非商品券
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
};
});
if (querForm.value.statusActiveIndex == 0) {
list.noCanUseCoupons = noUseGoodsCoupon;
canUseGoodsCoupon.map(item => {
item.selected = false
item.disabled = false
})
list.canUseCoupons = canUseGoodsCoupon;
} else {
list.noUseDiscountCoupon = noUseDiscountCoupon;
canUseDiscountCoupon.map(item => {
item.selected = false
item.disabled = false
})
list.canUseDiscountCoupon = canUseDiscountCoupon;
}
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
console.log('list===', list);
}
// 获取用户可用的优惠券
const couponList = ref([])
async function findCouponAjax() {
try {
tableData.loading = true
const res = await findCoupon({
shopUserId: query.value.userId,
type: query.value.type
shopUserId: query.value.userId
})
couponList.value = res
formatCoupon()
// if (query.value.type == 1) {
// tableData.list = res
// } else {
// let arr = []
// let ids = props.orderList.map(item => item.product_id)
// res && res.map((item, index) => {
if (query.value.type == 1) {
tableData.list = res
} else {
let arr = []
let ids = props.orderList.map(item => item.product_id)
res && res.map((item, index) => {
// let found = ids.find(val => val == item.proId)
// let result = found !== undefined
let found = ids.find(val => val == item.proId)
let result = found !== undefined
// if (result) {
// let pro = props.orderList.find(val => val.product_id == item.proId)
if (result) {
let pro = props.orderList.find(val => val.product_id == item.proId)
// console.log('pro===', pro);
console.log('pro===', pro);
// let discount = pro.lowPrice
let discount = pro.lowPrice
// if (goodsStore.showVipPrice) {
// discount = pro.memberPrice
// }
if (goodsStore.showVipPrice) {
discount = pro.memberPrice
}
// if (+pro.discount_sale_amount) {
// discount = pro.discount_sale_amount
// }
if (+pro.discount_sale_amount) {
discount = pro.discount_sale_amount
}
// arr.push({
// ...item,
// productName: pro.productName,
// lowPrice: pro.lowPrice,
// discount: discount
// })
// }
// })
// tableData.list = arr
arr.push({
...item,
productName: pro.productName,
lowPrice: pro.lowPrice,
discount: discount
})
}
})
tableData.list = arr
console.log('tableData.list===', tableData.list);
}
// console.log('tableData.list===', tableData.list);
// }
} catch (error) {
console.log(error);
}
@@ -222,13 +497,15 @@ defineExpose({
</script>
<style scoped lang="scss">
.table {
padding-top: var(--el-font-size-base);
}
.dialog_footer {
display: flex;
justify-content: flex-end;
padding-top: var(--el-font-size-base);
}
.title {
padding: 20px 0 10px 0;
font-size: 16px;
color: #333;
}
</style>

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
},
};

View File

@@ -10,7 +10,7 @@
<div class="right" v-if="!userPayWait">
<div class="amount">
<span class="t">扫码支付</span>
<span class="n">{{ props.money }}</span>
<span class="n">{{ goodsStore.cartInfo.costSummary.finalPayAmount }}</span>
</div>
<div class="input">
<el-input ref="inputRef" v-model="scanCode" :maxlength="18"
@@ -100,6 +100,10 @@ const props = defineProps({
payData: {
type: Object,
default: {}
},
chargeId: {
type: [Number, String],
default: "",
}
});
@@ -122,6 +126,11 @@ async function submitHandleAjax() {
if (!scanCode.value || scanCode.value.length > 18) return;
loading.value = true;
console.log('props.selecttype===', props.selecttype);
console.log('props.payType===', props.payType);
// return;
// 判断订单是否锁定
await goodsStore.isOrderLock({
table_code: goodsStore.orderListInfo.tableCode
@@ -147,7 +156,8 @@ async function submitHandleAjax() {
shopId: store.shopInfo.id,
shopUserId: props.orderId,
amount: props.amount,
authCode: scanCode.value
authCode: scanCode.value,
rechargeDetailId: props.chargeId,
})
} else {
// 快捷收银