newsNotice.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view style="background-color: #fff;height:1135px;" >
  3. <u-navbar title="新闻公告"></u-navbar>
  4. <view class="options">
  5. <view class="options-item">
  6. <u-tabs :list="tabList" :current="current" @change="change" :show-bar="false" active-color="#333" inactive-color="#c4c0c0"></u-tabs>
  7. </view>
  8. </view>
  9. <view class="swiper-box">
  10. <u-swiper :list="list" mode="dot">
  11. </u-swiper>
  12. </view>
  13. <view class="news">
  14. <view class="news-content" v-for="(item,index) in newsList" :key="item.id" @click="gotoUrl('pages/article/articleDetails?id=' + item.id)">
  15. <view class="content-text">
  16. {{item.title}}
  17. <view class="news-time">{{item.createTime.slice(5)}}</view>
  18. </view>
  19. <view class="content-img">
  20. <img :src="item.pic" alt="">
  21. </view>
  22. </view>
  23. </view>
  24. <u-divider v-if="newsList.length ==recordsTotal">已经到底了</u-divider>
  25. </view>
  26. </template>
  27. <script>
  28. import * as newsApi from '@/apis/news.js'
  29. export default {
  30. data() {
  31. return {
  32. tabList: [
  33. {name: '通知公告',type: '1'},
  34. {name: '行业新闻',type: '2'},
  35. {name: '优惠活动',type: '3'},
  36. ],
  37. current: 0,
  38. newsList: [],
  39. newsType: '1',
  40. pageIndex: 1,
  41. recordsTotal: 0,
  42. list: [{
  43. image: '/static/img/快乐周末游1x (1).png',
  44. }
  45. ],
  46. }
  47. },
  48. onReachBottom() {
  49. if (this.newsList.length < this.recordsTotal) {
  50. this.myLoadmore();
  51. }
  52. },
  53. onReady() {
  54. this.getNewsList();
  55. },
  56. methods: {
  57. change(index) {
  58. this.current = index;
  59. this.newsType = this.tabList[index].type;
  60. this.getNewsList(true)
  61. },
  62. getNewsList(bl) {
  63. uni.showLoading({
  64. title: "加载中",
  65. mask: true,
  66. })
  67. if (bl) {
  68. this.newsList = [];
  69. this.pageIndex = 1;
  70. }
  71. newsApi.newsInfoList({
  72. pageIndex: 1,
  73. pageSize: 10,
  74. type: this.newsType
  75. }).then((res) => {
  76. uni.hideLoading()
  77. this.newsList = [
  78. ...this.newsList,
  79. ...res.data.data
  80. ];
  81. this.recordsTotal = res.data.recordsTotal
  82. }).catch(error => {
  83. uni.showToast({
  84. title: error,
  85. icon: "none"
  86. })
  87. })
  88. },
  89. myLoadmore() {
  90. this.pageIndex += 1;
  91. this.getNewsList()
  92. },
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. .options{
  98. width: 60%;
  99. height: 44px;
  100. line-height: 44px;
  101. display: flex;
  102. justify-content: space-between;
  103. margin: 0px 16px ;
  104. }
  105. .swiper-box{
  106. width: 343px;
  107. height: 146px;
  108. margin-left: 16px;
  109. }
  110. .news {
  111. background-color: #fff;
  112. margin: 0 16px ;
  113. border-radius: 8px;
  114. .news-content {
  115. display: flex;
  116. justify-content: space-between;
  117. margin-bottom: 24px;
  118. .content-text {
  119. width: 211px;
  120. height: 42px;
  121. line-height: 21px;
  122. color: #101010;
  123. text-align: left;
  124. font-size: 14px
  125. }
  126. ;
  127. .content-img {
  128. width: 100px;
  129. height: 80px;
  130. background-color: #777777;
  131. border-radius: 4px;
  132. overflow: hidden;
  133. img {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. .news-time {
  139. margin-top: 12px;
  140. color: #999999;
  141. width: 80px;
  142. height: 20px;
  143. font-size: 14px;
  144. }
  145. }
  146. }
  147. </style>