var app = new Vue({ 'el': '#app', 'data': { // 列表数据 dataList: [], // 参数 params: { page: 1, pageSize: 10, }, timeIds: [], loading: false, loaded: false, }, created: function(){ this.getDataList(0); }, mounted: function(){ var _this = this; $(window).scroll(function(){ var scrollHeight = $(this).scrollTop(); var height = $('body')[0].scrollHeight; var docHeight = $(this).outerHeight(); if(docHeight+scrollHeight >= height){ if(_this.loading || _this.loaded){ return false; } _this.params.page++; _this.getDataList(1); } }) }, methods: { // 获取列表数据 getDataList: function(more){ var _this = this; $.hideLoading(); $.showLoading("数据加载中..."); $.post('/weixin/print/collageList', _this.params, function (res) { $.hideLoading(); _this.loading = false; if (res.code == 'success') { if(res.data.data.length<=0 && _this.params.page > 1){ _this.loaded = true; $.toast("已加载完全部...",'text'); return false; } if(more){ $.each(res.data.data, function(k,item){ console.log(item); _this.dataList.push(item); }); }else{ _this.dataList = res.data.data } if(_this.dataList){ _this.timeLock(_this.dataList); } }else if(res.code == 'login'){ login(res.data.url); } }, "json"); }, // 倒计时 timeLock: function (dataList) { var _this = this; $.each(dataList, function(k,item){ var time = item.closeTime; if (time > 0) { _this.timeIds[item.id] = setInterval(function () { time--; var text = '00:00:00'; if (time > 0) { var hour = Math.floor(time / 3600); var minute = Math.floor(time / 60) % 60; var second = time % 60; hour = hour < 10 ? '0' + hour : hour; minute = minute < 10 ? '0' + minute : minute; second = second < 10 ? '0' + second : second; text = hour+':'+minute+':'+second; $("#time_"+item.id).html(text); } else { clearInterval(_this.timeId); $("#time_"+item.id).html(text); } }, 1000); } }) }, collage: function(id,num){ if(num<=0){ var _this = this; $.showLoading('当前拼团已成团,请刷新后重试'); setTimeout(function () { _this.getDataList(); }, 1200) return false; } $.actions({ title: '选择操作', actions: [{ text: "确认拼团", className: "color-success", onClick: function() { location.href = '/weixin/print/collage?pt=2&id='+id; } }] }); }, } })