|
@@ -17,6 +17,7 @@ var shoppingCart = new Vue({
|
|
|
originalPrice: 0,
|
|
|
allChecked: true,
|
|
|
submitIds: [],//去结算商品Ids
|
|
|
+ checkenProsList:[],// 勾选中的商品
|
|
|
isShowPopup:false,
|
|
|
currentTab:1,
|
|
|
couponParam:{// 获取弹窗优惠券领取参数
|
|
@@ -31,6 +32,7 @@ var shoppingCart = new Vue({
|
|
|
couponPrice:0, // 优惠金额
|
|
|
totalDiscountAmount:0, // 总共减去金额
|
|
|
isDiscount:false, // 控制显示优惠明细
|
|
|
+ isCheckedProductStatus:false
|
|
|
},
|
|
|
watch:{
|
|
|
listData: {
|
|
@@ -84,8 +86,11 @@ var shoppingCart = new Vue({
|
|
|
_self.listData.forEach(function(supplier){
|
|
|
supplier.isChecked = true;
|
|
|
if(supplier.cartList.length>0){
|
|
|
- supplier.cartList.forEach(function(cartItem){
|
|
|
- _self.submitIds.push(cartItem.productId);
|
|
|
+ supplier.cartList.forEach(function(pros){
|
|
|
+ pros.isChecked = true
|
|
|
+ _self.submitIds.push(pros.productId);
|
|
|
+ _self.checkenProsList.push(pros);
|
|
|
+ _self.isCheckedProductStatus = true;
|
|
|
})
|
|
|
}
|
|
|
});
|
|
@@ -112,57 +117,86 @@ var shoppingCart = new Vue({
|
|
|
$(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
|
|
|
if(!isPC){looseBody();}
|
|
|
},
|
|
|
- ckeckItem: function(event){
|
|
|
- var el = event.currentTarget;
|
|
|
- if(!$(el).prop("checked")){
|
|
|
- $(el).parents('.supplierItem').find('.supplierTit').find('input.check').prop("checked", false);
|
|
|
+ ckeckItem: function(supplier,pro){//为未选中的时候改变为true,反之为true
|
|
|
+ var _self = this;
|
|
|
+ pro.isChecked = !pro.isChecked;
|
|
|
+ if (pro.isChecked) {
|
|
|
+ if (!_self.submitIds.includes(pro.productId * 1)) {
|
|
|
+ _self.submitIds.push(pro.productId);
|
|
|
+ _self.checkenProsList.push(pro);
|
|
|
+ }
|
|
|
+ _self.isCheckedProductStatus = true;
|
|
|
+ } else {
|
|
|
+ var lent = _self.submitIds.indexOf(pro.productId * 1)
|
|
|
+ if (lent >= 0) {
|
|
|
+ _self.submitIds.splice(lent, 1);
|
|
|
+ _self.checkenProsList.splice(lent, 1);
|
|
|
+ }
|
|
|
}
|
|
|
- this.computedPrice();
|
|
|
+ _self.updateProductCheckedAllBtn(supplier)
|
|
|
+ _self.updateCheckAllBtn()
|
|
|
+ _self.computedPrice();
|
|
|
},
|
|
|
- ckeckSupplier: function(event, supplierChecked){
|
|
|
- var el = event.currentTarget;
|
|
|
+ ckeckSupplier: function(supplier){
|
|
|
var _self = this;
|
|
|
- var cartList = $(el).parents('.supplierItem').find('input[name=cartList]');
|
|
|
- this.$nextTick(function(){
|
|
|
- if (supplierChecked) {
|
|
|
- $.each(cartList, function (index, item) {
|
|
|
- if (!_self.submitIds.includes(item.value*1)){
|
|
|
- _self.submitIds.push(item.value*1);
|
|
|
- }
|
|
|
- });
|
|
|
- }else{
|
|
|
- $.each(cartList, function (index, item) {
|
|
|
- var loc = _self.submitIds.indexOf(item.value*1);
|
|
|
- if(loc >=0 ){
|
|
|
- _self.submitIds.splice(loc, 1);
|
|
|
- _self.allChecked = false;
|
|
|
- }
|
|
|
- });
|
|
|
+ supplier.isChecked = !supplier.isChecked;
|
|
|
+ _self.setProductChecked(supplier);
|
|
|
+ _self.updateCheckAllBtn();
|
|
|
+ _self.computedPrice();
|
|
|
+ },
|
|
|
+ updateProductCheckedAllBtn: function(supplier) { // 单独每个供应商的勾选判断
|
|
|
+ var productsList = supplier.cartList,
|
|
|
+ productsCheckedLength = 0;
|
|
|
+ productsList.forEach(pros => {
|
|
|
+ if (pros.isChecked) {
|
|
|
+ productsCheckedLength++;
|
|
|
}
|
|
|
- _self.computedPrice();
|
|
|
- });
|
|
|
+ })
|
|
|
+ supplier.isChecked = productsCheckedLength === productsList.length
|
|
|
},
|
|
|
- ckeckAll: function(){
|
|
|
+ updateCheckAllBtn: function() { // 全选勾选判断
|
|
|
var _self = this;
|
|
|
- this.$nextTick(function(){
|
|
|
- if (_self.allChecked) {
|
|
|
- _self.submitIds = [];
|
|
|
- _self.listData.forEach(function(supplier){
|
|
|
- supplier.isChecked = true;
|
|
|
- if(supplier.cartList.length>0){
|
|
|
- supplier.cartList.forEach(function(cartItem){
|
|
|
- _self.submitIds.push(cartItem.productId);
|
|
|
- })
|
|
|
- }
|
|
|
- });
|
|
|
- }else{
|
|
|
- _self.submitIds = [];
|
|
|
- _self.listData.forEach(function(supplier){
|
|
|
- supplier.isChecked = false;
|
|
|
- });
|
|
|
+ var goodsCheckedLength = 0,
|
|
|
+ goodsList = _self.listData;
|
|
|
+ goodsList.forEach(function(supplier){
|
|
|
+ if (supplier.isChecked) {
|
|
|
+ goodsCheckedLength++;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ _self.allChecked = goodsCheckedLength === goodsList.length;
|
|
|
+ },
|
|
|
+ updateBothCheckBtn: function(){// 更新商铺勾选状态
|
|
|
+ var _self = this;
|
|
|
+ _self.listData.forEach(supplier => {
|
|
|
+ supplier.isChecked = _self.allChecked;
|
|
|
+ _self.setProductChecked(supplier);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ setProductChecked: function(supplier) {//
|
|
|
+ var _self = this;
|
|
|
+ supplier.cartList.forEach(pros => {
|
|
|
+ if (supplier.isChecked) {
|
|
|
+ pros.isChecked = true;
|
|
|
+ if (!_self.submitIds.includes(pros.productId * 1)) {
|
|
|
+ _self.submitIds.push(pros.productId);
|
|
|
+ _self.checkenProsList.push(pros);
|
|
|
+ }
|
|
|
+ _self.isCheckedProductStatus = true;
|
|
|
+ } else {
|
|
|
+ pros.isChecked = false;
|
|
|
+ var lent = this.submitIds.indexOf(pros.productId * 1);
|
|
|
+ if (lent >= 0) {
|
|
|
+ _self.submitIds.splice(lent, 1);
|
|
|
+ _self.checkenProsList.splice(lent, 1);
|
|
|
+ }
|
|
|
}
|
|
|
- _self.computedPrice();
|
|
|
- });
|
|
|
+ })
|
|
|
+ _self.computedPrice();
|
|
|
+ },
|
|
|
+ ckeckAll: function(){
|
|
|
+ var _self = this;
|
|
|
+ _self.allChecked = !_self.allChecked;
|
|
|
+ _self.updateBothCheckBtn()
|
|
|
},
|
|
|
setPromotions:function(){
|
|
|
var _self = this;
|
|
@@ -248,59 +282,69 @@ var shoppingCart = new Vue({
|
|
|
reducedPrice += supplier.reducedPrice;
|
|
|
originalPrice += supplier.originalPrice;
|
|
|
});
|
|
|
- // 总促销计算
|
|
|
- _self.promotionsList.forEach(function (promotions) {
|
|
|
- // 凑单满减
|
|
|
- if (promotions.mode * 1 === 2 && promotions.type * 1 === 2) {
|
|
|
- var collecTotal = 0;
|
|
|
- var collecDiscountNum = 0;
|
|
|
- promotions.productList.forEach(function (product) {
|
|
|
- if (_self.submitIds.includes(product.productId * 1)) {
|
|
|
- total += product.number * product.price;
|
|
|
- }
|
|
|
- });
|
|
|
- if(promotions.discount == 1){// 支持凑单满减促销叠加条件的执行
|
|
|
- collecDiscountNum += parseInt(collecTotal/promotions.touchPrice) // 凑单满减促销叠加次数 = 凑单商品合计价格/凑单满减促销价格
|
|
|
- console.log('凑单促销满减叠加通道叠加次数',`${collecDiscountNum}次`)
|
|
|
- if (collecTotal >= promotions.touchPrice) {
|
|
|
- totalPrice -= promotions.reducedPrice*collecDiscountNum
|
|
|
- reducedPrice += promotions.reducedPrice*collecDiscountNum
|
|
|
- }
|
|
|
- }else{
|
|
|
- console.log('凑单促销满减非叠加通道')
|
|
|
- if (collecTotal >= promotions.touchPrice) {
|
|
|
- totalPrice -= promotions.reducedPrice
|
|
|
- reducedPrice += promotions.reducedPrice
|
|
|
+ if(_self.isCheckedProductStatus){
|
|
|
+ // 总促销计算
|
|
|
+ _self.promotionsList.forEach(function (promotions) {
|
|
|
+ // 凑单满减
|
|
|
+ if (promotions.mode * 1 === 2 && promotions.type * 1 === 2) {
|
|
|
+ var collecTotal = 0;
|
|
|
+ var collecDiscountNum = 0;
|
|
|
+ promotions.productList.forEach(function (product) {
|
|
|
+ collecTotal += _self.collecTotalPrice(product);
|
|
|
+ });
|
|
|
+ if(promotions.discount == 1){// 支持凑单满减促销叠加条件的执行
|
|
|
+ collecDiscountNum += parseInt(collecTotal/promotions.touchPrice) // 凑单满减促销叠加次数 = 凑单商品合计价格/凑单满减促销价格
|
|
|
+ console.log('凑单促销满减叠加通道叠加次数',`${collecDiscountNum}次`)
|
|
|
+ if (collecTotal >= promotions.touchPrice) {
|
|
|
+ totalPrice -= promotions.reducedPrice*collecDiscountNum
|
|
|
+ reducedPrice += promotions.reducedPrice*collecDiscountNum
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ console.log('凑单促销满减非叠加通道')
|
|
|
+ if (collecTotal >= promotions.touchPrice) {
|
|
|
+ totalPrice -= promotions.reducedPrice
|
|
|
+ reducedPrice += promotions.reducedPrice
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ });
|
|
|
+ _self.totalPrice = totalPrice;
|
|
|
+ _self.reducedPrice = reducedPrice;
|
|
|
+ _self.originalPrice = originalPrice;
|
|
|
+ _self.kindCount = kindCount;
|
|
|
+ _self.totalCount = totalCount;
|
|
|
+ // 计算优惠券
|
|
|
+ if (_self.totalCouponList.length > 0) {
|
|
|
+ let eligibleCoupons = _self.calculationCoupon();
|
|
|
+ if (eligibleCoupons.length > 0) {
|
|
|
+ _self.eligibleCoupons.splice(0, _self.eligibleCoupons.length);
|
|
|
+ _self.eligibleCoupons = eligibleCoupons.sort((a, b) => b.couponAmount - a.couponAmount)
|
|
|
+ _self.couponPrice = this.eligibleCoupons[0].couponAmount
|
|
|
+ } else {
|
|
|
+ _self.couponPrice = 0
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
- _self.totalPrice = totalPrice;
|
|
|
- _self.reducedPrice = reducedPrice;
|
|
|
- _self.originalPrice = originalPrice;
|
|
|
- _self.kindCount = kindCount;
|
|
|
- _self.totalCount = totalCount;
|
|
|
- // 计算优惠券
|
|
|
- if (_self.totalCouponList.length > 0) {
|
|
|
- let eligibleCoupons = _self.calculationCoupon();
|
|
|
- if (eligibleCoupons.length > 0) {
|
|
|
- _self.eligibleCoupons.splice(0, _self.eligibleCoupons.length);
|
|
|
- _self.eligibleCoupons = eligibleCoupons.sort((a, b) => b.couponAmount - a.couponAmount)
|
|
|
- _self.couponPrice = this.eligibleCoupons[0].couponAmount
|
|
|
+ // 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
|
+ _self.totalDiscountAmount = _self.reducedPrice + _self.couponPrice;
|
|
|
+ console.log('最终优惠金额', _self.totalDiscountAmount);
|
|
|
+ // 控制显示优惠明细
|
|
|
+ if (_self.totalDiscountAmount > 0) {
|
|
|
+ _self.isDiscount = true;
|
|
|
} else {
|
|
|
- _self.couponPrice = 0
|
|
|
+ _self.isDiscount = false;
|
|
|
}
|
|
|
}
|
|
|
- // 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
|
- _self.totalDiscountAmount = _self.reducedPrice + _self.couponPrice;
|
|
|
- console.log('最终优惠金额', _self.totalDiscountAmount);
|
|
|
- // 控制显示优惠明细
|
|
|
- if (_self.totalDiscountAmount > 0) {
|
|
|
- _self.isDiscount = true;
|
|
|
- } else {
|
|
|
- _self.isDiscount = false;
|
|
|
+ })
|
|
|
+ },
|
|
|
+ collecTotalPrice:function(pros){// 凑单满减计算勾选的凑单商品总价
|
|
|
+ var _self = this;
|
|
|
+ var price;
|
|
|
+ _self.checkenProsList.forEach(el => {
|
|
|
+ if(pros.productId == el.productId ){
|
|
|
+ price = el.number * el.price
|
|
|
}
|
|
|
})
|
|
|
+ return price
|
|
|
},
|
|
|
calculationCoupon:function(){// 优惠券计算
|
|
|
var _self = this;
|
|
@@ -466,10 +510,7 @@ var shoppingCart = new Vue({
|
|
|
if(data.couponList && data.couponList.length >0){
|
|
|
_self.productCouponList = data.couponList;
|
|
|
_self.isCouponEmpty = false;
|
|
|
- console.log('有优惠券')
|
|
|
- console.log(_self.productCouponList)
|
|
|
}else{
|
|
|
- console.log('没有优惠券')
|
|
|
_self.isCouponEmpty = true;
|
|
|
}
|
|
|
}else{
|