secondary.vue 4.1 KB

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