yujing-list.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. (function() {
  2. Vue.component('yujing-list', {
  3. template: '<div style="position:relative;height:100%;">\
  4. <div class="sk-spinner sk-spinner-chasing-dots" v-show="!isRequestEnd" style="top: 50%;left:50%;margin-left:-0.1rem;margin-top: -0.1rem;position:absolute;">\
  5. <div class="sk-dot1"></div>\
  6. <div class="sk-dot2"></div>\
  7. </div>\
  8. <div id="wrapper" style="overflow: hidden;" v-show="isRequestEnd">\
  9. <div id="scroller">\
  10. <div id="pullDown" style="display:none;">\
  11. <div class="pullDownLabel"></div>\
  12. </div>\
  13. <div class="pulldown-tips">下拉刷新</div>\
  14. <div class="div-yujing-content">\
  15. <div class="mt32" v-for="(yujing,index) in yujingData">\
  16. <div class="c-f20 c-B5E1FC">{{yujing.create_time}}</div>\
  17. <div class="c-f20 c-B5E1FC mt8" v-if="yujing.address == null">地址暂无&emsp;{{yujing.sender_name}}&emsp;{{yujing.value2Name}}\
  18. <span class="c-E9350B ml20 c-f20">异常</span>\
  19. </div>\
  20. <div class="c-f20 c-B5E1FC mt8" v-else>{{yujing.address}}&emsp;{{yujing.sender_name}}&emsp;{{yujing.value2Name}}\
  21. <span class="c-E9350B ml20 c-f20">异常</span>\
  22. </div>\
  23. </div>\
  24. </div>\
  25. <div id="pullUp">\
  26. <div class="pullUpLabel">加载更多</div>\
  27. </div>\
  28. </div>\
  29. </div>\
  30. </div>',
  31. props: [],
  32. data: function() {
  33. return {
  34. yujingData: [],
  35. page: 1,
  36. pageSize: 50,
  37. myScroll: null,
  38. isEnd: false,
  39. loadingStep: 0,
  40. isRequestEnd:false
  41. }
  42. },
  43. mounted: function() {
  44. var _self = this;
  45. var pullDown = $("#pullDown"),
  46. pullUp = $("#pullUp"),
  47. pullDownLabel = $("#pullDown .pullDownLabel"),
  48. pullUpLabel = $("#pullUp .pullUpLabel");
  49. //初始化请求数据
  50. getRequestData();
  51. _self.myScroll = new IScroll("#wrapper", {
  52. scrollbars: "custom",
  53. mouseWheel: true,
  54. interactiveScrollbars: true,
  55. shrinkScrollbars: false,
  56. fadeScrollbars: false,
  57. scrollY: true,
  58. probeType: 2,
  59. resizeScrollbars: false
  60. // bindToWrapper:true
  61. });
  62. _self.myScroll.on("scroll", function() {
  63. if(this.y > 40) { //下拉刷新操作
  64. $(".pulldown-tips").hide();
  65. pullDown.addClass("refresh").show();
  66. pullDownLabel.text("松手刷新数据");
  67. _self.loadingStep = 1;
  68. pullDownAction(_self);
  69. } else if(this.y <= this.maxScrollY &&!_self.isEnd) { //上拉加载更多
  70. pullUp.addClass("refresh").show();
  71. pullUpLabel.text("正在载入");
  72. _self.loadingStep = 1;
  73. pullUpAction(_self);
  74. }
  75. });
  76. _self.myScroll.on("scrollEnd", function() {
  77. if(_self.loadingStep == 1) {
  78. if(pullDown.hasClass("refresh")) { //下拉刷新操作
  79. pullDown.removeClass("refresh").addClass("loading");
  80. pullDownLabel.text("正在刷新");
  81. _self.loadingStep = 2;
  82. pullDownAction(_self);
  83. }
  84. }
  85. });
  86. document.addEventListener('touchmove', function(e) {
  87. e.preventDefault();
  88. }, false);
  89. //下拉刷新
  90. function pullDownAction() {
  91. setTimeout(function() {
  92. _self.page = 1;
  93. pullDown.hide();
  94. getRequestData();
  95. loadingStep = 0;
  96. $(".pulldown-tips").show();
  97. _self.myScroll.refresh();
  98. }, 400);
  99. }
  100. //上拉加载
  101. function pullUpAction() {
  102. if(!_self.isEnd) {
  103. setTimeout(function() {
  104. pullUp.hide();
  105. _self.page++;
  106. getRequestData();
  107. _self.myScroll.refresh();
  108. loadingStep = 0;
  109. }, 400);
  110. }
  111. }
  112. function getRequestData() {
  113. //警报信息
  114. intelligentAPI.warningInformationAlarm({
  115. page: _self.page,
  116. pageSize: _self.pageSize
  117. }).then(function(res) {
  118. if(res.status == 200) {
  119. var reqData = res.data;
  120. if(_self.page == 1) {
  121. _self.yujingData = reqData;
  122. } else {
  123. var dataArr = _.map(reqData, function(data) {
  124. _self.yujingData.push(data);
  125. return data;
  126. })
  127. }
  128. if(reqData.length < _self.pageSize) {
  129. _self.isEnd = true;
  130. pullUpLabel.text("没有更多数据了...");
  131. }else{
  132. pullUpLabel.text("加载更多");
  133. }
  134. setTimeout(function() {
  135. _self.myScroll.refresh();
  136. }, 500)
  137. _self.isRequestEnd = true;
  138. } else {
  139. toastr.error(res.msg)
  140. }
  141. })
  142. }
  143. }
  144. });
  145. })()