index.vue 3.0 KB

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