|
@@ -6,20 +6,12 @@ var shoppingCart = new Vue({
|
|
|
userToken: '',
|
|
|
listLoading: true,
|
|
|
listData: [],
|
|
|
- cartList:[],
|
|
|
invalidData: [],
|
|
|
- totalSize: 0,
|
|
|
+ kindCount: 0,
|
|
|
totalCount: 0,
|
|
|
totalPrice: 0,
|
|
|
- ischecked:false,
|
|
|
- isCheckAll:false,
|
|
|
- isStock:'',
|
|
|
- allPrice:0,//每个店铺下的总价
|
|
|
- tipsName:false,
|
|
|
- fromMessage:'',//提示文字
|
|
|
- isShow:false,
|
|
|
- ladderPriceslist:[],//阶梯价
|
|
|
- showIndex:''
|
|
|
+ allChecked: true,
|
|
|
+ submitIds: [],//去结算商品Ids
|
|
|
|
|
|
},
|
|
|
computed: {
|
|
@@ -33,9 +25,19 @@ var shoppingCart = new Vue({
|
|
|
if (r.code === 0 && r.data) {
|
|
|
_self.listData = r.data.list;
|
|
|
_self.invalidData = r.data.invalid;
|
|
|
- _self.totalSize = r.data.totalSize;
|
|
|
+ _self.kindCount = r.data.kindCount;
|
|
|
_self.totalCount = r.data.totalCount;
|
|
|
_self.totalPrice = r.data.totalPrice;
|
|
|
+ // 默认全选
|
|
|
+ _self.listData.forEach(function(supplier){
|
|
|
+ supplier.checked = true;
|
|
|
+ if(supplier.cartList.length>0){
|
|
|
+ supplier.cartList.forEach(function(cartItem){
|
|
|
+ _self.submitIds.push(cartItem.productId);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ _self.allChecked = true;
|
|
|
}
|
|
|
_self.listLoading = false;
|
|
|
});
|
|
@@ -55,111 +57,118 @@ var shoppingCart = new Vue({
|
|
|
$(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.ladder').hide();
|
|
|
if(!isPC){looseBody();}
|
|
|
},
|
|
|
- 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)
|
|
|
+ ckeckSupplier: function(event, supplierChecked){
|
|
|
+ var el = event.currentTarget;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ _self.computedPrice();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ckeckAll: function(){
|
|
|
+ var _self = this;
|
|
|
+ this.$nextTick(function(){
|
|
|
+ if (_self.allChecked) {
|
|
|
+ _self.submitIds = [];
|
|
|
+ _self.listData.forEach(function(supplier){
|
|
|
+ supplier.checked = 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.checked = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ _self.computedPrice();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ computedPrice: function(){
|
|
|
+ var _self = this;
|
|
|
+ this.$nextTick(function(){
|
|
|
+ var totalPrice = 0;
|
|
|
+ var kindCount = 0;
|
|
|
+ var totalCount = 0;
|
|
|
+ _self.listData.forEach(function(supplier){
|
|
|
+ var supplierPrice = 0;
|
|
|
+ if(supplier.cartList.length>0){
|
|
|
+ supplier.cartList.forEach(function(cart){
|
|
|
+ if (_self.submitIds.includes(cart.productId*1)){
|
|
|
+ supplierPrice += cart.price*cart.number;
|
|
|
+ kindCount += 1;
|
|
|
+ totalCount += cart.number;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ supplier.totalPrice = supplierPrice;
|
|
|
+ totalPrice += supplier.totalPrice;
|
|
|
+ });
|
|
|
+ _self.totalPrice = totalPrice;
|
|
|
+ _self.kindCount = kindCount;
|
|
|
+ _self.totalCount = totalCount;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ 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);
|
|
|
+ },
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
- activeBtn:function () {
|
|
|
- var _this = this;
|
|
|
- _this.isShow = false;
|
|
|
+ deleteCart: function(cartId){
|
|
|
+ alertInfo("确定要删除该商品?",function(){
|
|
|
+ // 删除逻辑
|
|
|
+ alert("test")
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
},
|