index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="go('/pages/news/detail?id=' + 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, type: '新闻资讯' },
  27. loadMore: true
  28. };
  29. },
  30. onLoad(e) {
  31. this.param.type = e.type || '新闻资讯';
  32. this.getType();
  33. this.getData();
  34. },
  35. methods: {
  36. click(e) {
  37. this.current = e.index;
  38. this.param.type = e.dictValue;
  39. this.refresh();
  40. },
  41. getData() {
  42. this.http.request({
  43. url: '/app/news/list',
  44. data: this.param,
  45. loading: 'false',
  46. success: (res) => {
  47. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  48. res.data.rows.forEach((item) => {
  49. item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
  50. this.list.push(item);
  51. });
  52. }
  53. });
  54. },
  55. getType() {
  56. this.http.request({
  57. url: '/app/common/type/news_type',
  58. loading: 'false',
  59. success: (res) => {
  60. this.tab = res.data.data;
  61. let obj = this.tab.filter((item) => item.dictLabel == this.param.type);
  62. if (obj.length > 0) {
  63. this.current = this.tab.indexOf(obj[0]);
  64. }
  65. }
  66. });
  67. },
  68. go(url) {
  69. uni.navigateTo({ url: url });
  70. },
  71. //刷新数据
  72. refresh() {
  73. this.loadMore = true;
  74. this.param.pageNum = 1;
  75. this.list = [];
  76. this.getData();
  77. }
  78. },
  79. //下拉刷新
  80. onPullDownRefresh() {
  81. setTimeout(() => {
  82. this.refresh();
  83. uni.stopPullDownRefresh();
  84. }, 1000);
  85. },
  86. //上拉加载
  87. onReachBottom() {
  88. if (this.loadMore) {
  89. this.param.pageNum++;
  90. this.getData();
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. .list {
  97. padding: 12px;
  98. .item {
  99. background-color: white;
  100. border-radius: 5px;
  101. padding: 12px;
  102. margin-bottom: 10px;
  103. .title {
  104. font-size: 15px;
  105. font-weight: bold;
  106. }
  107. .desc {
  108. font-size: 14px;
  109. color: $font-c;
  110. padding-top: 7px;
  111. text {
  112. padding-right: 20px;
  113. }
  114. }
  115. }
  116. }
  117. </style>