list.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <view class="search">
  4. <u-search placeholder="搜索资讯" v-model="param.title" bgColor="white" @search="refresh()" :animation="true" actionText="取消" @clear="refresh()"></u-search>
  5. </view>
  6. <view class="list">
  7. <view class="news_item" v-for="(item, index) in list" :key="index" @click="detail(item)">
  8. <image src="../../static/tp.jpg" mode="aspectFill" class="img"></image>
  9. <view class="con">
  10. <view class="title ellip">{{ item.title }}</view>
  11. <view class="source omit">{{ item.source }}</view>
  12. <view class="releaseTime">{{ item.releaseTime }}</view>
  13. </view>
  14. </view>
  15. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  16. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. list: [],
  25. param: { pageNo: 1, pageSize: 10 },
  26. loadMore: true
  27. };
  28. },
  29. onLoad(e) {
  30. if (e.keyword) {
  31. this.param.title = e.keyword;
  32. this.refresh();
  33. } else {
  34. this.getData();
  35. }
  36. },
  37. methods: {
  38. getData() {
  39. this.http.request({
  40. url: '/level-one-server/app/TbPortNews/getPortNewsList',
  41. data: this.param,
  42. loading: 'false',
  43. success: res => {
  44. this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
  45. this.list.push(...res.data.data);
  46. }
  47. });
  48. },
  49. detail(item) {
  50. uni.navigateTo({ url: '/pages/news/detail?id=' + item.id });
  51. },
  52. //刷新数据
  53. refresh() {
  54. this.loadMore = true;
  55. this.param.pageNo = 1;
  56. this.list = [];
  57. this.getData();
  58. }
  59. },
  60. //下拉刷新
  61. onPullDownRefresh() {
  62. setTimeout(() => {
  63. this.refresh();
  64. uni.stopPullDownRefresh();
  65. }, 1000);
  66. },
  67. //上拉加载
  68. onReachBottom() {
  69. if (this.loadMore) {
  70. this.param.pageNo++;
  71. this.getData();
  72. }
  73. }
  74. };
  75. </script>
  76. <style lang="scss">
  77. page {
  78. background-color: $pg;
  79. }
  80. .list {
  81. padding: 12px;
  82. }
  83. </style>