category.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="category">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <template v-else-if="categories.length > 0">
  5. <!-- 侧边导航 -->
  6. <scroll-view class="slide-navbar" :scroll-y="true">
  7. <template v-for="(item, index) in categories">
  8. <view
  9. class="slide"
  10. :class="{ active: index === current }"
  11. :key="item.id"
  12. v-text="item.name"
  13. @click="onClick(item, index)"
  14. ></view>
  15. </template>
  16. </scroll-view>
  17. <!-- 右侧容器 -->
  18. <scroll-view
  19. class="panel"
  20. :scroll-y="true"
  21. :scroll-with-animation="true"
  22. :scroll-top="scrollTop"
  23. @scroll="onScroll"
  24. >
  25. <view class="cate" v-for="(item, index) in smallTypeList" :key="index" @click="toGoodsFloor(item)">
  26. <image class="cate-icon" :src="item.crmIcon"></image>
  27. <view class="cate-name" v-text="item.name"></view>
  28. </view>
  29. </scroll-view>
  30. </template>
  31. <template v-else>
  32. <tui-no-data :imgUrl="staticUrl + 'icon-empty-address.png'" :imgHeight="230" :imgWidth="290">
  33. <view class="empty-tip">暂无分类信息~</view>
  34. </tui-no-data>
  35. </template>
  36. </view>
  37. </template>
  38. <script>
  39. import { fetchProductTypeFirst, fetchProductTypeSecond } from '@/services/api/goods.js'
  40. export default {
  41. data() {
  42. return {
  43. isRequest: true,
  44. categories: [],
  45. current: 0,
  46. oldScrollTop: 0,
  47. scrollTop: 100
  48. }
  49. },
  50. computed: {
  51. smallTypeList() {
  52. const current = this.categories[this.current]
  53. return (current && current.smallTypeList) || []
  54. }
  55. },
  56. onShow() {
  57. this.fetchProductTypeFirst()
  58. },
  59. methods: {
  60. onClick(item, index) {
  61. this.current = index
  62. this.scrollTop = this.oldScrollTop
  63. this.$nextTick(() => {
  64. this.scrollTop = 0
  65. })
  66. },
  67. onScroll(e) {
  68. this.oldScrollTop = e.detail.scrollTop
  69. },
  70. // 获取一级商品分了列表
  71. async fetchProductTypeFirst() {
  72. try {
  73. const { data } = await fetchProductTypeFirst()
  74. this.categories = data
  75. this.isRequest = false
  76. } catch (e) {
  77. console.log(e)
  78. }
  79. },
  80. // 商品楼层
  81. toGoodsFloor(item) {
  82. this.$setStorage('NAVBAR', {
  83. type: 'second',
  84. id: item.smallTypeId,
  85. title: item.name
  86. })
  87. this.$router.navigateTo('goods/goods-list')
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .category {
  94. @extend .cm-flex-between;
  95. align-items: flex-start;
  96. background-color: #fff;
  97. .slide-navbar {
  98. width: 200rpx;
  99. height: 100vh;
  100. background-color: #f7f7f7;
  101. box-sizing: border-box;
  102. .slide {
  103. width: 100%;
  104. height: 94rpx;
  105. text-align: center;
  106. line-height: 94rpx;
  107. font-size: 28rpx;
  108. color: #666666;
  109. background-color: #f7f7f7;
  110. &.active {
  111. background-color: #fff;
  112. color: #ff457b;
  113. }
  114. }
  115. }
  116. .panel {
  117. width: 550rpx;
  118. height: 100vh;
  119. padding-bottom: 40rpx;
  120. background-color: #fff;
  121. box-sizing: border-box;
  122. &::after {
  123. content: '';
  124. display: block;
  125. clear: both;
  126. }
  127. .cate {
  128. float: left;
  129. margin-top: 40rpx;
  130. margin-left: 40rpx;
  131. @extend .cm-flex-center;
  132. flex-direction: column;
  133. .cate-icon {
  134. display: block;
  135. width: 128rpx;
  136. height: 128rpx;
  137. }
  138. .cate-name {
  139. @include ellipsis(1);
  140. width: 100%;
  141. margin-top: 16rpx;
  142. color: #666;
  143. font-size: 26rpx;
  144. text-align: center;
  145. }
  146. }
  147. }
  148. }
  149. </style>