// pages/pbService/bike/index.js let systemInfo = wx.getSystemInfoSync(),rect = wx.getMenuButtonBoundingClientRect(); let height = (rect.top - systemInfo.statusBarHeight) * 2 + rect.height + systemInfo.statusBarHeight; import commonApi from "../../../utils/https/common" let app = getApp() Page({ /** * 页面的初始数据 */ data: { seachHeight:height, location:{ latitude:"", longitude:"" }, latitude:"", longitude:"", list:[], types:["公共自行车","找厕所","停车场"],//都做一起了 根据type来分 默认就是自行车 type:0, typeService:['pbservice/Ztfw/publicBycicle','pbservice/Ztfw/toilets','pbservice/Ztfw/park'] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ type:options.type?options.type:0 }) let that = this; wx.getLocation({ altitude: 'altitude', type: 'gcj02', success: function (res) { console.log(res) that.setData({ latitude:options.lat?options.lat:res.latitude, longitude:options.lon?options.lon:res.longitude, location:{ latitude:options.lat?options.lat:res.latitude, longitude:options.lon?options.lon:res.longitude } }) that.getList() }, fail:function(err){ that.setData({ latitude:options.lon?options.lon:app.globalData.latitude, longitude:options.lon?options.lon:app.globalData.longitude, location:{ latitude:options.lat?options.lat:app.globalData.latitude, longitude:options.lon?options.lon:app.globalData.longitude } }) that.getList() } }) }, getList:function(){ // return; commonApi.user_post(this.data.typeService[this.data.type],{ point_type:"gaode", lat:this.data.latitude, lon:this.data.longitude }).then(res=>{ let list = []; if(this.data.type==2){ res.data = res.data.parklist; } res.data.map((item,index)=>{ let mapItem = {}; if(this.data.type==0){ item.showContent = item.name + "(" + item.address + ")"; mapItem.latitude = Number(item.gaodelat); mapItem.longitude = Number(item.gaodelng); } else if(this.data.type==1){ item.showContent = item.poiname; mapItem.latitude = Number(item.latitude); mapItem.longitude = Number(item.longitude); } else if(this.data.type==2){ item.showContent = item.parkName + "(" + item.address + ")"; mapItem.latitude = Number(item.gaodelat); mapItem.longitude = Number(item.gaodelon); } mapItem.id = index; mapItem.info = item; mapItem.iconPath = "https://static.ticket.sz-trip.com/xcxImages/other/bike"+this.data.type+".png"; mapItem.width = 40; mapItem.height=40; if(mapItem.latitude<40){ list.push(mapItem) } }) this.setData({ list:list }) console.log(res) }) }, onTapMarker:function(e){ console.log(e) let index = e.detail.markerId,list = this.data.list; let item = list[index]; wx.showModal({ title:'到这去', content:item.info.showContent, success:function(res){ if(res.confirm){ wx.openLocation({ latitude: item.latitude, longitude: item.longitude, }) } } }) }, changeRegion:function(e){ if(e.type!='end') return; console.log(e.detail.centerLocation) this.setData(e.detail.centerLocation) this.getList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })