// pages/info/roadInfo/index.js let device = wx.getSystemInfoSync(); const ratio = device.windowWidth / 750; import commonApi from "../../../utils/https/common" import util from "../../../utils/util" let app = getApp() Page({ /** * 页面的初始数据 */ data: { fixed:false, type:1, info:null, top:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ this.setData({ id:options.id }) } else { util.back(); return; } let rect = wx.getMenuButtonBoundingClientRect(); let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; console.log(height) this.setData({ top:height }) let api = commonApi._post; if(wx.getStorageSync("jstrip_token")){ api = commonApi.user_post; } api("product/get_product_detail",{ id:options.id }).then(res=>{ res.data.display_tags = (res.data.display_tags?res.data.display_tags.split(","):[]).splice(0,2); res.data.sku.map(item=>{ item.sku_model.recharge = item.sku_model.recharge?item.sku_model.recharge.split(","):[]; item.sku_model.recharge.map(item=>{ item = Number(item); }) }) this.setData({ info:res.data }) }) }, changeMenu:function(e){ let index = e.currentTarget.dataset.index,that = this; const query=wx.createSelectorQuery(); //创建节点查询器 query.select("#box"+index).boundingClientRect() //选择toViewid获取位置信息 query.selectViewport().scrollOffset() //获取页面查询位置的 query.exec(function(res) { let scrollTop = res[0].top + res[1].scrollTop - 110 * ratio - that.data.top; wx.pageScrollTo({ scrollTop: scrollTop + 4, duration: 0 }) that.setData({ type:index }) }) }, order:function(){ app.globalData.couponInfo = null; app.globalData.product = { product:this.data.info, sku:this.data.info.sku[0] } wx.navigateTo({ url: '/pages/order/card/index' }) }, onPageScroll:function(e){ let that = this,height = this.data.top; let topHeight = height; wx.createSelectorQuery().select('#menus').boundingClientRect(function(rect){ console.log(rect.top,topHeight) if(rect.top<=topHeight){ // 此时应该把menus固定在顶部 that.setData({ fixed:true }) } else{ that.setData({ fixed:false }) } // 滚动时判断滚动到哪个部分了 const query=wx.createSelectorQuery(); //创建节点查询器 query.select("#box1").boundingClientRect() //选择toViewid获取位置信息 query.select("#box2").boundingClientRect() //选择toViewid获取位置信息 let minHeight = that.data.fixed?(110 * ratio + height): topHeight; query.exec(function(res) { if(res[1].top