优惠券问题修复
This commit is contained in:
@@ -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,6 +301,88 @@ function isActive(item) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const couponList=ref([])
|
||||
function formatCoupon(){
|
||||
|
||||
let canUseGoodsCoupon = [];
|
||||
let canUseDiscountCoupon = [];
|
||||
|
||||
let noUseGoodsCoupon = [];
|
||||
let noUseDiscountCoupon = [];
|
||||
const user = uni.cache.get('shopUserInfo');
|
||||
let shopInfo = uni.cache.get('shopInfo') || {};
|
||||
if (!shopInfo.isMemberPrice) {
|
||||
shopInfo = {};
|
||||
}
|
||||
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
|
||||
const dinnerType = cartStore.dinnerType;
|
||||
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
|
||||
const shopId = uni.cache.get('shopId');
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//商品券
|
||||
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;
|
||||
list.canUseCoupons = canUseGoodsCoupon;
|
||||
} else {
|
||||
list.noCanUseCoupons = noUseDiscountCoupon;
|
||||
list.canUseCoupons = canUseDiscountCoupon;
|
||||
}
|
||||
|
||||
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
|
||||
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
|
||||
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
|
||||
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
|
||||
}
|
||||
|
||||
// 获取优惠券列表
|
||||
async function getCouponList() {
|
||||
try {
|
||||
@@ -305,83 +393,9 @@ async function getCouponList() {
|
||||
const res = await findCoupon({
|
||||
shopUserId: uni.cache.get('shopUserInfo').id
|
||||
});
|
||||
|
||||
let canUseGoodsCoupon = [];
|
||||
let canUseDiscountCoupon = [];
|
||||
|
||||
let noUseGoodsCoupon = [];
|
||||
let noUseDiscountCoupon = [];
|
||||
const user = uni.cache.get('shopUserInfo');
|
||||
let shopInfo = uni.cache.get('shopInfo') || {};
|
||||
if (!shopInfo.isMemberPrice) {
|
||||
shopInfo = {};
|
||||
}
|
||||
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
|
||||
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];
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//商品券
|
||||
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;
|
||||
list.canUseCoupons = canUseGoodsCoupon;
|
||||
} else {
|
||||
list.noCanUseCoupons = noUseDiscountCoupon;
|
||||
list.canUseCoupons = canUseDiscountCoupon;
|
||||
}
|
||||
|
||||
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
|
||||
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
|
||||
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
|
||||
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user