index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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" :img-mode="'aspectFit'" :name="'picUrl'" 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. import * as Api_common from '@/apis/common.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. ],
  50. }
  51. },
  52. onReachBottom() {
  53. if (this.list.length < this.recordsTotal) {
  54. this.myLoadmore();
  55. }
  56. },
  57. methods: {
  58. getBannerInfo(){
  59. uni.showLoading({
  60. title: "加载中",
  61. mask: true,
  62. })
  63. Api_common.getBannerInfo("TZGG").then((res) => {
  64. this.wrapList =res.data;
  65. }).catch(error => {
  66. uni.showToast({
  67. title: error
  68. })
  69. })
  70. },
  71. getType() {
  72. uni.showLoading({
  73. title: "加载中",
  74. mask: true,
  75. })
  76. this.pageIndex = 1;
  77. API.newsTypeList().then((res) => {
  78. this.tabList = res.data;
  79. if(this.tabList.length){
  80. this.newstype=this.tabList[0]
  81. }
  82. this.getList()
  83. uni.hideLoading()
  84. }).catch(error => {
  85. uni.showToast({
  86. title: error
  87. })
  88. })
  89. },
  90. getList(bl) {
  91. if(this.newstype==""){
  92. return
  93. }
  94. uni.showLoading({
  95. title: "加载中",
  96. mask: true,
  97. })
  98. if (bl) {
  99. this.list = [];
  100. this.pageIndex = 1;
  101. }
  102. var data = {
  103. type:this.newstype.shortName,
  104. pageSize:5,
  105. pageIndex: this.pageIndex
  106. };
  107. API.newscontent(data).then((res) => {
  108. this.list = [
  109. ...this.list,
  110. ...res.data.data
  111. ];
  112. this.recordsTotal = res.data.recordsTotal
  113. uni.hideLoading()
  114. }).catch(error => {
  115. uni.showToast({
  116. title: error
  117. })
  118. })
  119. },
  120. myLoadmore() {
  121. this.pageIndex += 1;
  122. this.getList()
  123. },
  124. change(index) {
  125. this.current = index;
  126. if(this.tabList.length){
  127. this.newstype=this.tabList[index]
  128. }
  129. this.getList(true)
  130. },
  131. onReady() {
  132. this.getBannerInfo()
  133. this.getType()
  134. }
  135. },
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .navbar-tit{
  140. padding-left:15px;
  141. font-size: 24px;
  142. }
  143. .homeTab{
  144. position: fixed;
  145. left: 0;
  146. right: 0;
  147. top: 55px;
  148. background-color: #fff;
  149. z-index: 99;
  150. }
  151. .homeWrap{
  152. padding:0 15px;
  153. margin-top: 40px;
  154. }
  155. .newsList{
  156. padding: 15px;
  157. .newsList-item{
  158. display: flex;
  159. margin-bottom: 24px;
  160. .newsList-text{
  161. flex: 1;
  162. min-width: 0;
  163. margin-right: 10px;
  164. display: flex;
  165. flex-direction: column;
  166. justify-content: space-between;
  167. h4{
  168. font-weight: normal;
  169. }
  170. p{
  171. color: #999;
  172. font-size: 12px;
  173. }
  174. }
  175. }
  176. }
  177. </style>