index.vue 3.4 KB

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