// pages/pbService/gym/index.js import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { types:[], typeIndex:0, list:[], page_no:1, total:1, location:{ latitude:"31.307249", longitude:"120.591426" } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; commonApi._post("pbservice/Gym/getGymTypes").then(res=>{ that.setData({ types:res.data.classifyList }) wx.getLocation({ type: 'gcj02', success:function(res){ that.setData({ location:res }) that.getList() }, fail:function(){ wx.showToast({ title: '请开启定位授权后重试', icon:'none' }) } }) }) }, changeType:function(e){ this.setData({ typeIndex:e.detail.value, list:[], page_no:1, total:1 }) this.getList() }, getList:function(){ let list = this.data.list; if(list.length>=this.data.total) return; commonApi._post("pbservice/Gym/getGymsByClassify",{ page_no:this.data.page_no, page_num:10, // point_type:"gaode", lon:this.data.location.longitude, lat:this.data.location.latitude, classify:this.data.types[this.data.typeIndex].cid }).then(res=>{ res.data.subStadiumList.map(item=>{ if(item.distance && item.distance>=1000){ item.distance = item.distance/1000+"km"; } else if(item.distance || item.distance==0){ item.distance = item.distance+"m"; } }) this.setData({ list:list.concat(res.data.subStadiumList), total:res.data.count, page_no:this.data.page_no+1 }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.getList() }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })