index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="news-index">
  3. <nav-bar title="新闻" @init="onInitNavbar"></nav-bar>
  4. <u-scroll-view :tabbar-conflict="false" @scroll-near-lower="onScrollToLower">
  5. <view class="main-container">
  6. <u-tabs :active.sync="tabActive" :tabs="tabs" tab-style="default" @change="tabChange"/>
  7. <van-empty v-if="newsList.length === 0" description="暂无数据" />
  8. <view v-else class="news-list">
  9. <template v-for="(item, index) in newsList">
  10. <news-item :item="item" :key="index" :type="tabActive" />
  11. </template>
  12. </view>
  13. <disclaimer-text></disclaimer-text>
  14. </view>
  15. </u-scroll-view>
  16. </view>
  17. </template>
  18. <script>
  19. import NavBar from '@/components/layout/nav-bar'
  20. import UTabs from '@/components/common/u-tabs'
  21. import UScrollView from '@/components/common/u-scroll-view'
  22. import NewsItem from '@/pages/news/components/news-item.vue'
  23. import { exhibitorsNewsList, newsList } from '@/api/exhibitor'
  24. import DisclaimerText from '@/components/disclaimer-text/index.vue'
  25. export default {
  26. options: {
  27. styleIsolation: 'shared'
  28. },
  29. components: {
  30. NavBar,
  31. UTabs,
  32. UScrollView,
  33. NewsItem,
  34. DisclaimerText
  35. },
  36. data() {
  37. return {
  38. tabActive: 'exhibition',
  39. tabs: [{
  40. label: '展会新闻',
  41. value: 'exhibition'
  42. }, {
  43. label: '展商新闻',
  44. value: 'exhibitor'
  45. }],
  46. newsList: [],
  47. newsParams: {
  48. page: 1,
  49. page_size: 10,
  50. keyword: '',
  51. },
  52. newsListLoading: false,
  53. newsListLastPage: 1,
  54. }
  55. },
  56. onLoad(options) {
  57. if (options.type) {
  58. this.tabActive = options.type
  59. }
  60. },
  61. created() {
  62. },
  63. methods: {
  64. getList() {
  65. if (this.tabActive === 'exhibitor') {
  66. this.getExhibitorsNewsList()
  67. }
  68. if (this.tabActive === 'exhibition') {
  69. this.getNewsList()
  70. }
  71. },
  72. getNewsList() {
  73. this.newsListLoading = true
  74. newsList(this.newsParams).then(res => {
  75. if (res.data.data) {
  76. if (this.newsParams.page > 1) {
  77. this.newsList = [...this.newsList, ...res.data.data]
  78. } else {
  79. this.newsList = res.data.data
  80. this.newsListLastPage = res.data.last_page
  81. }
  82. } else {
  83. this.showToast('系统繁忙,稍候再试')
  84. }
  85. this.newsListLoading = false
  86. })
  87. },
  88. getExhibitorsNewsList() {
  89. this.newsListLoading = true
  90. exhibitorsNewsList(this.newsParams).then(res => {
  91. if (res.data.data) {
  92. if (this.newsParams.page > 1) {
  93. this.newsList = [...this.newsList, ...res.data.data]
  94. } else {
  95. this.newsList = res.data.data
  96. this.newsListLastPage = res.data.last_page
  97. }
  98. } else {
  99. this.showToast('系统繁忙,稍候再试')
  100. }
  101. this.newsListLoading = false
  102. })
  103. },
  104. onScrollToLower(e) {
  105. if (this.newsListLastPage === this.newsParams.page) {
  106. return
  107. }
  108. if (this.newsListLoading === true) {
  109. return
  110. }
  111. this.newsListLoading = true
  112. this.newsParams.page = this.newsParams.page+1
  113. this.getList()
  114. },
  115. tabChange(e) {
  116. this.tabActive = e.detail.value
  117. this.newsParams.page = 1
  118. this.getList()
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. .news-list{
  125. display: grid;
  126. grid-template-columns: 1fr;
  127. grid-row-gap: 18rpx;
  128. margin-top: 28rpx;
  129. }
  130. </style>