recommendCategory.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="category-box box">
  3. <swiper
  4. :indicator-dots="false"
  5. :current="current"
  6. @change="onSwiperChange"
  7. class="swiper"
  8. >
  9. <swiper-item v-for="(page, pageIndex) in pageList" :key="pageIndex">
  10. <view class="category-list">
  11. <view class="category-item" v-for="(item, index) in page" :key="index" @click="handleClick(item)">
  12. <image :src="item.dictImage" mode="aspectFill"></image>
  13. <view>{{ item.dictLabel || '' }}</view>
  14. </view>
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. <view v-if="list.length > perPage" class="indicator">
  19. <view
  20. class="indicator-bar"
  21. :class="{ active: pageIndex === current }"
  22. v-for="(page, pageIndex) in pageList"
  23. :key="pageIndex"
  24. ></view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'recommendCategory',
  31. props: {
  32. list: {
  33. type: Array,
  34. default: () => []
  35. }
  36. },
  37. data() {
  38. return {
  39. current: 0
  40. }
  41. },
  42. computed: {
  43. perPage() {
  44. return 8
  45. },
  46. pageList() {
  47. const pages = []
  48. for (let i = 0; i < this.list.length; i += this.perPage) {
  49. pages.push(this.list.slice(i, i + this.perPage))
  50. }
  51. return pages
  52. }
  53. },
  54. methods: {
  55. onSwiperChange(e) {
  56. this.current = e.detail.current
  57. },
  58. handleClick(item) {
  59. if (item.dictValue) {
  60. uni.navigateTo({
  61. url: '/pages_shopping/home/productList?tuiCateId=' + item.dictValue + '&title=' + encodeURIComponent(item.dictLabel || '')
  62. })
  63. } else if (item.page) {
  64. uni.navigateTo({
  65. url: item.page
  66. })
  67. }
  68. this.$emit('click', item)
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .box {
  75. background: #FFFFFF;
  76. border-radius: 16rpx;
  77. margin: 24rpx;
  78. box-sizing: border-box;
  79. padding: 26rpx 0 6rpx 0;
  80. }
  81. .swiper {
  82. height: 364rpx;
  83. }
  84. .category-list {
  85. display: flex;
  86. align-items: center;
  87. justify-content: flex-start;
  88. flex-wrap: wrap;
  89. }
  90. .category-item {
  91. width: 25%;
  92. font-family: PingFang SC, PingFang SC;
  93. font-weight: 400;
  94. font-size: 24rpx;
  95. color: #222222;
  96. display: flex;
  97. flex-direction: column;
  98. align-items: center;
  99. margin-bottom: 20rpx;
  100. image {
  101. width: 104rpx;
  102. height: 104rpx;
  103. margin-bottom: 26rpx;
  104. border-radius: 16rpx;
  105. }
  106. }
  107. .indicator {
  108. display: flex;
  109. justify-content: center;
  110. align-items: center;
  111. margin-top: 6rpx;
  112. .indicator-bar {
  113. width: 40rpx;
  114. height: 4rpx;
  115. border-radius: 2rpx;
  116. background: rgba(37, 131, 235, 0.3);
  117. margin: 0 6rpx;
  118. transition: background 0.3s;
  119. &.active {
  120. background: #2583EB;
  121. }
  122. }
  123. }
  124. </style>