news-recommend.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="news-recommend">
  3. <view v-if="recommendType === 'home'" class="news-tab">
  4. <u-tabs :active.sync="newsType" :tabs="tabs" tab-style="default" @change="tabChange"/>
  5. </view>
  6. <view class="news-list" v-if="newsList && newsList.length > 0">
  7. <template v-for="(item, index) in newsList">
  8. <news-item :item="item" :key="index" :type="newsType" />
  9. </template>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import UTabs from '@/components/common/u-tabs'
  15. import NewsItem from '@/pages/news/components/news-item.vue'
  16. import { exhibitorsNewsList, newsList } from '@/api/exhibitor'
  17. export default {
  18. components: {
  19. UTabs,
  20. NewsItem
  21. },
  22. props: {
  23. // 特定的展商ID
  24. exhibitorId: Number,
  25. recommendType: {
  26. type: String,
  27. default: 'home'
  28. }
  29. },
  30. data() {
  31. return {
  32. newsType: 'exhibition',
  33. tabs: [{
  34. label: '展会新闻',
  35. value: 'exhibition'
  36. }, {
  37. label: '展商新闻',
  38. value: 'exhibitor'
  39. }],
  40. newsList: [],
  41. newsListParams: {
  42. page: 1,
  43. page_size: 3,
  44. keyword: ''
  45. },
  46. tabActive: 'exhibition',
  47. newsListLoading: false
  48. }
  49. },
  50. created() {
  51. if (this.recommendType === 'detail') {
  52. this.newsType = 'exhibitor'
  53. this.tabActive = 'exhibitor'
  54. }
  55. },
  56. mounted() {
  57. this.getList()
  58. },
  59. methods: {
  60. getList() {
  61. if (this.tabActive === 'exhibitor') {
  62. this.getExhibitorsNewsList()
  63. }
  64. if (this.tabActive === 'exhibition') {
  65. this.getNewsList()
  66. }
  67. },
  68. getNewsList() {
  69. this.newsListLoading = true
  70. newsList(this.newsListParams).then(res => {
  71. if (res.data.data) {
  72. if (this.newsListParams.page > 1) {
  73. this.newsList = [...this.newsList, ...res.data.data]
  74. } else {
  75. this.newsList = res.data.data
  76. this.newsListLastPage = res.data.last_page
  77. }
  78. } else {
  79. this.showToast('系统繁忙,稍候再试')
  80. }
  81. this.newsListLoading = false
  82. })
  83. },
  84. getExhibitorsNewsList() {
  85. this.newsListLoading = true
  86. if (this.exhibitorId) {
  87. this.newsListParams.exhibitors_id = this.exhibitorId
  88. } else {
  89. this.newsListParams.exhibitors_id = 0
  90. }
  91. exhibitorsNewsList(this.newsListParams).then(res => {
  92. if (res.data.data) {
  93. if (this.newsListParams.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. tabChange(e) {
  106. this.tabActive = e.detail.value
  107. this.newsListParams.page = 1
  108. this.getList()
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. .news-list{
  115. display: grid;
  116. grid-template-columns: 1fr;
  117. grid-row-gap: 18rpx;
  118. margin-top: 28rpx;
  119. }
  120. </style>