news-recommend.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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">
  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. mounted() {
  31. this.getNewsList()
  32. },
  33. data() {
  34. return {
  35. newsType: 'exhibition',
  36. tabs: [{
  37. label: '展会新闻',
  38. value: 'exhibition'
  39. }, {
  40. label: '展商新闻',
  41. value: 'exhibitor'
  42. }],
  43. newsList: [],
  44. newsListParams: {
  45. page: 1,
  46. page_size: 3,
  47. keyword: ''
  48. },
  49. newsListLoading: false
  50. }
  51. },
  52. created() {
  53. if (this.recommendType === 'detail') {
  54. this.newsType = 'exhibitor'
  55. }
  56. },
  57. methods: {
  58. getList() {
  59. if (this.tabActive === 'exhibitor') {
  60. this.getExhibitorsNewsList()
  61. }
  62. if (this.tabActive === 'exhibition') {
  63. this.getNewsList()
  64. }
  65. },
  66. getNewsList() {
  67. this.newsListLoading = true
  68. newsList(this.newsListParams).then(res => {
  69. if (res.data.data) {
  70. if (this.newsListParams.page > 1) {
  71. this.newsList = [...this.newsList, ...res.data.data]
  72. } else {
  73. this.newsList = res.data.data
  74. this.newsListLastPage = res.data.last_page
  75. }
  76. } else {
  77. this.showToast('系统繁忙,稍候再试')
  78. }
  79. this.newsListLoading = false
  80. })
  81. },
  82. getExhibitorsNewsList() {
  83. this.newsListLoading = true
  84. exhibitorsNewsList(this.newsListParams).then(res => {
  85. if (res.data.data) {
  86. if (this.newsListParams.page > 1) {
  87. this.newsList = [...this.newsList, ...res.data.data]
  88. } else {
  89. this.newsList = res.data.data
  90. this.newsListLastPage = res.data.last_page
  91. }
  92. } else {
  93. this.showToast('系统繁忙,稍候再试')
  94. }
  95. this.newsListLoading = false
  96. })
  97. },
  98. tabChange(e) {
  99. this.tabActive = e.detail.value
  100. this.newsListParams.page = 1
  101. this.getList()
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .news-list{
  108. display: grid;
  109. grid-template-columns: 1fr;
  110. grid-row-gap: 18rpx;
  111. margin-top: 28rpx;
  112. }
  113. </style>