|
@@ -13,17 +13,6 @@ var shoppingCart = new Vue({
|
|
|
allChecked: true,
|
|
|
submitIds: [],//去结算商品Ids
|
|
|
|
|
|
- cartList:[],
|
|
|
- ischecked:false,
|
|
|
- isCheckAll:false,
|
|
|
- isStock:'',
|
|
|
- allPrice:0,//每个店铺下的总价
|
|
|
- tipsName:false,
|
|
|
- fromMessage:'',//提示文字
|
|
|
- isShow:false,
|
|
|
- ladderPriceslist:[],//阶梯价
|
|
|
- showIndex:''
|
|
|
-
|
|
|
},
|
|
|
computed: {
|
|
|
|
|
@@ -138,122 +127,42 @@ var shoppingCart = new Vue({
|
|
|
_self.totalCount = totalCount;
|
|
|
});
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- changeCountAdd:function(item,pros){//商品数量加加
|
|
|
- var _this = this;
|
|
|
- console.log(item,pros)
|
|
|
- if(pros.step === 2){
|
|
|
- pros.isStep = false;
|
|
|
- pros.number += pros.min;
|
|
|
- _this.isStock = false
|
|
|
- }else{
|
|
|
- pros.number++;
|
|
|
- _this.isStock = false
|
|
|
- }
|
|
|
- _this.totalPeice(item)
|
|
|
- },
|
|
|
- changeCountSub:function(item,pros){//商品数量减减
|
|
|
- var _this = this;
|
|
|
- if(pros.number<=pros.min){
|
|
|
- pros.number= pros.min;
|
|
|
- _this.tipsName = true;
|
|
|
- _this.fromMessage = '该商品最小起批量为'+pros.min;
|
|
|
- setTimeout(function(){
|
|
|
- _this.tipsName = false;
|
|
|
- },1000);
|
|
|
- return
|
|
|
- }else{
|
|
|
- if(pros.step === 2){
|
|
|
- pros.isStep = false;
|
|
|
- pros.number -= pros.min
|
|
|
- }else{
|
|
|
- pros.number--
|
|
|
- }
|
|
|
- _this.tipsName = false;
|
|
|
- _this.totalPeice(item)
|
|
|
- }
|
|
|
- },
|
|
|
- totalPeice:function(item){ //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
|
|
|
- var prosPrice=0;
|
|
|
- var productsList=item.cartList;
|
|
|
- productsList.forEach(function(pros){
|
|
|
- prosPrice+=pros.price*pros.number;
|
|
|
- item.allPrice = prosPrice;
|
|
|
- })
|
|
|
- },
|
|
|
- changeNnmber:function($event,item,pros){//输入商品数量更新
|
|
|
- var _value = event.target.value;
|
|
|
- var _this = this;
|
|
|
- if(!_value){
|
|
|
- pros.number = pros.min;
|
|
|
- }else if(_value < pros.min){
|
|
|
- _this.tipsName = true;
|
|
|
- _this.fromMessage = '该商品最小起批量为'+pros.min;
|
|
|
- setTimeout(function(){
|
|
|
- _this.tipsName = false;
|
|
|
- },1000);
|
|
|
- pros.number = pros.min;
|
|
|
- }else{
|
|
|
- _this.tipsName = false;
|
|
|
- pros.number = parseInt(_value)
|
|
|
- }
|
|
|
- _this.totalPeice(item)
|
|
|
- },
|
|
|
- checkShop:function (item) {
|
|
|
- var _this = this;
|
|
|
- item.checked = !item.checked;
|
|
|
- _this.setProductChecked(item);
|
|
|
- _this.updateCheckAllBtn();
|
|
|
- console.log(item)
|
|
|
+ cartNumberSub: function(cart){
|
|
|
+ cart.number -= cart.step;
|
|
|
+ if (cart.number<cart.min){
|
|
|
+ cart.number = cart.min;
|
|
|
+ }
|
|
|
+ this.numberChange(cart);
|
|
|
+ },
|
|
|
+ cartNumberAdd: function(cart){
|
|
|
+ cart.number += cart.step;
|
|
|
+ this.numberChange(cart);
|
|
|
},
|
|
|
- setProductChecked:function(item) {
|
|
|
- var products = item.cartList;
|
|
|
- products.forEach(function (pros){
|
|
|
- if(item.checked) {
|
|
|
- // 有效
|
|
|
- pros.productsChecked = true;
|
|
|
- } else {
|
|
|
- pros.productsChecked = false;
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- updateCheckAllBtn:function() {// 全选勾选判断
|
|
|
- var _this = this;
|
|
|
- var goodsCheckedLength = 0,
|
|
|
- disabledListLength = 0,
|
|
|
- goodsList = _this.listData;
|
|
|
- goodsList.forEach(function(item) {
|
|
|
- if(item.checked) {
|
|
|
- goodsCheckedLength++;
|
|
|
- }
|
|
|
- })
|
|
|
- console.log(goodsCheckedLength)
|
|
|
- _this.isCheckAll = goodsCheckedLength === goodsList.length - disabledListLength;
|
|
|
- console.log(_this.isCheckAll)
|
|
|
- },
|
|
|
- showladder:function(index){
|
|
|
- var _this = this;
|
|
|
- _this.showIndex = index;
|
|
|
- console.log(index)
|
|
|
- _this.isShow = !_this.isShow;
|
|
|
- },
|
|
|
- activity:function () {
|
|
|
- var _this = this;
|
|
|
- _this.isShow = !_this.isShow;
|
|
|
+ cartNumberChange: function(cart){
|
|
|
+ cart.number = Math.ceil(cart.number/cart.step)*cart.step;
|
|
|
+ this.numberChange(cart);
|
|
|
},
|
|
|
- activeBtn:function () {
|
|
|
- var _this = this;
|
|
|
- _this.isShow = false;
|
|
|
+ numberChange: function(cart){
|
|
|
+ if(cart.ladderFlag){
|
|
|
+ cart.ladderPrices.forEach(function(ladder){
|
|
|
+ if(cart.number>=ladder.buyNum){
|
|
|
+ cart.price = ladder.buyPrice;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 计算价格
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
},
|