news-recommend.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 } 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. watch: {
  31. exhibitorId(val) {
  32. this.newsListParams.exhibitors_id = val
  33. this.getNewsList()
  34. }
  35. },
  36. data() {
  37. return {
  38. newsType: 'exhibition',
  39. tabs: [{
  40. label: '展会新闻',
  41. value: 'exhibition'
  42. }, {
  43. label: '展商新闻',
  44. value: 'exhibitor'
  45. }],
  46. newsList: [],
  47. newsListParams: {
  48. page: 1,
  49. page_size: 3,
  50. exhibitors_id: 0
  51. },
  52. newsListLoading: false
  53. }
  54. },
  55. created() {
  56. if (this.recommendType === 'detail') {
  57. this.newsType = 'exhibitor'
  58. }
  59. },
  60. methods: {
  61. getNewsList() {
  62. if (this.newsListLoading === true) {
  63. return
  64. }
  65. this.newsListLoading = true
  66. exhibitorsNewsList(this.newsListParams).then(res => {
  67. if (res.code === 0) {
  68. if (this.newsListParams.page > 1) {
  69. this.newsList = [...this.newsList, ...res.data.data]
  70. } else {
  71. this.newsList = res.data.data
  72. }
  73. }
  74. this.newsListLoading = false
  75. })
  76. },
  77. tabChange() {
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .news-list{
  84. display: grid;
  85. grid-template-columns: 1fr;
  86. grid-row-gap: 18rpx;
  87. margin-top: 28rpx;
  88. }
  89. </style>