newsNotice.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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" v-if="list.length">
  10. <u-swiper :list="list" @click="clickBanner" :img-mode="'aspectFit'" :name="'picUrl'" >
  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. ],
  44. }
  45. },
  46. onReachBottom() {
  47. if (this.newsList.length < this.recordsTotal) {
  48. this.myLoadmore();
  49. }
  50. },
  51. onReady() {
  52. this.getNewsList();
  53. this.getBannerInfo("NEWS")
  54. },
  55. methods: {
  56. getBannerInfo(code){
  57. uni.showLoading({
  58. title: "加载中",
  59. mask: true,
  60. })
  61. newsApi.getBannerInfo(code).then((res) => {
  62. this.list =res.data;
  63. }).catch(error => {
  64. uni.showToast({
  65. title: error,icon: "none"
  66. })
  67. })
  68. },
  69. clickBanner(index){
  70. var mod= this.list[index]
  71. if(mod.linkUrl.indexOf('http')==0){
  72. window.location=mod.linkUrl;
  73. }
  74. else if(mod.linkUrl.indexOf('#/')==0){
  75. if(mod.linkUrl.indexOf("?")==-1){
  76. mod.linkUrl+='?';
  77. }
  78. window.location=mod.linkUrl;
  79. }
  80. else if(mod.linkUrl=='#'||mod.linkUrl==''){
  81. }
  82. else{
  83. uni.navigateTo({
  84. url:mod.linkUrl
  85. })
  86. }
  87. },
  88. change(index) {
  89. this.current = index;
  90. this.newsType = this.tabList[index].type;
  91. this.getNewsList(true)
  92. },
  93. getNewsList(bl) {
  94. uni.showLoading({
  95. title: "加载中",
  96. mask: true,
  97. })
  98. if (bl) {
  99. this.newsList = [];
  100. this.pageIndex = 1;
  101. }
  102. newsApi.newsInfoList({
  103. pageIndex: 1,
  104. pageSize: 10,
  105. type: this.newsType
  106. }).then((res) => {
  107. uni.hideLoading()
  108. this.newsList = [
  109. ...this.newsList,
  110. ...res.data.data
  111. ];
  112. this.recordsTotal = res.data.recordsTotal
  113. }).catch(error => {
  114. uni.showToast({
  115. title: error,
  116. icon: "none"
  117. })
  118. })
  119. },
  120. myLoadmore() {
  121. this.pageIndex += 1;
  122. this.getNewsList()
  123. },
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .options{
  129. width: 60%;
  130. height: 44px;
  131. line-height: 44px;
  132. display: flex;
  133. justify-content: space-between;
  134. margin: 0px 16px ;
  135. }
  136. .swiper-box{
  137. width: 343px;
  138. height: 146px;
  139. margin-left: 16px;
  140. }
  141. .news {
  142. background-color: #fff;
  143. margin: 0 16px ;
  144. border-radius: 8px;
  145. .news-content {
  146. display: flex;
  147. justify-content: space-between;
  148. margin-bottom: 24px;
  149. .content-text {
  150. width: 211px;
  151. height: 42px;
  152. line-height: 21px;
  153. color: #101010;
  154. text-align: left;
  155. font-size: 14px
  156. }
  157. ;
  158. .content-img {
  159. width: 100px;
  160. height: 80px;
  161. background-color: #777777;
  162. border-radius: 4px;
  163. overflow: hidden;
  164. img {
  165. width: 100%;
  166. height: 100%;
  167. }
  168. }
  169. .news-time {
  170. margin-top: 12px;
  171. color: #999999;
  172. width: 80px;
  173. height: 20px;
  174. font-size: 14px;
  175. }
  176. }
  177. }
  178. </style>