index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false"><view class="navbar-tit">资讯</view></u-navbar>
  4. <view class="homeTab">
  5. <u-tabs :list="tabList" :current="current" @change="change" :show-bar="false" active-color="#333" inactive-color="#c4c0c0"></u-tabs>
  6. </view>
  7. <view class="homeWrap">
  8. <u-swiper :list="wrapList" height="300" border-radius="24"></u-swiper>
  9. </view>
  10. <view class="newsList">
  11. <view class="newsList-item"
  12. @click="gotoUrl('pages/news/detalis?id='+item.id)"
  13. v-for="(item ,index) in list" :key="item.id" >
  14. <view class="newsList-text">
  15. <h4 class="u-line-2" v-html="item.content">
  16. </h4>
  17. <p>{{item.createTime}}</p>
  18. </view>
  19. <u-image class="newsList-img" :src="item.images" height="150" width="200" border-radius="10"></u-image>
  20. </view>
  21. <u-divider color="#B6BDC3" v-if="list.length ==recordsTotal" style="margin-top:20px;">已经到底了</u-divider>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import * as API from '@/apis/news.js'
  27. export default {
  28. data() {
  29. return {
  30. form:{
  31. },
  32. newstype:'',
  33. typelist: [],
  34. pageIndex: 1,
  35. recordsTotal: 0,
  36. list: [],
  37. tabList: [{
  38. name: '通知公告'
  39. }, {
  40. name: '活动报道'
  41. },{
  42. name: '婚恋课堂'
  43. },{
  44. name: '问题解答'
  45. }],
  46. current: 0,
  47. wrapList: [{
  48. image: '/static/img/banner.png',
  49. },
  50. {
  51. image: '/static/img/banner.png',
  52. },
  53. {
  54. image: '/static/img/banner.png',
  55. }
  56. ],
  57. }
  58. },
  59. onReachBottom() {
  60. if (this.list.length < this.recordsTotal) {
  61. this.myLoadmore();
  62. }
  63. },
  64. methods: {
  65. getType() {
  66. uni.showLoading({
  67. title: "加载中",
  68. mask: true,
  69. })
  70. this.pageIndex = 1;
  71. API.newsTypeList().then((res) => {
  72. this.tabList = res.data;
  73. if(this.tabList.length){
  74. this.newstype=this.tabList[0]
  75. }
  76. this.getList()
  77. uni.hideLoading()
  78. }).catch(error => {
  79. uni.showToast({
  80. title: error
  81. })
  82. })
  83. },
  84. getList(bl) {
  85. if(this.newstype==""){
  86. return
  87. }
  88. uni.showLoading({
  89. title: "加载中",
  90. mask: true,
  91. })
  92. if (bl) {
  93. this.list = [];
  94. this.pageIndex = 1;
  95. }
  96. var data = {
  97. type:this.newstype.shortName,
  98. pageSize:5,
  99. pageIndex: this.pageIndex
  100. };
  101. API.newscontent(data).then((res) => {
  102. this.list = [
  103. ...this.list,
  104. ...res.data.data
  105. ];
  106. this.recordsTotal = res.data.recordsTotal
  107. uni.hideLoading()
  108. }).catch(error => {
  109. uni.showToast({
  110. title: error
  111. })
  112. })
  113. },
  114. myLoadmore() {
  115. this.pageIndex += 1;
  116. this.getList()
  117. },
  118. change(index) {
  119. this.current = index;
  120. if(this.tabList.length){
  121. this.newstype=this.tabList[index]
  122. }
  123. this.getList(true)
  124. },
  125. onReady() {
  126. this.getType()
  127. }
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .navbar-tit{
  133. padding-left:15px;
  134. font-size: 24px;
  135. }
  136. .homeTab{
  137. position: fixed;
  138. left: 0;
  139. right: 0;
  140. top: 55px;
  141. background-color: #fff;
  142. z-index: 99;
  143. }
  144. .homeWrap{
  145. padding:0 15px;
  146. margin-top: 40px;
  147. }
  148. .newsList{
  149. padding: 15px;
  150. .newsList-item{
  151. display: flex;
  152. margin-bottom: 24px;
  153. .newsList-text{
  154. flex: 1;
  155. min-width: 0;
  156. margin-right: 10px;
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: space-between;
  160. h4{
  161. font-weight: normal;
  162. }
  163. p{
  164. color: #999;
  165. font-size: 12px;
  166. }
  167. }
  168. }
  169. }
  170. </style>