// pages/sportsGroundList/index.js const app = getApp(); let latitude = 31.2336800000; // 纬度 let longitude = 121.4715700000; // 经度 let page = 1; Page({ /** * 页面的初始数据 */ data: { state: 1, venues: [], isShowAuth: false, isShowNewplot: false, isGoHome: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { let that = this; this.setData({ state: options.state }) this.getLocationDistance(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { let pages = getCurrentPages(); this.setData({ isGoHome: pages.length == 1 }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { this.getData(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { this.getData(++page); }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { return { title: '智慧云馆' } }, // 切换列表 changeTip(e) { let state = e.currentTarget.dataset.state; this.setData({ state: state }) this.getData(); }, // 点击cell clickCell(e) { let id = e.currentTarget.dataset.id; if (this.data.state == 1) { wx.navigateTo({ url: `/pages/basketballGym/index?id=${id}`, }) } if (this.data.state == 2 || this.data.state == 3) { wx.navigateTo({ url: `/pages/gymnasium/index?id=${id}`, }) } }, getLocationDistance(){ let that = this; wx.getFuzzyLocation({ type: 'gcj02', success: function(res) { latitude = res.latitude; longitude = res.longitude; that.getData() }, fail: function(res) { that.getData() }, }) }, // 获取数据 getData(e) { wx.showLoading({ title: '加载中...', mask: true, }) app.$api.venues({ latitude: latitude, longitude: longitude, page: e ? e : 1, pageSize: 10, type: this.data.state }).then(res => { page = res.page.data.length > 0 ? res.page.page : page--; let list = []; if (e) { list = this.data.venues } for (let i = 0; i < res.page.data.length; i++) { list.push(res.page.data[i]); } this.setData({ venues: list, isShowNewplot: true }) // if (this.data.state == 3) { // wx.showToast({ // title: '暂未开放,敬请期待', // icon: 'none', // }) // } wx.stopPullDownRefresh(); }, err => { wx.stopPullDownRefresh(); this.setData({ isShowNewplot: true }) }) } })