secondary.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <!-- 一级分类 -->
  4. <scroll-view class="cate-left" :scroll-y="true" @touchmove.stop.prevent>
  5. <text class="type-nav" :class="{ selected: curIndex == index }" v-for="(item, index) in list" :key="index"
  6. @click="handleSelectNav(index)">{{ item.name }}</text>
  7. </scroll-view>
  8. <view class="cate-content">
  9. <!-- 二级分类列表 -->
  10. <view class="category-list clearfix">
  11. <view class="category-item" v-for="(item, index) in list[curIndex].children" :key="index" @click="handleGoods(item.category_id)">
  12. <view v-if="item.image" class="item-image">
  13. <image class="image" mode="scaleToFill" :src="item.image.preview_url"></image>
  14. </view>
  15. <view class="item-name">
  16. <text class="oneline-hide">{{ item.name }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import * as GoodsApi from '@/api/goods'
  25. export default {
  26. props: {
  27. // 分类列表
  28. list: {
  29. type: Array,
  30. default: []
  31. }
  32. },
  33. data() {
  34. return {
  35. // 一级分类:指针
  36. curIndex: 0
  37. }
  38. },
  39. methods: {
  40. // 一级分类:选中分类
  41. handleSelectNav(index) {
  42. this.curIndex = index
  43. },
  44. // 跳转至商品列表页
  45. handleGoods(categoryId) {
  46. this.$navTo('pages/goods/list', { categoryId })
  47. }
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .container {
  53. padding-left: 175rpx;
  54. }
  55. // 分类内容
  56. .cate-content {
  57. z-index: 1;
  58. background: #fff;
  59. padding-top: 90rpx;
  60. min-height: 300rpx;
  61. }
  62. // 一级分类+二级分类 20
  63. .cate-left {
  64. position: fixed;
  65. top: calc(88rpx + var(--window-top));
  66. left: var(--window-left);
  67. bottom: var(--window-bottom);
  68. width: 175rpx;
  69. height: calc(100% - var(--window-top) - var(--window-bottom) - 90rpx) !important;
  70. background: #f8f8f8;
  71. color: #444;
  72. }
  73. // 左侧一级分类
  74. .type-nav {
  75. position: relative;
  76. height: 90rpx;
  77. z-index: 10;
  78. display: block;
  79. font-size: 26rpx;
  80. display: flex;
  81. justify-content: center;
  82. align-items: center;
  83. &.selected {
  84. background: #fff;
  85. border-right: none;
  86. font-size: 28rpx;
  87. color: $main-bg
  88. }
  89. }
  90. // 分类列表
  91. .category-list {
  92. padding: 30rpx 20rpx;
  93. }
  94. .category-item {
  95. float: left;
  96. width: 33.33333%;
  97. display: flex;
  98. flex-direction: column;
  99. align-items: center;
  100. margin-bottom: 40rpx;
  101. .item-image {
  102. .image {
  103. display: block;
  104. width: 146rpx;
  105. height: 146rpx;
  106. }
  107. }
  108. .item-name {
  109. margin-top: 10rpx;
  110. text-align: center;
  111. font-size: 26rpx;
  112. }
  113. }
  114. </style>