| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- <template>
- <view class="content">
- <scroll-view scroll-y class="left-aside">
- <view v-for="item in flist" :key="item.id" class="f-item b-b" :class="{ active: item.id === currentId }" @click="tabtap(item)">
- {{ item.cate_name }}
- </view>
- </scroll-view>
- <scroll-view scroll-with-animation scroll-y class="right-aside" @scroll="asideScroll" :scroll-top="tabScrollTop">
- <view v-for="item in flist" :key="item.id" class="s-list" :id="'main-' + item.id">
- <text class="s-item">{{ item.cate_name }}</text>
- <view class="t-list ">
- <view @click="navToList(item.id, titem.id)" class="t-item" v-for="titem in item.children" :key="titem.id">
- <view class="">
- <image :src="titem.pic"></image>
- </view>
-
- <view class="titem-right">
- <text>{{ titem.cate_name }}<br><text>跨店联盟洗护专属礼包</text></text>
- <view class="titem-right-d">
- <view class="price">
- ¥138
- </view>
- <view class="button">
- 马上购
- </view>
- </view>
- </view>
-
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { getCategoryList } from '@/api/product.js';
- export default {
- data() {
- return {
- sizeCalcState: false,
- tabScrollTop: 0,
- currentId: 1,
- flist: [],
- };
- },
- onLoad() {
- this.loadData();
- },
- // 监听导航栏输入框点击事件
- onNavigationBarSearchInputClicked(e) {
- uni.navigateTo({
- url: '/pages/product/search'
- });
- },
- methods: {
- // 载入数据
- async loadData() {
- let obj = this;
- getCategoryList({})
- .then(({ data }) => {
- obj.flist = data.map(function(s) {
- return s;
- });
- })
- .catch(err => {
- console.log(err);
- });
- },
- //一级分类点击
- tabtap(item) {
- console.log(item);
- // 判断有没有初始化页面高度对象数据
- if (!this.sizeCalcState) {
- this.calcSize();
- }
- // 获取当前点击的id
- this.currentId = item.id;
- this.tabScrollTop = item.top;
- },
- //右侧栏滚动
- asideScroll(e) {
- // 判断有没有初始化页面高度对象数据
- if (!this.sizeCalcState) {
- this.calcSize();
- }
- let scrollTop = e.detail.scrollTop;
- let box = 0; //列表包裹框高度初始化
- let bottom = 10; //距离页面底部多少像素左侧列表切换到最后一个一级分类
- // 查询当前页面对象
- let view = uni.createSelectorQuery().select('.content');
- view.fields(
- {
- id: true,
- dataset: true,
- rect: true,
- size: true,
- scrollOffset: true
- },
- function(e) {
- // 保存包裹框高度
- box = e.height;
- }
- ).exec();
- // 获取所有距离顶部大于滚轮距离页面高度的所有分类
- let tabs = this.flist.filter(item =>( item.top-10) <= scrollTop).reverse();
- if (tabs.length > 0) {
- // 判断是否已经到达滚轮底部
- if (box + scrollTop + bottom >= e.detail.scrollHeight) {
- this.currentId = this.flist[this.flist.length - 1].id;
- } else {
- this.currentId = tabs[0].id;
- }
- }
- },
- //计算右侧栏每个tab的高度等信息
- calcSize() {
- let h = 0;
- this.flist.forEach(item => {
- let view = uni.createSelectorQuery().select('#main-' + item.id);
- view.fields(
- {
- size: true
- },
- data => {
- item.top = h;
- h += data.height;
- item.bottom = h;
- }
- ).exec();
- });
- this.sizeCalcState = true;
- },
- navToList(sid, tid) {
- // 点击导航跳转到详细页面
- uni.navigateTo({
- url: '/pages/product/list?fid='+this.currentId+'&sid='+sid+'&tid='+tid
- });
- }
- }
- };
- </script>
- <style lang="scss">
- page,
- .content {
- height: 100%;
- background-color: #f8f8f8;
- }
- .content {
- display: flex;
- }
- .left-aside {
- flex-shrink: 0;
- width: 200rpx;
- height: 100%;
- background-color: #F2F2F2;
-
- }
- .f-item {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100rpx;
- font-size: 28rpx;
- color: $font-color-base;
- position: relative;
- &.active {
- color: #000;
- font-weight: bold;
- background: #fff;
- &:before {
- content: '';
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- height: 100%;
- width: 4rpx;
- background-color: #1075FF;
- border-radius: 0 4px 4px 0;
- opacity: 0.8;
- }
- }
- }
- .right-aside {
- // flex: 1;
- background-color: #fff;
- overflow: hidden;
- .s-list {
- margin-top: 2rpx;
- // padding: 5rpx;
- margin: 25rpx;
- }
- }
- .s-item {
- display: flex;
- // align-items: center;
- height: 70rpx;
- padding: 30rpx;
- padding-top: 20rpx;
- font-size: 28rpx;
- color: $font-color-dark;
- }
- .t-list {
- // display: flex;
- // flex-wrap: wrap;
- border-radius: 15rpx;
- width: 100%;
- background: #fff;
- padding-top: 12rpx;
- &:after {
- content: '';
- flex: 99;
- height: 0;
- }
- }
- .t-item {
- margin-top: 20rpx;
- flex-shrink: 0;
- display: flex;
- border-bottom: solid 1rpx #F2F2F2;
- // justify-content: center;
- // align-items: center;
- // flex-direction: column;
- // padding: 30rpx;
- width: 100%;
- font-size: 26rpx;
- color: #666;
- padding-bottom: 20rpx;
- image {
- width: 180rpx;
- height: 180rpx;
- margin: 0 20rpx;
- border-radius: 10rpx;
- }
-
- .titem-right {
- display: grid;
- align-content: space-between;
- text:nth-child(1) {
- color: #333333;
- font-size: 32rpx;
- }
- text:nth-child(2) {
- color: #666666;
- font-size: 28rpx;
- }
- .titem-right-d {
- display: flex;
- justify-content: space-between;
- .price {
- color: #FB3A2F;
- font-size: 32rpx;
- }
- .button {
- background: linear-gradient(90deg, #438BED 0%, #44BFEC 100%);
- background-color: #438BED;
- height: 50rpx;
- line-height: 50rpx;
- border-radius: 25rpx;
- padding: 0 30rpx;
- color: #fff;
- font-size: 25rpx;
- }
- }
-
- }
- }
- </style>
|