notices.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 10,
  10. lt: 1,
  11. },
  12. loading: false,
  13. loaded: false,
  14. },
  15. created: function(){
  16. this.params.lt = getParam('type');
  17. this.getDataList(0);
  18. },
  19. mounted: function(){
  20. var _this = this;
  21. $(window).scroll(function(){
  22. var scrollHeight = $(this).scrollTop();
  23. var height = $('body')[0].scrollHeight;
  24. var docHeight = $(this).outerHeight();
  25. if(docHeight+scrollHeight >= height){
  26. if(_this.loading || _this.loaded){
  27. return false;
  28. }
  29. _this.params.page++;
  30. _this.getDataList(1);
  31. }
  32. })
  33. },
  34. methods: {
  35. // 获取列表数据
  36. getDataList: function(more){
  37. var _this = this;
  38. _this.loading = true;
  39. if(_this.params.page == 1){
  40. _this.dataList = [];
  41. }
  42. $.showLoading("数据加载中...");
  43. $.post('/weixin/member/getNotices', _this.params, function (res) {
  44. _this.loading = false;
  45. $.hideLoading();
  46. if (res.code == 'success') {
  47. if(res.data.data.length<=0 && _this.params.page > 1){
  48. _this.loaded = true;
  49. $.toast("已加载完全部...",'text');
  50. return false;
  51. }
  52. if(more){
  53. $.each(res.data.data, function(k,item){
  54. _this.dataList.push(item);
  55. });
  56. }else{
  57. _this.dataList = res.data.data
  58. }
  59. }else if(res.code == 'login'){
  60. login(res.data.url);
  61. }
  62. }, "json");
  63. }
  64. }
  65. })