index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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" />
  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. this.getList()
  61. },
  62. created() {
  63. },
  64. methods: {
  65. getList() {
  66. if (this.tabActive === 'exhibitor') {
  67. this.getExhibitorsNewsList()
  68. }
  69. if (this.tabActive === 'exhibition') {
  70. this.getNewsList()
  71. }
  72. },
  73. getNewsList() {
  74. this.newsListLoading = true
  75. newsList(this.newsParams).then(res => {
  76. if (res.data.data) {
  77. if (this.newsParams.page > 1) {
  78. this.newsList = [...this.newsList, ...res.data.data]
  79. } else {
  80. this.newsList = res.data.data
  81. this.newsListLastPage = res.data.last_page
  82. }
  83. } else {
  84. this.showToast('系统繁忙,稍候再试')
  85. }
  86. this.newsListLoading = false
  87. })
  88. },
  89. getExhibitorsNewsList() {
  90. this.newsListLoading = true
  91. exhibitorsNewsList(this.newsParams).then(res => {
  92. if (res.data.data) {
  93. if (this.newsParams.page > 1) {
  94. this.newsList = [...this.newsList, ...res.data.data]
  95. } else {
  96. this.newsList = res.data.data
  97. this.newsListLastPage = res.data.last_page
  98. }
  99. } else {
  100. this.showToast('系统繁忙,稍候再试')
  101. }
  102. this.newsListLoading = false
  103. })
  104. },
  105. onScrollToLower(e) {
  106. if (this.newsListLastPage === this.newsParams.page) {
  107. return
  108. }
  109. if (this.newsListLoading === true) {
  110. return
  111. }
  112. this.newsListLoading = true
  113. this.newsParams.page = this.newsParams.page+1
  114. this.getList()
  115. },
  116. tabChange(e) {
  117. this.tabActive = e.detail.value
  118. this.newsParams.page = 1
  119. this.getList()
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss">
  125. .news-list{
  126. display: grid;
  127. grid-template-columns: 1fr;
  128. grid-row-gap: 18rpx;
  129. margin-top: 28rpx;
  130. }
  131. </style>