category.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="category">
  3. <!-- 侧边导航 -->
  4. <scroll-view class="slide-navbar" :scroll-y="true">
  5. <template v-for="(item, index) in navbar">
  6. <view
  7. class="slide"
  8. :class="{ active: index === current }"
  9. :key="item.id"
  10. v-text="item.name"
  11. @click="onClick(item, index)"
  12. ></view>
  13. </template>
  14. </scroll-view>
  15. <!-- 右侧容器 -->
  16. <scroll-view
  17. class="panel"
  18. :scroll-y="true"
  19. :scroll-with-animation="true"
  20. :scroll-top="scrollTop"
  21. @scroll="onScroll"
  22. >
  23. <view class="cate" v-for="cate in categories" :key="cate.id">
  24. <image class="cate-icon" :src="cate.image"></image>
  25. <view class="cate-name" v-text="cate.name"></view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </template>
  30. <script>
  31. import { fetchProductTypeFirst, fetchProductTypeSecond } from '@/services/api/goods.js'
  32. export default {
  33. data() {
  34. return {
  35. categories: [
  36. {
  37. id: 1,
  38. name: '防晒霜',
  39. image: 'https://picsum.photos/200/200?random=1'
  40. },
  41. {
  42. id: 2,
  43. name: '防晒霜',
  44. image: 'https://picsum.photos/200/200?random=2'
  45. },
  46. {
  47. id: 3,
  48. name: '防晒霜',
  49. image: 'https://picsum.photos/200/200?random=3'
  50. },
  51. {
  52. id: 4,
  53. name: '防晒霜',
  54. image: 'https://picsum.photos/200/200?random=4'
  55. },
  56. {
  57. id: 6,
  58. name: '防晒霜',
  59. image: 'https://picsum.photos/200/200?random=4'
  60. },
  61. {
  62. id: 5,
  63. name: '防晒霜',
  64. image: 'https://picsum.photos/200/200?random=4'
  65. },
  66. {
  67. id: 7,
  68. name: '防晒霜',
  69. image: 'https://picsum.photos/200/200?random=4'
  70. },
  71. {
  72. id: 8,
  73. name: '防晒霜',
  74. image: 'https://picsum.photos/200/200?random=4'
  75. },
  76. {
  77. id: 9,
  78. name: '防晒霜',
  79. image: 'https://picsum.photos/200/200?random=4'
  80. },
  81. {
  82. id: 10,
  83. name: '防晒霜',
  84. image: 'https://picsum.photos/200/200?random=4'
  85. },
  86. {
  87. id: 11,
  88. name: '防晒霜',
  89. image: 'https://picsum.photos/200/200?random=4'
  90. },
  91. {
  92. id: 12,
  93. name: '防晒霜',
  94. image: 'https://picsum.photos/200/200?random=4'
  95. },
  96. {
  97. id: 13,
  98. name: '防晒霜',
  99. image: 'https://picsum.photos/200/200?random=4'
  100. },
  101. {
  102. id: 14,
  103. name: '防晒霜',
  104. image: 'https://picsum.photos/200/200?random=4'
  105. },
  106. {
  107. id: 15,
  108. name: '防晒霜',
  109. image: 'https://picsum.photos/200/200?random=4'
  110. },
  111. {
  112. id: 16,
  113. name: '防晒霜',
  114. image: 'https://picsum.photos/200/200?random=4'
  115. },
  116. {
  117. id: 17,
  118. name: '防晒霜',
  119. image: 'https://picsum.photos/200/200?random=4'
  120. },
  121. {
  122. id: 18,
  123. name: '防晒霜',
  124. image: 'https://picsum.photos/200/200?random=4'
  125. },
  126. {
  127. id: 19,
  128. name: '防晒霜',
  129. image: 'https://picsum.photos/200/200?random=4'
  130. },
  131. {
  132. id: 20,
  133. name: '防晒霜',
  134. image: 'https://picsum.photos/200/200?random=4'
  135. },
  136. {
  137. id: 21,
  138. name: '防晒霜',
  139. image: 'https://picsum.photos/200/200?random=4'
  140. },
  141. {
  142. id: 22,
  143. name: '防晒霜',
  144. image: 'https://picsum.photos/200/200?random=4'
  145. },
  146. {
  147. id: 23,
  148. name: '防晒霜',
  149. image: 'https://picsum.photos/200/200?random=4'
  150. }
  151. ],
  152. navbar: [
  153. {
  154. name: '中胚层产品',
  155. id: 1
  156. },
  157. {
  158. name: '抗衰除皱',
  159. id: 2
  160. },
  161. {
  162. name: '术后修复',
  163. id: 3
  164. },
  165. {
  166. name: 'SPA产品',
  167. id: 4
  168. },
  169. {
  170. name: '面部护理',
  171. id: 5
  172. },
  173. {
  174. name: '耗材',
  175. id: 6
  176. },
  177. {
  178. name: '临期产品',
  179. id: 7
  180. }
  181. ],
  182. current: 1,
  183. oldScrollTop: 0,
  184. scrollTop: 100
  185. }
  186. },
  187. onShow() {
  188. this.fetchProductTypeFirst()
  189. },
  190. methods: {
  191. onClick(item, index) {
  192. this.current = index
  193. this.scrollTop = this.oldScrollTop
  194. this.$nextTick(() => {
  195. this.scrollTop = 0
  196. })
  197. },
  198. onScroll(e) {
  199. this.oldScrollTop = e.detail.scrollTop
  200. },
  201. // 获取一级商品分了列表
  202. async fetchProductTypeFirst() {
  203. try {
  204. const { data } = await fetchProductTypeFirst()
  205. console.log(data)
  206. } catch (e) {
  207. console.log(e)
  208. }
  209. },
  210. // 获取二级商品分了列表
  211. fetchProductTypeSecond() {}
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .category {
  217. @extend .cm-flex-between;
  218. align-items: flex-start;
  219. background-color: #fff;
  220. .slide-navbar {
  221. width: 200rpx;
  222. height: 100vh;
  223. background-color: #f7f7f7;
  224. box-sizing: border-box;
  225. .slide {
  226. width: 100%;
  227. height: 94rpx;
  228. text-align: center;
  229. line-height: 94rpx;
  230. font-size: 28rpx;
  231. color: #666666;
  232. background-color: #f7f7f7;
  233. &.active {
  234. background-color: #fff;
  235. color: #ff457b;
  236. }
  237. }
  238. }
  239. .panel {
  240. width: 550rpx;
  241. height: 100vh;
  242. padding-bottom: 40rpx;
  243. background-color: #fff;
  244. box-sizing: border-box;
  245. &::after {
  246. content: '';
  247. display: block;
  248. clear: both;
  249. }
  250. .cate {
  251. float: left;
  252. margin-top: 40rpx;
  253. margin-left: 40rpx;
  254. @extend .cm-flex-center;
  255. flex-direction: column;
  256. .cate-icon {
  257. display: block;
  258. width: 128rpx;
  259. height: 128rpx;
  260. }
  261. .cate-name {
  262. @include ellipsis(1);
  263. width: 100%;
  264. margin-top: 16rpx;
  265. color: #666;
  266. font-size: 26rpx;
  267. text-align: center;
  268. }
  269. }
  270. }
  271. }
  272. </style>