|
@@ -700,7 +700,15 @@
|
|
this.allPrice = totalPrice ;
|
|
this.allPrice = totalPrice ;
|
|
// 计算优惠券
|
|
// 计算优惠券
|
|
if(this.totalCouponList.length>0){
|
|
if(this.totalCouponList.length>0){
|
|
- this.calculationCoupon()
|
|
|
|
|
|
+ let eligibleCoupons = this.calculationCoupon()
|
|
|
|
+ console.log('eligibleCoupons',eligibleCoupons)
|
|
|
|
+ if(eligibleCoupons.length>0){
|
|
|
|
+ this.eligibleCoupons.splice(0,this.eligibleCoupons.length);
|
|
|
|
+ this.eligibleCoupons.push(eligibleCoupons[0])
|
|
|
|
+ this.couponPrice = this.eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount)[0].couponAmount
|
|
|
|
+ }else{
|
|
|
|
+ this.couponPrice = 0
|
|
|
|
+ }
|
|
}
|
|
}
|
|
// 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
// 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
this.totalDiscountAmount = this.reducedPrice + this.couponPrice;
|
|
this.totalDiscountAmount = this.reducedPrice + this.couponPrice;
|
|
@@ -728,62 +736,64 @@
|
|
})
|
|
})
|
|
},
|
|
},
|
|
calculationCoupon(){// 优惠券计算
|
|
calculationCoupon(){// 优惠券计算
|
|
- const eligibleCoupons = [];
|
|
|
|
- this.goodsList.forEach((shop,index)=>{
|
|
|
|
- shop.cartList.forEach(pros=>{
|
|
|
|
|
|
+ let eligibleCoupons = []
|
|
|
|
+ this.goodsList.forEach(shop=>{
|
|
|
|
+ shop.cartList.forEach(pros=>{
|
|
if(pros.productsChecked){
|
|
if(pros.productsChecked){
|
|
- this.totalCouponList.map((coupon,index)=>{//循环优惠券
|
|
|
|
- const couponType = coupon.couponType;
|
|
|
|
- if(couponType == 0){// 活动券
|
|
|
|
- if(coupon.productType == 1){// 活动券-全商城商品
|
|
|
|
- if(this.allPrice>=coupon.touchPrice){
|
|
|
|
- eligibleCoupons.push(coupon)
|
|
|
|
- eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
|
|
+ this.totalCouponList.forEach(coupon=>{//循环优惠券
|
|
|
|
+ switch(coupon.couponType){
|
|
|
|
+ case 0:// 活动券
|
|
|
|
+ if(coupon.productType == 1){// 活动券-全商城商品
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
|
|
+ }
|
|
|
|
+ }else if(coupon.productType == 2){// 活动券-指定商品
|
|
|
|
+ if(coupon.productIds && coupon.productIds.includes(pros.productId)){
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }else if(coupon.productType == 2){// 活动券-指定商品
|
|
|
|
- if(coupon.productIds && coupon.productIds.includes(pros.productId)){
|
|
|
|
- if(this.allPrice>=coupon.touchPrice){
|
|
|
|
- eligibleCoupons.push(coupon)
|
|
|
|
- eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
|
|
+ break;
|
|
|
|
+ case 1:// 品类券适用于产品或者仪器 categoryType(commodityType) : 1 产品 2 仪器
|
|
|
|
+ if( coupon.categoryType && coupon.categoryType == pros.commodityType){
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
- return false
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- // 品类券适用于产品或者仪器,购买产品类或仪器类的商品,商品金额达到优惠标准即可使用优惠券
|
|
|
|
- }else if(couponType == 1){// 品类券 categoryType(commodityType) : 1 产品 2 仪器
|
|
|
|
- if( coupon.categoryType && coupon.categoryType == pros.commodityType){
|
|
|
|
- if(this.allPrice>=coupon.touchPrice){
|
|
|
|
- eligibleCoupons.push(coupon)
|
|
|
|
- eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
|
|
+ break;
|
|
|
|
+ case 2:// 用户专享券 适用于商城全部商品
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
}
|
|
}
|
|
- }
|
|
|
|
- // 适用于商城全部商品
|
|
|
|
- }else if(couponType == 2 || couponType == 4){// 用户专享券和新用户券
|
|
|
|
- if(this.allPrice>=coupon.touchPrice){
|
|
|
|
- eligibleCoupons.push(coupon)
|
|
|
|
- eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
- }
|
|
|
|
- // 店铺券适用于某个供应商的全部商品
|
|
|
|
- }else if(couponType == 3){// 店铺券 supplierId
|
|
|
|
- if(coupon.shopId && pros.supplierId == coupon.shopId){
|
|
|
|
- if(this.allPrice>=coupon.touchPrice){
|
|
|
|
- eligibleCoupons.push(coupon)
|
|
|
|
- eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
|
|
+ break;
|
|
|
|
+ case 3:// 店铺券适用于某个供应商的全部商品
|
|
|
|
+ if(coupon.shopId && pros.supplierId == coupon.shopId){
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ break;
|
|
|
|
+ case 4://新用户券 适用于商城全部商品
|
|
|
|
+ if(this.allPrice >= coupon.touchPrice){
|
|
|
|
+ eligibleCoupons = this.setCouponsArr(coupon)
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ })
|
|
|
|
+ }else{
|
|
|
|
+ console.log('没有选择商品')
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|
|
- if(eligibleCoupons.length>0){
|
|
|
|
- this.eligibleCoupons.push(eligibleCoupons[0])
|
|
|
|
- this.couponPrice = this.eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount)[0].couponAmount
|
|
|
|
- }
|
|
|
|
|
|
+ return eligibleCoupons;
|
|
},
|
|
},
|
|
- checkenTotalPrice(){
|
|
|
|
-
|
|
|
|
|
|
+ setCouponsArr(coupon){//处理
|
|
|
|
+ const list = []
|
|
|
|
+ list.push(coupon)
|
|
|
|
+ list.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
|
+ return list
|
|
},
|
|
},
|
|
changeCountAdd(item,pros){//商品数量加加
|
|
changeCountAdd(item,pros){//商品数量加加
|
|
if(pros.step === 2){
|
|
if(pros.step === 2){
|