secondary.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view v-if="list.length > 0" class="secondary">
  3. <!-- 二级分类 20 -->
  4. <view class="cate-content">
  5. <!-- 左侧 一级分类 -->
  6. <scroll-view class="cate-left" :scroll-y="true" :style="{ height: `${scrollHeight}px` }">
  7. <text class="type-nav" :class="{ selected: curIndex == index }" v-for="(item, index) in list" :key="index"
  8. @click="handleSelectNav(index)">{{ item.name }}</text>
  9. </scroll-view>
  10. <!-- 右侧 二级分类 -->
  11. <scroll-view class="cate-right" :scroll-top="scrollTop" :scroll-y="true" :style="{ height: `${scrollHeight}px` }">
  12. <view v-if="list[curIndex]" class="cate-right-cont">
  13. <view class="cate-two-box">
  14. <view class="cate-cont-box">
  15. <view class="flex-three" v-for="(item, idx) in list[curIndex].children" :key="idx" @click="onTargetGoodsList(item.category_id)">
  16. <view class="cate-img-padding">
  17. <view v-if="item.image" class="cate-img">
  18. <image class="image" mode="scaleToFill" :src="item.image.preview_url"></image>
  19. </view>
  20. </view>
  21. <text class="name oneline-hide">{{ item.name }}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. <empty v-if="!list.length" />
  29. </view>
  30. </template>
  31. <script>
  32. import { PageCategoryStyleEnum } from '@/common/enum/store/page/category'
  33. import Empty from '@/components/empty'
  34. import { rpx2px } from '@/utils/util'
  35. export default {
  36. components: {
  37. Empty
  38. },
  39. props: {
  40. // 分类列表
  41. list: {
  42. type: Array,
  43. default: []
  44. },
  45. },
  46. data() {
  47. return {
  48. // 枚举类
  49. PageCategoryStyleEnum,
  50. // 列表高度
  51. scrollHeight: 0,
  52. // 一级分类:指针
  53. curIndex: 0,
  54. // 内容区竖向滚动条位置
  55. scrollTop: 0,
  56. }
  57. },
  58. created() {
  59. // 设置分类列表高度
  60. this.setListHeight()
  61. },
  62. methods: {
  63. // 设置列表内容的高度
  64. setListHeight() {
  65. const { windowHeight } = uni.getSystemInfoSync()
  66. this.scrollHeight = windowHeight - rpx2px(96)
  67. },
  68. // 一级分类:选中分类
  69. handleSelectNav(index) {
  70. this.curIndex = index
  71. this.scrollTop = 0
  72. },
  73. // 跳转至商品列表页
  74. onTargetGoodsList(categoryId) {
  75. this.$navTo('pages/goods/list', { categoryId })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. // 分类内容
  82. .cate-content {
  83. display: flex;
  84. z-index: 1;
  85. background: #fff;
  86. padding-top: 96rpx;
  87. }
  88. // 一级分类+二级分类 20
  89. .cate-left {
  90. height: 100%;
  91. display: flex;
  92. flex-direction: column;
  93. flex: 0 0 23%;
  94. background: #f8f8f8;
  95. color: #444;
  96. }
  97. .cate-right {
  98. display: flex;
  99. flex-direction: column;
  100. height: 100%;
  101. overflow: hidden;
  102. .cate-right-cont {
  103. width: 100%;
  104. display: flex;
  105. flex-flow: row wrap;
  106. align-content: flex-start;
  107. padding-top: 15rpx;
  108. .cate-two-box {
  109. width: 100%;
  110. padding: 0 10px;
  111. }
  112. }
  113. }
  114. // 左侧一级分类
  115. .type-nav {
  116. position: relative;
  117. height: 90rpx;
  118. z-index: 10;
  119. display: block;
  120. font-size: 26rpx;
  121. display: flex;
  122. justify-content: center;
  123. align-items: center;
  124. &.selected {
  125. background: #fff;
  126. color: #fa2209;
  127. border-right: none;
  128. font-size: 28rpx;
  129. }
  130. }
  131. // 右侧二级分类
  132. .cate-cont-box {
  133. margin-bottom: 30rpx;
  134. padding-bottom: 10rpx;
  135. background: #fff;
  136. overflow: hidden;
  137. .name {
  138. display: block;
  139. padding-bottom: 30rpx;
  140. text-align: center;
  141. font-size: 26rpx;
  142. color: #444444;
  143. }
  144. .cate-img-padding {
  145. padding: 16rpx 16rpx 4rpx 16rpx;
  146. }
  147. .cate-img {
  148. position: relative;
  149. width: 100%;
  150. padding-top: 100%;
  151. .image {
  152. width: 100%;
  153. height: 100%;
  154. position: absolute;
  155. top: 0;
  156. left: 0;
  157. border-radius: 10rpx;
  158. }
  159. }
  160. }
  161. </style>