var WxParse = null; var app = getApp() var that=null var that0=null Page( { data: { loadingHidden:false, nodataHidden:true, indicatorDots: true, indicatorDots0: true, vertical: false, vertical0: false, autoplay: true, interval: 6000, interval0: 8000, duration: 1000, duration0: 1000, business:[], navData:[], nav:0, Start: 0, qkeyword:"请输入关键字", keyword:"", },onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { const userId = wx.getStorageSync("userId") const userInfodata = wx.getStorageSync("userInfo") let sel = 3; // 根据用户权限调整选中索引 if (userId && userInfodata) { const userInfo = JSON.parse(userInfodata); if (userInfo.bdshEnable == 1) { sel = 3; // 在特殊权限菜单中,"门店"选项不存在,"我的"选项索引为3 } else { sel = 3; // 在普通菜单中,"门店"选项索引为3 } } // 只设置选中状态,菜单列表由全局配置管理 this.getTabBar().setData({ selected: sel }) } }, onLoad: function(options) { that = this wx.setBackgroundColor({ backgroundColor: "#96C6F5", }) that.clearCache();//清本页缓存 that.getlist(0);//第一次加载数据 var sopenFrame0=setInterval(function (){ clearInterval(sopenFrame0); wx.getLocation({ type: 'gcj02', // 比较精确 success: (res) => { wx.setStorageSync("latitude", res.latitude) wx.setStorageSync("longitude", res.longitude) that.clearCache();//清本页缓存 that.getlist(0); },fail: (err) => { /*wx.showToast({ title: JSON.stringify(err), icon: "none", duration: 20000 })*/ } }) },1000); }, // 下拉刷新 onPullDownRefresh: function () { //在当前页面显示导航条加载动画 wx.showNavigationBarLoading(); //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框 wx.showLoading({ title: '刷新中...', }) that.clearCache(); that.getlist(1);//第一次加载数据 }, // 页面上拉触底事件(上拉加载更多) onReachBottom: function () { that.getlist(2);//后台获取新数据并追加渲染 }, // 清缓存 clearCache:function(){ that.setData({ Start: 0, loadingHidden:false }); }, getlist: function (gp) { var userId = wx.getStorageSync("userId") var LoginId = wx.getStorageSync("LoginId") var latitude = wx.getStorageSync("latitude") var longitude = wx.getStorageSync("longitude") wx.request({ url: app.globalData.apiurl + "/xapiajax.ashx", data: { action:"getBusinessdata", userId:(!userId?"":userId), LoginId:(!LoginId?"":LoginId), keyword:that.data.keyword, t:(that.data.nav>0?that.data.nav:""), Start:that.data.Start, latitude:(!latitude?"":latitude), longitude:(!longitude?"":longitude), }, method:"GET", dataType:"json", header: { "content-type": "application/json" // 默认值 }, success (res) { if(res.data.status==1){ var tmpArr = null; if(gp==0||gp==1){ tmpArr = res.data.Businesslist }else{ tmpArr = that.data.business; tmpArr.push.apply(tmpArr,res.data.Businesslist); } that.setData({ business: tmpArr, Start: that.data.Start+res.data.Businesslist.length, loadingHidden:true }) if(gp==0||gp==1){ that.setData({ navData:res.data.lbs }) if(res.data.Businesslist.length==0){ that.setData({ nodataHidden:false }) }else{ that.setData({ nodataHidden:true }) } } } else{ if(res.data.msg=="您未登录"){ wx.removeStorageSync('userId') wx.removeStorageSync('LoginId') } } if(gp==0||gp==1){ //隐藏loading 提示框 wx.hideLoading(); //隐藏导航条加载动画 wx.hideNavigationBarLoading(); //停止下拉刷新 wx.stopPullDownRefresh(); } } }) },onsearch:function() { var keyword=that.data.keyword.replace(/\s+/g, ""); if(keyword!=""){ that.setData({ keyword:keyword }) that.clearCache();//清本页缓存 that.getlist(0);//第一次加载数据 }else{ wx.showToast({ title: "关键字不能为空", icon: "none", duration: 3000 }) } },swiperchange0:function(e) { },closeserver:function(e) { that.setData({ bodyHidden:true }) },inserver :function(e) { },onnav:function(e) { var index = e.currentTarget.dataset.id that.setData({ nav:index }) that.clearCache(); that.getlist(0); },onamap:function(e) { var address = e.currentTarget.dataset.id var lat = e.currentTarget.dataset.lat var lon = e.currentTarget.dataset.lon wx.navigateTo({ url: "../map/index?lat=" + lon + "&lon=" + lat + "&address=" + address }) },oncopy0:function(e) { var address = e.currentTarget.dataset.id wx.setClipboardData({ data: address, success: function (res) { wx.showToast({ title: "复制成功" }) } }) },onview:function(e) { var id = e.currentTarget.dataset.id wx.navigateTo({ url: "../businessview/index?id=" + id }) } })