index.vue 2.6 KB

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