; var orderPage = new Vue({ el: "#productList", data: { isRequset:true, noMore: false, listLoading: true, isHandle:false, isAllChecked:false, isProductChecked:false, checkedNum:0, productIds:'', listQuery:{ userId:0, pageNum:1, pageSize:12, }, listData:[], checkedList:[], listRecord: 0, pageInput: '1' }, filters: { NumFormat:function(value) { return Number(value).toFixed(2); } }, computed: { pageTotal: function () { var total = Math.ceil(this.listRecord / this.listQuery.pageSize); return total > 0 ? total : 1; }, showPageBtn: function () { var total = Math.ceil(this.listRecord / this.listQuery.pageSize); total = total > 0 ? total : 1; var index = this.listQuery.pageNum, arr = []; if (total <= 6) { for (var i = 1; i <= total; i++) { arr.push(i); } return arr; } if (index <= 3) return [1, 2, 3, 4, 5, 0, total]; if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total]; return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total]; } }, methods: { toPagination: function (pageNum) {//点击切换分页 if (pageNum <= this.pageTotal) { this.listQuery.pageNum = pageNum; this.getCollectionProductList(); } }, checkNum: function () {//输入跳转分页 if (this.pageInput > this.pageTotal) { this.pageInput = this.pageTotal; } else if (this.pageInput < 1) { this.pageInput = 1; } }, getCollectionProductList: function () { var _self = this; ProductApi.getProductUserLikeList(_self.listQuery,function (response) { if (response.code === 0 ) { var data = response.data; _self.listRecord = data.totalRecord; var list = data.results.map((el,index)=>{ el.isChecked = false; return el }); if(isPC){ _self.listData = list; }else{ _self.listData = _self.listData.concat(list); } console.log('listData',_self.listData) setTimeout(function(){ // 图片懒加载 $("img[data-original]").lazyload(); },500); _self.listLoading = false; _self.requestFlag = true; }else { CAIMEI.Alert(res.msg, '确定'); } }); }, PromotionsFormat:function(promo){//促销活动类型数据处理 if(promo!=null){ if(promo.type == 1 && promo.mode == 1){ return true }else{ return false } } return false }, shoppingCart:function (pros) { var _self = this; ShoppingApi.ShoppingAddCart( { userID:_self.listQuery.userId, productID:pros.productId, productCount:1 }, function (response) { if(response.code === 0){ globalHead.getHeadCart(_self.listQuery.userId); $.confirm({ useBootstrap: false, boxWidth: (isPC?'338px':'74.6vw'), title: false, content:'
商品已成功加入购物车!

当前购物车共'+response.data+'种商品

', closeIcon: true, animation: 'opacity', closeAnimation: 'opacity', animateFromElement: false, scrollToPreviousElement: false, buttons: { login: { text: '去结算', btnClass: 'btn-to-cart', action: function(){ window.location.href = '/shopping/cart.html'; } }, close: { text: '继续购物', btnClass: 'btn-to-goon' } } }); } else { dialog("加入购物车失败!"); } }) }, hanldBuyCart:function (pros,type) {// 1 加入购物车 2 立即购买 var _self = this; console.log('pros',pros) console.log('type',type) if(type == 1) { _self.shoppingCart(pros); }else{ window.location.href = '/shopping/confirm.html?type=2&id='+pros.productId+'&count='+pros.priceGrade; } }, hanldAllAddCart:function () {// 批量加入购物车 var _self = this; if(!_self.isProductChecked){ CAIMEI.dialog('请先选择商品',false); } _self.productIds = _self.checkedList.join(",") }, hanldCancel:function (pros) {// 取消收藏 var _self = this; CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () { ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:pros.productId+','},function(response){ if(response.code == 0){ CAIMEI.dialog('取消收藏成功',true,function () { _self.getCollectionProductList(); }); }else{ CAIMEI.Alert(response.msg, '确定', false); } }) }) }, hanldAllCancel:function () {// 批量取消收藏 var _self = this; var checkedList =[]; _self.productIds = ''; if(!_self.isProductChecked){ CAIMEI.dialog('请先选择商品',false); return; } _self.listData.forEach((el)=>{ if(el.isChecked){ checkedList.push(el.productId) } }) _self.productIds = checkedList.join(",") console.log('_self.productIds2',_self.productIds); CAIMEI.Modal('确定要取消收藏吗?','取消','确定',function () { ProductApi.getDeleteUserLike({userId:_self.listQuery.userId,productIds:_self.productIds},function(response){ if(response.code == 0){ CAIMEI.dialog('取消收藏成功',true,function () { _self.getCollectionProductList(); }); }else{ CAIMEI.Alert(response.msg, '确定', false); } }) }) }, isCheckedAll(){//全选 var _self = this; _self.isAllChecked = !_self.isAllChecked; _self.listData.forEach((el)=>{ el.isChecked = _self.isAllChecked; }) if(_self.isAllChecked){ _self.isProductChecked = true; _self.checkedNum = _self.listData.length; }else{ _self.isProductChecked = false; _self.checkedNum = 0; } }, checkedSoperv:function (pros) {// 勾选 console.log(pros) var _self = this; var goodsCheckedLength = 0; pros.isChecked = !pros.isChecked _self.listData.forEach(el => { if(el.isChecked) { goodsCheckedLength++; } }) _self.checkedNum = goodsCheckedLength; _self.isAllChecked = goodsCheckedLength === _self.listData.length; if(goodsCheckedLength>0){ _self.isProductChecked = true }else{ _self.isProductChecked = false } }, showHandle:function () {// 显示批量操作 this.isHandle = true; }, hideHandle:function () { this.isHandle = false; } }, mounted: function () { var _self = this; if(globalUserData){ _self.userId = globalUserData.userId; _self.listQuery.userId = this.userId; _self.getCollectionProductList(); } } });