index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view>
  3. <view class="tab">
  4. <u-tabs :list="tab" :current="current" keyName="dictLabel" @click="click"></u-tabs>
  5. </view>
  6. <view class="list">
  7. <view class="item" v-for="(item, index) in list" :key="index" @click="detail(item.id)">
  8. <view class="title omit">{{ item.title }}</view>
  9. <view class="desc">
  10. <text>{{ item.type }}</text>
  11. <text>发布于 {{ item.createTime }}</text>
  12. </view>
  13. </view>
  14. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  15. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. current: 0,
  24. tab: [],
  25. list: [],
  26. param: { pageNum: 1, pageSize: 10 },
  27. loadMore: true
  28. };
  29. },
  30. onLoad(e) {
  31. this.getType();
  32. this.getData();
  33. },
  34. methods: {
  35. click(e) {
  36. this.current = e.index;
  37. this.param.type = e.dictValue;
  38. this.refresh();
  39. },
  40. getData() {
  41. this.http.request({
  42. url: '/app/news/list',
  43. data: this.param,
  44. loading: 'false',
  45. success: (res) => {
  46. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  47. res.data.rows.forEach((item) => {
  48. item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
  49. this.list.push(item);
  50. });
  51. }
  52. });
  53. },
  54. getType() {
  55. this.http.request({
  56. url: '/app/common/type/news_type',
  57. loading: 'false',
  58. success: (res) => {
  59. this.tab = res.data.data;
  60. this.tab.unshift({ dictLabel: '全部新闻', dictValue: '' });
  61. }
  62. });
  63. },
  64. detail(id) {
  65. uni.navigateTo({ url: '/pages/news/detail?id=' + id });
  66. },
  67. //刷新数据
  68. refresh() {
  69. this.loadMore = true;
  70. this.param.pageNum = 1;
  71. this.list = [];
  72. this.getData();
  73. }
  74. },
  75. //下拉刷新
  76. onPullDownRefresh() {
  77. setTimeout(() => {
  78. this.refresh();
  79. uni.stopPullDownRefresh();
  80. }, 1000);
  81. },
  82. //上拉加载
  83. onReachBottom() {
  84. if (this.loadMore) {
  85. this.param.pageNum++;
  86. this.getData();
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="scss">
  92. .list {
  93. padding: 12px;
  94. .item {
  95. background-color: white;
  96. border-radius: 5px;
  97. padding: 12px;
  98. margin-bottom: 10px;
  99. .title {
  100. font-size: 15px;
  101. font-weight: bold;
  102. }
  103. .desc {
  104. font-size: 14px;
  105. color: $font-c;
  106. padding-top: 7px;
  107. text {
  108. padding-right: 20px;
  109. }
  110. }
  111. }
  112. }
  113. </style>