var promotionsList = new Vue({ el: "#promotionsList", data: { userId: 0, listLoading: true, requestFlag: true, noMore: false, params: { id: 0, size: 0, num: 0 }, promotions: {}, listData: [], listRecord: 0, pageInput: '1', userIdentity: '', userToken: '' }, computed: { pageTotal: function () { var total = Math.ceil(this.listRecord / this.params.size); return total > 0 ? total : 1; }, showPageBtn: function () { var total = Math.ceil(this.listRecord / this.params.size); total = total > 0 ? total : 1; var index = this.params.num, 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) { var params = {pageNum: pageNum}; window.location.href = updateUrlParam(params); } }, checkNum: function () { if (this.pageInput > this.pageTotal) { this.pageInput = this.pageTotal; } else if (this.pageInput < 1) { this.pageInput = 1; } }, getPromotions: function(){ var _self = this; ProductApi.GetPromotionsInfo({promotionsId:this.params.id},function (res) { if (res.code === 0 && res.data) { _self.promotions = res.data; _self.getProductsByPromotions(); }else{ CAIMEI.Alert("该促销活动已过期或不存在!", '确定', true, function(){ window.location.href="/"; }); } }); }, getProductsByPromotions: function () { var _self = this; ProductApi.GetPromotionsProduct({ promotionsId: this.params.id, pageSize: this.params.size, pageNum: this.params.num, identity:this.userIdentity },function (res) { if (res.code === 0 && res.data) { _self.listRecord = res.data.total; var resultData = res.data.list; var productIdArr = []; resultData.map(function (item) { productIdArr.push(item.productId) }); setProductPrice(resultData, productIdArr.join(","), _self.userId, function () { _self.$forceUpdate(); }); if(isPC){ _self.listData = resultData; }else{ _self.listData = _self.listData.concat(resultData); } console.log(_self.listData); _self.listLoading = false; _self.requestFlag = true; }else{ CAIMEI.Alert(res.msg, '确定'); } }); } }, created: function () { if(isPC){ this.params.size = getUrlParam("pageSize") ? getUrlParam("pageSize") * 1 : 20; this.params.num = getUrlParam("pageNum") ? getUrlParam("pageNum") * 1 : 1; }else{ this.params.size = 10; this.params.num = 1; } this.params.id = getUrlParam("id") ? getUrlParam("id") : 0; // 搜索框赋值 $('#topSearch').find('[data-select]').attr("data-select", 0).text("产品"); $('#topSearch').find('.jqSelect').find('select').val(0); $('#topSearch').find('.keyword').val(getUrlParam("keyword")); if(globalUserData){ this.userId = globalUserData.userId; this.userIdentity = globalUserData.identity; this.userToken = globalUserData.token; } // 获取页面数据 this.getPromotions(); }, mounted: function () { var _self = this; if(!isPC){ $('footer').addClass("noneImportant"); //移动端上垃加载更多 $(window).on('scroll', function(){ var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = window.innerHeight; if (scrollTop + windowHeight >= scrollHeight) { //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作 var totalPage = Math.ceil(_self.listRecord / _self.params.size)?Math.ceil(_self.listRecord / _self.params.size):1; var next = _self.params.num+1; if(next <= totalPage){ if (_self.requestFlag){ _self.params.num = next; _self.getPromotions(); } _self.requestFlag = false; }else{ //到底了 _self.noMore = true; $('footer').removeClass("noneImportant"); } } }); } } });