123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <template>
- <view class="category">
- <!-- 侧边导航 -->
- <scroll-view class="slide-navbar" :scroll-y="true">
- <template v-for="(item, index) in navbar">
- <view
- class="slide"
- :class="{ active: index === current }"
- :key="item.id"
- v-text="item.name"
- @click="onClick(item, index)"
- ></view>
- </template>
- </scroll-view>
- <!-- 右侧容器 -->
- <scroll-view
- class="panel"
- :scroll-y="true"
- :scroll-with-animation="true"
- :scroll-top="scrollTop"
- @scroll="onScroll"
- >
- <view class="cate" v-for="cate in categories" :key="cate.id">
- <image class="cate-icon" :src="cate.image"></image>
- <view class="cate-name" v-text="cate.name"></view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { fetchProductTypeFirst, fetchProductTypeSecond } from '@/services/api/goods.js'
- export default {
- data() {
- return {
- categories: [
- {
- id: 1,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=1'
- },
- {
- id: 2,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=2'
- },
- {
- id: 3,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=3'
- },
- {
- id: 4,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 6,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 5,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 7,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 8,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 9,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 10,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 11,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 12,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 13,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 14,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 15,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 16,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 17,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 18,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 19,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 20,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 21,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 22,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- },
- {
- id: 23,
- name: '防晒霜',
- image: 'https://picsum.photos/200/200?random=4'
- }
- ],
- navbar: [
- {
- name: '中胚层产品',
- id: 1
- },
- {
- name: '抗衰除皱',
- id: 2
- },
- {
- name: '术后修复',
- id: 3
- },
- {
- name: 'SPA产品',
- id: 4
- },
- {
- name: '面部护理',
- id: 5
- },
- {
- name: '耗材',
- id: 6
- },
- {
- name: '临期产品',
- id: 7
- }
- ],
- current: 1,
- oldScrollTop: 0,
- scrollTop: 100
- }
- },
- onShow() {
- this.fetchProductTypeFirst()
- },
- methods: {
- onClick(item, index) {
- this.current = index
- this.scrollTop = this.oldScrollTop
- this.$nextTick(() => {
- this.scrollTop = 0
- })
- },
- onScroll(e) {
- this.oldScrollTop = e.detail.scrollTop
- },
- // 获取一级商品分了列表
- async fetchProductTypeFirst() {
- try {
- const { data } = await fetchProductTypeFirst()
- console.log(data)
- } catch (e) {
- console.log(e)
- }
- },
- // 获取二级商品分了列表
- fetchProductTypeSecond() {}
- }
- }
- </script>
- <style lang="scss" scoped>
- .category {
- @extend .cm-flex-between;
- align-items: flex-start;
- background-color: #fff;
- .slide-navbar {
- width: 200rpx;
- height: 100vh;
- background-color: #f7f7f7;
- box-sizing: border-box;
- .slide {
- width: 100%;
- height: 94rpx;
- text-align: center;
- line-height: 94rpx;
- font-size: 28rpx;
- color: #666666;
- background-color: #f7f7f7;
- &.active {
- background-color: #fff;
- color: #ff457b;
- }
- }
- }
- .panel {
- width: 550rpx;
- height: 100vh;
- padding-bottom: 40rpx;
- background-color: #fff;
- box-sizing: border-box;
- &::after {
- content: '';
- display: block;
- clear: both;
- }
- .cate {
- float: left;
- margin-top: 40rpx;
- margin-left: 40rpx;
- @extend .cm-flex-center;
- flex-direction: column;
- .cate-icon {
- display: block;
- width: 128rpx;
- height: 128rpx;
- }
- .cate-name {
- @include ellipsis(1);
- width: 100%;
- margin-top: 16rpx;
- color: #666;
- font-size: 26rpx;
- text-align: center;
- }
- }
- }
- }
- </style>
|