index.vue 3.6 KB

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