Commit 2f702978ebc4efc0663f79e279ba90e86e55c114

Authored by wangfan
1 parent fb9e2ba4

快速预定

@@ -42,5 +42,10 @@ Component({ @@ -42,5 +42,10 @@ Component({
42 menuHidden:true 42 menuHidden:true
43 }) 43 })
44 }, 44 },
  45 + activeMenuID(id){
  46 + this.setData({
  47 + activeMenuID:id
  48 + })
  49 + },
45 } 50 }
46 }) 51 })
@@ -72,6 +72,10 @@ Page({ @@ -72,6 +72,10 @@ Page({
72 totalHeight: getApp().system.windowHeight, 72 totalHeight: getApp().system.windowHeight,
73 kindHeight: getApp().system.windowHeight - 68 73 kindHeight: getApp().system.windowHeight - 68
74 }) 74 })
  75 + setTimeout(()=>{
  76 + this.initScrollHeightList();
  77 + },1000)
  78 +
75 }, 79 },
76 80
77 /** 81 /**
@@ -260,39 +264,44 @@ Page({ @@ -260,39 +264,44 @@ Page({
260 }) 264 })
261 }, 265 },
262 getClassNameFlag:true, 266 getClassNameFlag:true,
263 - async bindscroll(e){ 267 + bindscroll(e){
264 if(!this.getClassNameFlag) return; 268 if(!this.getClassNameFlag) return;
265 - console.log(e);  
266 this.getClassNameFlag=false; 269 this.getClassNameFlag=false;
267 - let activeId=await this.getClassName();  
268 - this.getClassNameFlag=true;  
269 - this.setData({  
270 - activeId:activeId, 270 + console.log('this.scrollHeightList',this.scrollHeightList)
  271 + let maxMX=9999999;
  272 + let activeId='';
  273 + Object.keys(this.scrollHeightList).forEach(tid=>{
  274 + let mx=parseInt(e.detail.scrollTop)-parseInt(this.scrollHeightList[tid].top)
  275 + if(mx>-100){
  276 + if(mx<maxMX) {
  277 + maxMX=mx;
  278 + activeId=tid;
  279 + }
  280 + }
271 }) 281 })
  282 + if(activeId){
  283 + console.log(activeId, this.scrollHeightList[activeId].dataset.name)
  284 + this.setData({
  285 + activeId:activeId,
  286 + })
  287 + this.selectComponent("#menu").activeMenuID(activeId);
  288 + }
  289 + this.getClassNameFlag=true;
272 }, 290 },
273 - getClassName(){ 291 + scrollHeightList:{},
  292 + initScrollHeightList(scroll){
  293 + //if(Object.keys(this.scrollHeightList).length>0) return;
274 let that=this; 294 let that=this;
275 return new Promise(function(success,fail){ 295 return new Promise(function(success,fail){
276 - let activeId='';  
277 - let activeTop=-100000;  
278 var query = wx.createSelectorQuery(); 296 var query = wx.createSelectorQuery();
279 query.selectAll('.list-model-masonry').boundingClientRect() 297 query.selectAll('.list-model-masonry').boundingClientRect()
280 query.exec(function (res) { 298 query.exec(function (res) {
281 for(let i=0;i<res[0].length;i++){ 299 for(let i=0;i<res[0].length;i++){
282 let x=res[0][i]; 300 let x=res[0][i];
283 - if(x.top<150){  
284 - console.log(x)  
285 - if(x.top>activeTop){  
286 - activeTop=x.top  
287 - activeId=x.id  
288 - }  
289 - }  
290 - }  
291 - console.log('class_name-activeId',activeId,activeTop);  
292 - if(activeTop>32){  
293 - activeId=''; 301 + //x.top=parseInt(scroll.detail.scrollTop)+parseInt(x.top);
  302 + that.scrollHeightList[x.id]=x;
294 } 303 }
295 - success(activeId) 304 + success()
296 }) 305 })
297 }) 306 })
298 }, 307 },
@@ -12,10 +12,10 @@ @@ -12,10 +12,10 @@
12 > 12 >
13 <view style = "padding-left:180rpx;"> 13 <view style = "padding-left:180rpx;">
14 <view class="section" wx:for="{{cookbooklist}}" wx:key="cookbooklist-key"> 14 <view class="section" wx:for="{{cookbooklist}}" wx:key="cookbooklist-key">
15 - <view id="{{'inToView'+item.id}}" class="class_name {{activeId==item.id?'class_name-active':''}}"> 15 + <view id="{{'inToView'+item.id}}" class="class_name {{activeId==item.id?'class_name-active11':''}}">
16 <view class="text">{{item.class_name}}</view> 16 <view class="text">{{item.class_name}}</view>
17 </view> 17 </view>
18 - <view class="list-model-masonry" id="{{item.id}}"> 18 + <view class="list-model-masonry" id="{{item.id}}" data-name="{{item.class_name}}">
19 <view class="list-model-column"> 19 <view class="list-model-column">
20 <block wx:for="{{item.cookbooklist[0]}}" wx:key="{{item.id}}" wx:for-index="itemIndex" > 20 <block wx:for="{{item.cookbooklist[0]}}" wx:key="{{item.id}}" wx:for-index="itemIndex" >
21 <view class="item"> 21 <view class="item">