index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" :border-bottom="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" v-if="wrapList.length">
  10. <u-swiper :list="wrapList" @click="clickBanner" :img-mode="'aspectFit'" :name="'picUrl'" height="294" border-radius="24"></u-swiper>
  11. </view>
  12. <view class="newsList" v-if="list.length">
  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-text="item.title">
  18. </h4>
  19. <p>{{item.createTime}}</p>
  20. </view>
  21. <u-image class="newsList-img" :src="item.images?item.images:'/static/img/default_img.png'" 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 class="jpDefault" v-else>
  26. <u-image width="179px" height="126px" src="/static/img/default1.png"></u-image>
  27. <p>暂无资讯内容</p>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as API from '@/apis/news.js'
  33. import * as Api_common from '@/apis/common.js'
  34. export default {
  35. data() {
  36. return {
  37. form:{
  38. },
  39. newstype:'',
  40. typelist: [],
  41. pageIndex: 1,
  42. recordsTotal: 0,
  43. list: [],
  44. tabList: [{
  45. name: '通知公告'
  46. }, {
  47. name: '活动报道'
  48. },{
  49. name: '婚恋课堂'
  50. },{
  51. name: '问题解答'
  52. }],
  53. current: 0,
  54. wrapList: [
  55. ],
  56. }
  57. },
  58. onReachBottom() {
  59. if (this.list.length < this.recordsTotal) {
  60. this.myLoadmore();
  61. }
  62. },
  63. methods: {
  64. getBannerInfo(code){
  65. uni.showLoading({
  66. title: "加载中",
  67. mask: true,
  68. })
  69. Api_common.getBannerInfo(code).then((res) => {
  70. this.wrapList =res.data;
  71. }).catch(error => {
  72. uni.showToast({
  73. title: error,icon: "none"
  74. })
  75. })
  76. },
  77. clickBanner(index){
  78. var obj= this.wrapList[index]
  79. uni.navigateTo({
  80. url:obj.linkUrl
  81. })
  82. },
  83. getType() {
  84. uni.showLoading({
  85. title: "加载中",
  86. mask: true,
  87. })
  88. this.pageIndex = 1;
  89. API.newsTypeList().then((res) => {
  90. this.tabList = res.data;
  91. if(this.tabList.length){
  92. this.newstype=this.tabList[0]
  93. }
  94. this.getList()
  95. this.getBannerInfo(this.newstype.shortName)
  96. uni.hideLoading()
  97. }).catch(error => {
  98. uni.showToast({
  99. title: error,icon: "none"
  100. })
  101. })
  102. },
  103. getList(bl) {
  104. if(this.newstype==""){
  105. return
  106. }
  107. uni.showLoading({
  108. title: "加载中",
  109. mask: true,
  110. })
  111. if (bl) {
  112. this.list = [];
  113. this.pageIndex = 1;
  114. }
  115. var data = {
  116. type:this.newstype.shortName,
  117. pageSize:5,
  118. pageIndex: this.pageIndex
  119. };
  120. API.newscontent(data).then((res) => {
  121. this.list = [
  122. ...this.list,
  123. ...res.data.data
  124. ];
  125. this.recordsTotal = res.data.recordsTotal
  126. uni.hideLoading()
  127. }).catch(error => {
  128. uni.showToast({
  129. title: error,icon: "none"
  130. })
  131. })
  132. },
  133. myLoadmore() {
  134. this.pageIndex += 1;
  135. this.getList()
  136. },
  137. change(index) {
  138. this.current = index;
  139. if(this.tabList.length){
  140. this.newstype=this.tabList[index]
  141. }
  142. this.getList(true)
  143. this.getBannerInfo(this.newstype.shortName)
  144. },
  145. onReady() {
  146. this.getType()
  147. //this.getBannerInfo()
  148. }
  149. },
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .jpDefault{
  154. padding-top:90px;
  155. display: flex;
  156. flex-direction: column;
  157. align-items: center;
  158. p{
  159. color: #A69F9F;
  160. font-size: 16px;
  161. margin-top: 12px;
  162. }
  163. }
  164. .navbar-tit{
  165. padding-left:15px;
  166. font-size: 24px;
  167. }
  168. .home-head{
  169. display: flex;
  170. justify-content: space-between;
  171. align-items: center;
  172. padding-right: 15px;
  173. background-color: #fff;
  174. z-index: 99;
  175. .homeAdd{
  176. color: #FF5E5E;
  177. span{
  178. margin-left: 3px;
  179. }
  180. }
  181. }
  182. .homeWrap{
  183. padding:0 15px;
  184. }
  185. .newsList{
  186. padding: 15px;
  187. .newsList-item{
  188. display: flex;
  189. margin-bottom: 24px;
  190. .newsList-text{
  191. flex: 1;
  192. min-width: 0;
  193. margin-right: 10px;
  194. display: flex;
  195. flex-direction: column;
  196. justify-content: space-between;
  197. h4{
  198. font-weight: normal;
  199. }
  200. p{
  201. color: #999;
  202. font-size: 12px;
  203. }
  204. }
  205. }
  206. }
  207. </style>