|
@@ -7,15 +7,24 @@ var shoppingCart = new Vue({
|
|
|
listLoading: true,
|
|
|
listData: [],
|
|
|
invalidData: [],
|
|
|
+ promotionsList: [],
|
|
|
kindCount: 0,
|
|
|
totalCount: 0,
|
|
|
totalPrice: 0,
|
|
|
+ reducedPrice: 0,
|
|
|
+ originalPrice: 0,
|
|
|
allChecked: true,
|
|
|
submitIds: [],//去结算商品Ids
|
|
|
|
|
|
},
|
|
|
- computed: {
|
|
|
-
|
|
|
+ watch:{
|
|
|
+ listData: {
|
|
|
+ handler: function() {
|
|
|
+ console.log('obj.a changed');
|
|
|
+ },
|
|
|
+ immediate: true,
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
getCartLists: function () {
|
|
@@ -28,6 +37,7 @@ var shoppingCart = new Vue({
|
|
|
_self.kindCount = r.data.kindCount;
|
|
|
_self.totalCount = r.data.totalCount;
|
|
|
_self.totalPrice = r.data.totalPrice;
|
|
|
+ _self.promotionsList = r.data.promotions;
|
|
|
// 默认全选
|
|
|
_self.listData.forEach(function(supplier){
|
|
|
supplier.checked = true;
|
|
@@ -38,6 +48,7 @@ var shoppingCart = new Vue({
|
|
|
}
|
|
|
});
|
|
|
_self.allChecked = true;
|
|
|
+ _self.computedPrice();
|
|
|
}
|
|
|
_self.listLoading = false;
|
|
|
});
|
|
@@ -102,27 +113,64 @@ var shoppingCart = new Vue({
|
|
|
_self.computedPrice();
|
|
|
});
|
|
|
},
|
|
|
+ setPromotions:function(){
|
|
|
+ var _self = this;
|
|
|
+ this.promotionsList.forEach(function(promotions){
|
|
|
+ promotions.productList.forEach(function(product){
|
|
|
+ _self.listData.map(function(supplier){
|
|
|
+ supplier.cartList.map(function(cart){
|
|
|
+ if(product.productId === cart.productId){
|
|
|
+ product.number = cart.number
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
computedPrice: function(){
|
|
|
var _self = this;
|
|
|
this.$nextTick(function(){
|
|
|
+ var originalPrice = 0;
|
|
|
+ var reducedPrice = 0;
|
|
|
var totalPrice = 0;
|
|
|
var kindCount = 0;
|
|
|
var totalCount = 0;
|
|
|
_self.listData.forEach(function(supplier){
|
|
|
+ var supplierOriginalPrice = 0;
|
|
|
var supplierPrice = 0;
|
|
|
if(supplier.cartList.length>0){
|
|
|
supplier.cartList.forEach(function(cart){
|
|
|
if (_self.submitIds.includes(cart.productId*1)){
|
|
|
+ supplierOriginalPrice += cart.originalPrice*cart.number;
|
|
|
supplierPrice += cart.price*cart.number;
|
|
|
kindCount += 1;
|
|
|
totalCount += cart.number;
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ supplier.originalPrice = supplierOriginalPrice;
|
|
|
+ originalPrice += supplier.originalPrice;
|
|
|
supplier.totalPrice = supplierPrice;
|
|
|
totalPrice += supplier.totalPrice;
|
|
|
});
|
|
|
- _self.totalPrice = totalPrice;
|
|
|
+ _self.promotionsList.forEach(function(promotions){
|
|
|
+ if(promotions.mode ===2){
|
|
|
+ var promotionsPrice = 0;
|
|
|
+ promotions.productList.forEach(function(product){
|
|
|
+ promotionsPrice += product.number * product.price;
|
|
|
+ });
|
|
|
+ if(promotionsPrice>=promotions.touchPrice){
|
|
|
+ reducedPrice += promotions.reducedPrice;
|
|
|
+ }
|
|
|
+ } else if (promotions.type===1 && promotions.mode ===1) {
|
|
|
+ promotions.productList.forEach(function(product){
|
|
|
+ reducedPrice += product.number * (product.originalPrice - product.price);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ _self.reducedPrice = reducedPrice;
|
|
|
+ _self.originalPrice = originalPrice;
|
|
|
+ _self.totalPrice = totalPrice-reducedPrice;
|
|
|
_self.kindCount = kindCount;
|
|
|
_self.totalCount = totalCount;
|
|
|
});
|
|
@@ -150,18 +198,23 @@ var shoppingCart = new Vue({
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ // 设置优惠数量
|
|
|
+ this.setPromotions();
|
|
|
// 计算价格
|
|
|
this.computedPrice();
|
|
|
// 更新购物车
|
|
|
var _self = this;
|
|
|
this.$nextTick(function(){
|
|
|
- tokenAjax("post", "/shoppingCart/update", {
|
|
|
- userID: this.userId,
|
|
|
- productID: cart.productId,
|
|
|
- productCount: cart.number
|
|
|
- },function (res) {
|
|
|
- console.log(res);
|
|
|
- });
|
|
|
+ _self.updateCart(cart);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ updateCart: function(cart){
|
|
|
+ tokenAjax("post", "/shoppingCart/update", {
|
|
|
+ userID: this.userId,
|
|
|
+ productID: cart.productId,
|
|
|
+ productCount: cart.number
|
|
|
+ },function (res) {
|
|
|
+ console.log(res);
|
|
|
});
|
|
|
},
|
|
|
deleteCart: function(cartId){
|