list.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="app">
  3. <view class="new-list" @tap="tapOpen" :data-url="'index?id=' + item.id" v-for="(item,index) of noticeList" :key="index" >
  4. <view class="name">{{ item.title }}</view>
  5. <view class="time">{{ item.time }}</view>
  6. </view>
  7. <view class="loading fx-r fx-ac fx-bc" v-if="page.isFrite && !page.isFoot">
  8. <image src="../../static/img/xloading.png"></image>
  9. <text>正在载入更多...</text>
  10. </view>
  11. <view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. noticeList: [],
  19. page:{
  20. isFirst:false,
  21. isLoad:false,
  22. isFoot:false,
  23. page:1
  24. }
  25. }
  26. },
  27. onLoad() {
  28. this.getData(true);
  29. },
  30. onReachBottom() {
  31. if(this.page.isFoot || this.page.isLoad) {
  32. return;
  33. }
  34. this.page.page ++;
  35. this.getData();
  36. },
  37. methods: {
  38. /**
  39. * 打开
  40. * @param {Object} ev
  41. */
  42. tapOpen:function(ev){
  43. let url = ev.currentTarget.dataset.url;
  44. this.utils.navigateTo(url);
  45. },
  46. getData:function(isPull = false){
  47. if(this.page.isLoad) return;
  48. this.page.isLoad = true;
  49. if(isPull) {
  50. this.page.page = 1;
  51. this.page.isLoad = false;
  52. this.page.isFoot = false;
  53. }
  54. uni.showLoading({ title: '获取数据中..' });
  55. var post = {};
  56. post.page = this.page.page;
  57. this
  58. .request
  59. .post("newsList",post)
  60. .then(res => {
  61. uni.hideLoading();
  62. this.page.isFirst = true;
  63. this.page.isLoad = false;
  64. if(isPull) {
  65. this.noticeList = res.data.list;
  66. } else {
  67. this.noticeList = this.noticeList.concat(res.data.list);
  68. }
  69. //是否到底
  70. if(res.data.list.length != res.data.pageSize) {
  71. this.page.isFoot = true;
  72. }
  73. })
  74. .catch(res=>{
  75. console.log(res);
  76. uni.hideLoading();
  77. uni.showModal({title: '系统提示',content: '加载失败,返回在尝试',showCancel: false});
  78. });
  79. },
  80. }
  81. }
  82. </script>
  83. <style>
  84. page{background-color: #fff;}
  85. .new-list{padding: 30rpx;border-bottom: 1px solid #E9E9E9;}
  86. .new-list .name{font-size: 28rpx;color: #333333;width: 100%;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;}
  87. .new-list .time{font-size: 20rpx;color: #999999;margin-top: 18rpx;}
  88. </style>