优惠券相关修改更新

This commit is contained in:
GaoHao
2024-11-18 14:18:10 +08:00
parent 2808dec925
commit c679b60cb7
17 changed files with 760 additions and 109 deletions

View File

@@ -35,7 +35,7 @@
'containertopboxitemleft_tows': status != 1,
'containertopboxitemleft_nameVip': item.type == 2,
}">
{{ item.type == 2 ? item.detail : '优惠券(元)'}}
{{ item.type == 2 ? item.name : '优惠券(元)'}}
</view>
</view>
@@ -84,19 +84,27 @@
{
name: '已使用',
type: '2'
},
{
name: '已过期',
type: '-1'
}
],
tabIndex: 1,
list: [],
status: 1,
type: "",
payAmount: 0,
shoppingCart: [],
productList: [],
};
},
onLoad(options) {
if (options.type) {
this.type = options.type;
}
if (options.type) { this.type = options.type }
if (options.payAmount) { this.payAmount = options.payAmount }
if (options.shoppingCart) { this.shoppingCart = JSON.parse(decodeURIComponent(options.shoppingCart)) }
if (options.productList) { this.productList = JSON.parse(decodeURIComponent(options.productList)) }
this.getCouponList()
},
@@ -117,13 +125,26 @@
*/
async getCouponList() {
try {
let res = await this.api.conponList({
let params = {
userId: uni.cache.get('userInfo').id,
shopId: uni.cache.get('shopId'),
status: this.status
})
}
if ( this.type == 'confirm_order_coupon' || this.type == 'confirm_order_product' ) {
params.orderId = -1;
}
let res = await this.api.conponList(params)
if (res.code == 0) {
this.list = res.data;
console.log(res)
let list = [];
if ( this.type == 'confirm_order_coupon') {
list = res.data.filter(v => v.type == 1);
}else if ( this.type == 'confirm_order_product') {
list = res.data.filter(v => v.type == 2);
} else {
list = res.data;
}
this.list = list;
}
} catch (e) {
//TODO handle the exception
@@ -135,9 +156,73 @@
*/
navigatorGo ( item ) {
uni.cache.set('shopId',item.shopId)
if ( this.type == 'confirm_order') {
uni.$emit('couponItem', JSON.stringify(item))
uni.navigateBack();
if ( this.type == 'confirm_order_coupon' || this.type == 'confirm_order_product') {
if ( item.type == 1 ) {
if( this.payAmount < item.fullAmount) {
uni.showToast({
title: "当前订单金额不足使用金额",
icon: "none",
})
return;
}
uni.$emit('couponItem', JSON.stringify(item))
uni.navigateBack();
} else {
let productNum = 0;//商品购物车数量
let productTicketNum = 0;//商品券使用数量
let product = this.shoppingCart.filter(v => v.productId == item.proId);
let productTicket = this.productList.filter(v => v.productId == item.proId);
if ( product.length <= 0 ) {
uni.showToast({
title: "购物车没有"+item.name,
icon: "none",
})
return;
}
if (this.productList.filter(v => v.userCouponId == item.id).length > 0) {
uni.showToast({
title: `当前优惠券已选择`,
icon: "none",
})
return;
}
// 计算当前商品购物车数量
product.forEach(item => {
productNum += item.number;
})
// 计算当前商品券使用数量
productTicket.forEach(item => {
productTicketNum += item.num;
})
if ( (productNum - productTicketNum) == 0 ) {
uni.showToast({
title: `当前商品已经全部抵扣`,
icon: "none",
})
return;
}
// let productNum = 0;
// product.map(item => {
// productNum += item.number
// })
// if ( productNum < item.num) {
// uni.showToast({
// title: `购物车${item.name}数量不足`,
// icon: "none",
// })
// return;
// }
// if (product[0].number item.num) {
// }
uni.$emit('couponItem', JSON.stringify(item))
uni.navigateBack();
}
} else {
uni.pro.navigateTo('/pages/order_food/order_food', {
shopId: item.shopId
@@ -163,7 +248,7 @@
margin-top: 32rpx;
.towcontentlistxitembox {
width: 50%;
width: 33.33%;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 28rpx;