wangfukang 3 weeks ago
parent
commit
c6cddfc236
  1. 164
      package1/group/groupBuySingle.vue

164
package1/group/groupBuySingle.vue

@ -1,6 +1,6 @@
<template>
<!-- 拼团单一商家 -->
<view class="page1">
<view class="page1" @touchmove="onPageTouchMove">
<!-- 固定顶部导航栏悬浮在背景图之上 -->
<view class="nav-bar"
:style="{'padding-top': menuButtonInfo.top +'px','background':lastScrollTop>200?'#fff':''}">
@ -90,15 +90,15 @@
</swiper>
</view>
<!-- 分类栏移到goods-list外层position:sticky才能生效 -->
<view style="display: flex;height: 72%;margin-top: 10px;">
<view id="menuList" style="border-right: 1px solid #eee;font-weight: 700;font-size: 14px;">
<view class="container" :class="{'container-sticky': isContainerSticky}" :style="{'margin-top': isContainerSticky ? '0' : '10px', 'top': isContainerSticky ? navBarHeight + 'px' : 'auto'}" style="display: flex;height: 72%;">
<scroll-view scroll-y id="menuList" style="border-right: 1px solid #eee;font-weight: 700;font-size: 14px;height: 100%;width: 160rpx;">
<view class="menu1" @tap="checkTab(index)" v-for="(item,index) in menuList" :key="index"
:style="{'border-radius':item.checked?'10px':'','color':item.checked?'rgba(0, 35, 28, 1)':'#777','background':item.checked?'#fff':'','border-right':item.checked?'5px solid #48D1CC;':''}">
<view style="width: 160rpx;">{{item.categoryName}}</view>
</view>
</view>
<view class="goods-list">
<view class="goods-member" v-for="(item,index) in productItem" :key="index"
</scroll-view>
<scroll-view class="goods-list" scroll-y :scroll-into-view="scrollIntoViewId" :scroll-top="goodsListScrollTop" @scroll="onGoodsListScroll" @scrolltoupper="onGoodsListScrollToTop" :scroll-with-animation="true">
<view class="goods-member" :id="'category-' + item.categoryId" v-for="(item,index) in productItem" :key="index"
@tap="goDetail('product',item)">
<view class="goods-top">
<view class="goods-img">
@ -143,7 +143,7 @@
</view>
<uni-load-more :status="loadStatus" @change="onChange" />
<view style="height: 80px;width: 100%;"></view>
</view>
</scroll-view>
</view>
</view>
@ -500,6 +500,13 @@
lastScrollTop: 0,
// onPageScroll
isSwitching: false,
//
isContainerSticky: false,
containerOriginalTop: 0,
scrollIntoViewId: '',
goodsListScrollTop: 0,
isAutoScrolling: false,
pageScrollTop: 0,
searchForm: {
shopId: '',
delFlag: 1,
@ -606,15 +613,95 @@
this.navBarHeight = info.statusBarHeight + 40;
},
onReady() {
//
// container
setTimeout(() => {
const query = uni.createSelectorQuery().in(this);
query.select('#menuList').boundingClientRect(rect => {
if (rect) this.menuListOffsetTop = rect.top + this.lastScrollTop;
query.select('.container').boundingClientRect(rect => {
if (rect) {
this.containerOriginalTop = rect.top;
this.menuListOffsetTop = rect.top;
}
}).exec();
}, 500);
},
onPageScroll(e) {
this.lastScrollTop = e.scrollTop;
// container
const stickyThreshold = this.containerOriginalTop - this.navBarHeight;
if (e.scrollTop >= stickyThreshold && !this.isContainerSticky) {
this.isContainerSticky = true;
}
},
methods: {
// touchmovegoods-list
onPageTouchMove(e) {
// scroll-view
},
// goods-list +
onGoodsListScroll(e) {
if (this.isAutoScrolling) return;
const scrollTop = e.detail.scrollTop;
//
if (scrollTop <= 0 && this.isContainerSticky) {
this.isContainerSticky = false;
return;
}
//
this.detectCurrentCategory();
},
onGoodsListScrollToTop() {
if (this.isAutoScrolling) return;
//
this.isContainerSticky = false;
},
//
detectCurrentCategory() {
if (this.isSwitching) return;
const query = uni.createSelectorQuery().in(this);
// goods-listgoods-member
query.selectAll('.goods-member').boundingClientRect();
query.select('.goods-list').boundingClientRect();
query.exec((res) => {
if (!res || !res[0] || !res[1]) return;
const items = res[0];
const listRect = res[1];
const listTop = listRect.top;
let currentCategoryId = '';
// goods-listitem
for (let i = items.length - 1; i >= 0; i--) {
if (items[i].top <= listTop + 10) {
// productItemcategoryId
if (this.productItem[i]) {
currentCategoryId = this.productItem[i].categoryId;
}
break;
}
}
if (currentCategoryId !== '' || currentCategoryId === '') {
// menuList
let found = false;
for (let i = 0; i < this.menuList.length; i++) {
if (String(this.menuList[i].id) === String(currentCategoryId)) {
if (!this.menuList[i].checked) {
for (let j = 0; j < this.menuList.length; j++) {
this.menuList[j].checked = (j === i);
}
this.$forceUpdate();
}
found = true;
break;
}
}
// categoryId""
if (!found && currentCategoryId === '') {
for (let j = 0; j < this.menuList.length; j++) {
this.menuList[j].checked = (j === 0);
}
this.$forceUpdate();
}
}
});
},
getProduct(categoryId) {
let that = this;
this.loadStatus = 'loading';
@ -666,15 +753,41 @@
}).catch((res) => {})
},
checkTab(index) {
this.isSwitching = true;
for (let i = 0; i < this.menuList.length; i++) {
this.menuList[i].checked = (i === index);
}
//
this.searchForm.pageNum = 1;
this.pageNum = 1;
this.total = 1;
this.productItem = [];
this.getProduct(this.menuList[index].id);
const selectedCategory = this.menuList[index];
// ""id
if (!selectedCategory.id && selectedCategory.id !== 0) {
this.goodsListScrollTop = 0;
this.$nextTick(() => {
this.goodsListScrollTop = 0;
});
} else {
//
if (!this.isContainerSticky) {
this.isContainerSticky = true;
}
// scroll-into-view
const targetId = 'category-' + selectedCategory.id;
// id
this.scrollIntoViewId = '';
this.$nextTick(() => {
this.isAutoScrolling = true;
this.scrollIntoViewId = targetId;
//
setTimeout(() => {
this.isAutoScrolling = false;
this.isSwitching = false;
}, 500);
});
return;
}
setTimeout(() => {
this.isSwitching = false;
}, 300);
this.$forceUpdate();
},
openOrderWait(item){
this.chooseWaitType = false
@ -1221,7 +1334,6 @@
height: 100%;
font-size: 24rpx;
position: relative;
overflow: hidden;
}
/* 顶部背景图随页面滚动(不固定) */
@ -1443,11 +1555,21 @@
}
.goods-list {
width: 95%;
height: auto;
flex: 1;
height: 100%;
border-radius: 20rpx;
margin: 0 auto 20rpx;
overflow: scroll;
overflow: hidden;
}
.container-sticky {
position: fixed;
left: 0;
width: 100%;
z-index: 50;
height: calc(100vh - 80px);
background: #F5F8F5;
padding: 0 2.5%;
box-sizing: border-box;
}
.goods-top {

Loading…
Cancel
Save