This commit is contained in:
gyq
2025-09-29 18:28:52 +08:00
3 changed files with 118 additions and 85 deletions

View File

@@ -254,7 +254,7 @@ function tabChange(index) {
querForm.value.statusActiveIndex = index;
list.page = 1;
list.status = 'nomore';
getCouponList();
formatCoupon();
}
function changeSelCoupon(item) {
@@ -277,6 +277,7 @@ function changeSelCoupon(item) {
}
}
const couponSel = ref({
id: ''
});
@@ -286,7 +287,12 @@ const goodsCouponSel = ref({
const quansSelArr = computed(() => {
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
});
watch(()=>couponSel.value.id,(newval)=>{
formatCoupon()
})
watch(()=>goodsCouponSel.value.id,(newval)=>{
formatCoupon()
})
function isActive(item) {
if (querForm.value.statusActiveIndex) {
return couponSel.value.id == item.id;
@@ -295,16 +301,9 @@ function isActive(item) {
}
}
// 获取优惠券列表
async function getCouponList() {
try {
uni.showLoading({
title: '加载中...',
mask: true
});
const res = await findCoupon({
shopUserId: uni.cache.get('shopUserInfo').id
});
const couponList=ref([])
function formatCoupon(){
let canUseGoodsCoupon = [];
let canUseDiscountCoupon = [];
@@ -320,8 +319,8 @@ async function getCouponList() {
const dinnerType = cartStore.dinnerType;
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
const shopId = uni.cache.get('shopId');
for (let i = 0; i < res.length; i++) {
const coupon = res[i];
for (let i = 0; i < couponList.value.length; i++) {
const coupon = couponList.value[i];
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
@@ -382,6 +381,21 @@ async function getCouponList() {
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
}
// 获取优惠券列表
async function getCouponList() {
try {
uni.showLoading({
title: '加载中...',
mask: true
});
const res = await findCoupon({
shopUserId: uni.cache.get('shopUserInfo').id
});
couponList.value=res
formatCoupon()
} catch (error) {
console.log(error);
}
@@ -490,6 +504,7 @@ onLoad(() => {
watch(
() => quansSelArr.value,
(newval) => {
// getCouponList()
const user = uni.cache.get('shopUserInfo');
let shopInfo = uni.cache.get('shopInfo') || {};
if (!shopInfo.isMemberPrice) {

View File

@@ -105,6 +105,9 @@ export const useCartsStore = defineStore('cart',
})
watch(() => shopInfo.value.isTableFee, (newval) => {
seatFeeConfig.value.isEnabled = !shopInfo.value.isTableFee
seatFeeConfig.value.pricePerPerson = shopInfo.value.tableFee||0
},{
deep:true
})
function setSeatFeeConfig(key, val) {

View File

@@ -18,6 +18,7 @@ export function returnGoodsPrice(goods, user, shopInfo) {
if (goods.discount_sale_amount * 1 > 0) {
return goods.discount_sale_amount;
}
console.log('returnGoodsPrice:shopInfo',shopInfo);
if(shopInfo&&!shopInfo.isMemberPrice){
return goods.salePrice;
}
@@ -151,6 +152,18 @@ export function returnCouponCanUse(args) {
return pre + returnGoodsPrice(cur, user,shopInfo) * cur.num;
}, 0);
}
if(user.isVip&&!coupon.vipPriceShare){
return {
canUse: false,
reason: "非会员可用"
};
}
if(selCoupon.length>0&&!selCoupon[0].otherCouponShare){
return {
canUse: false,
reason: "当前选中的券不可与其他券同享"
};
}
// 没有符合条件的商品
if (!isDikouAll && canCalcGoodsArr.length === 0) {
@@ -264,18 +277,19 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user,sh
* @param user 用户信息
* @param goodsOrderPrice 商品订单金额
* @param selCoupon 已选择的优惠券列表
* @param shopInfo 店铺信息
*/
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon) {
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon,shopInfo) {
const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user);
console.log('canDikouGoodsArr', canDikouGoodsArr);
if (coupon.type == 2) {
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo);
}
if (coupon.type == 6) {
return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo);
}
if (coupon.type == 4) {
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo);
}
if (coupon.type == 3) {
return returnCouponZhekouDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice, selCoupon);
@@ -331,8 +345,9 @@ export function returnCouponZhekouDiscount(
* @param canDikouGoodsArr 可抵扣商品列表
* @param coupon 优惠券
* @param user 用户信息
* @param shopInfo 店铺信息
*/
export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user) {
export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user,shopInfo) {
const {
useFoods,
discountNum,
@@ -362,7 +377,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user) {
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
}
}
const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user);
const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user,shopInfo);
return result;
}