|
|
|
@ -25,6 +25,9 @@ Page({ |
|
|
|
searchSectionVisible: true, |
|
|
|
lastScrollTop: 0, |
|
|
|
isScrollLocked: false, |
|
|
|
searchSectionOpacity: 1, |
|
|
|
searchSectionTransform: 0, |
|
|
|
isSearchBarFullyHidden: false, |
|
|
|
|
|
|
|
// 回到顶部按钮
|
|
|
|
showBackToTop: false, |
|
|
|
@ -604,11 +607,13 @@ Page({ |
|
|
|
return { leftColumnGoods: leftColumn, rightColumnGoods: rightColumn } |
|
|
|
}, |
|
|
|
|
|
|
|
// 搜索输入
|
|
|
|
// 搜索输入(实时搜索)
|
|
|
|
onSearchInput: function(e) { |
|
|
|
this.setData({ |
|
|
|
searchKeyword: e.detail.value |
|
|
|
}) |
|
|
|
// 实时应用筛选条件
|
|
|
|
this.searchGoods() |
|
|
|
}, |
|
|
|
|
|
|
|
// 搜索商品
|
|
|
|
@ -637,22 +642,23 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 选择地区
|
|
|
|
// 选择地区(实时更新)
|
|
|
|
selectRegion: function(e) { |
|
|
|
const region = e.currentTarget.dataset.region |
|
|
|
this.setData({ |
|
|
|
selectedRegion: region |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 确认地区选择
|
|
|
|
confirmRegion: function() { |
|
|
|
|
|
|
|
// 重新显示tabBar
|
|
|
|
const app = getApp(); |
|
|
|
if (app && app.globalData) { |
|
|
|
app.globalData.showTabBar = true; |
|
|
|
} |
|
|
|
|
|
|
|
// 应用筛选条件
|
|
|
|
this.setData({ |
|
|
|
selectedRegion: region, |
|
|
|
showRegionPicker: false |
|
|
|
}) |
|
|
|
|
|
|
|
// 重新筛选商品
|
|
|
|
const filteredGoods = this.applyFilters(this.data.goods) |
|
|
|
const groupedGoods = this.groupGoodsForStaggeredLayout(filteredGoods) |
|
|
|
const { leftColumnGoods, rightColumnGoods } = this.distributeToColumns(filteredGoods) |
|
|
|
@ -660,8 +666,7 @@ Page({ |
|
|
|
filteredGoods: filteredGoods, |
|
|
|
groupedGoods: groupedGoods, |
|
|
|
leftColumnGoods: leftColumnGoods, |
|
|
|
rightColumnGoods: rightColumnGoods, |
|
|
|
showRegionPicker: false |
|
|
|
rightColumnGoods: rightColumnGoods |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
@ -782,39 +787,44 @@ Page({ |
|
|
|
onScroll: function(e) { |
|
|
|
const { scrollTop } = e.detail; |
|
|
|
|
|
|
|
if (this.data.isScrollLocked) { |
|
|
|
this.setData({ lastScrollTop: scrollTop }); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const scrollDirection = scrollTop > this.data.lastScrollTop ? 'down' : 'up'; |
|
|
|
const scrollDelta = Math.abs(scrollTop - this.data.lastScrollTop); |
|
|
|
let searchSectionOpacity = 1; |
|
|
|
let searchSectionTransform = 0; |
|
|
|
let isSearchBarFullyHidden = false; |
|
|
|
|
|
|
|
if (scrollDelta < 10) { |
|
|
|
this.setData({ lastScrollTop: scrollTop }); |
|
|
|
return; |
|
|
|
if (scrollTop > 50) { |
|
|
|
// 当滚动距离超过50rpx时,开始逐渐隐藏
|
|
|
|
const hideProgress = Math.min((scrollTop - 50) / 100, 1); // 0-1的隐藏进度
|
|
|
|
searchSectionOpacity = 1 - hideProgress; |
|
|
|
searchSectionTransform = -20 * hideProgress; |
|
|
|
|
|
|
|
// 当隐藏进度达到100%时,完全隐藏并收缩高度
|
|
|
|
if (hideProgress >= 1) { |
|
|
|
isSearchBarFullyHidden = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (scrollDirection === 'down' && scrollTop > 100 && this.data.searchSectionVisible) { |
|
|
|
this.setData({ searchSectionVisible: false, isScrollLocked: true }); |
|
|
|
setTimeout(() => { |
|
|
|
this.setData({ isScrollLocked: false }); |
|
|
|
}, 300); |
|
|
|
} else if (scrollDirection === 'up' && !this.data.searchSectionVisible && scrollTop < 50) { |
|
|
|
this.setData({ searchSectionVisible: true, isScrollLocked: true }); |
|
|
|
setTimeout(() => { |
|
|
|
this.setData({ isScrollLocked: false }); |
|
|
|
}, 300); |
|
|
|
// 当滚动回到顶部时,重置所有状态
|
|
|
|
if (scrollTop <= 50) { |
|
|
|
searchSectionOpacity = 1; |
|
|
|
searchSectionTransform = 0; |
|
|
|
isSearchBarFullyHidden = false; |
|
|
|
} |
|
|
|
|
|
|
|
// 更新搜索框状态和样式
|
|
|
|
this.setData({ |
|
|
|
searchSectionOpacity: searchSectionOpacity, |
|
|
|
searchSectionTransform: searchSectionTransform, |
|
|
|
isSearchBarFullyHidden: isSearchBarFullyHidden, |
|
|
|
lastScrollTop: scrollTop |
|
|
|
}); |
|
|
|
|
|
|
|
// 回到顶部按钮显示逻辑
|
|
|
|
if (scrollTop > 300 && !this.data.showBackToTop) { |
|
|
|
this.setData({ showBackToTop: true }); |
|
|
|
} else if (scrollTop <= 300 && this.data.showBackToTop) { |
|
|
|
this.setData({ showBackToTop: false }); |
|
|
|
} |
|
|
|
|
|
|
|
this.setData({ lastScrollTop: scrollTop }); |
|
|
|
|
|
|
|
const { scrollHeight, clientHeight } = e.detail; |
|
|
|
const distanceToBottom = scrollHeight - scrollTop - clientHeight; |
|
|
|
|
|
|
|
|