var instrumentList = new Vue({ el: "#instrumentList", data: { searchFlag: false, listLoading: true, requestFlag: true, noMore: false, params: { size: 0, num: 0, keyword: "" }, listData: [], listRecord: 0, pageInput: '' }, 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; } }, getListByKeyword: function () { var _self = this; $.getJSON(spiServer+"/search/query/equipment", { keyword: this.params.keyword, pageSize: this.params.size, pageNum: this.params.num }, function (r) { if (r.code === 0 && r.data) { var result = JSON.parse(r.data); _self.listRecord = result.total; if(isPC){ _self.listData = result.items; }else{ _self.listData = _self.listData.concat(result.items); } } _self.listLoading = false; _self.requestFlag = true; }) }, }, 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 = 20; this.params.num = 1; } this.params.keyword = getUrlParam("keyword") ? getUrlParam("keyword") : ""; // 获取列表数据 this.getListByKeyword(); }, mounted: function () { var searchTypeID = getUrlParam("searchTypeID"); 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){ _self.params.num = next; if (_self.requestFlag){ console.log(_self.params); // 获取列表数据 _self.getListByKeyword(); } _self.requestFlag = false; }else{ //到底了 _self.noMore = true; $('footer').removeClass("noneImportant"); } } }); } } });