// pages/map/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" import util from "../../utils/util" Page({ /** * 页面的初始数据 */ data: { seachHeight:height, topHeight:rect.top, areas:['姑苏','吴江','苏州'], areaIndex:0, latitude:"", longitude:"", type:0, keywords:"", list:[], showInfo:false, info:null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.type){ this.setData({ type:options.type }) } let that = this; // 获取当前定位 commonApi._post("act/get_suzhou_areas").then(res=>{ wx.getLocation({ type: 'gcj02', success: function (r) { console.log(r) res.data.unshift({ area_id:"", area_title:"全部", lon:r.longitude, lat:r.latitude }) that.setData({ areas:res.data, areaIndex:0 }) } }) commonApi._post("pbservice/Other/getClientConfig",{ unique_key:"wechatxcx" }).then(res=>{ let data = JSON.parse(res.data) this.setData({ indexHot:data.indexHot, isTest:data.isTest }) if(data.isTest==true){ this.setData({ type:1 }) } that.getList() }) }) }, gotoDetail:function(){ if(this.data.info.info.type=='relic'){ wx.navigateTo({ url: '/pages/pbService/wbdw/info/index?id='+this.data.info.info.id, }) } else if(this.data.info.info.type=='restaurant' || this.data.info.info.type=='tenscenic'){ wx.navigateTo({ url: '/pages/info/foodInfo/index?id='+this.data.info.info.id, }) } else { util.gotoDetail(this.data.info.info) } }, onTapMarker:function(e){ console.log(e) this.setData({ info:this.data.list[e.detail.markerId], showInfo:true }) }, hideInfo:function(){ this.setData({ info:null, showInfo:false }) }, changeType:function(e){ this.setData({ type:e.currentTarget.dataset.type }) this.getList() }, changeArea:function(e){ this.setData({ areaIndex:e.detail.value }) this.getList() }, changeRegion:function(e){ console.log(e) this.getList() }, getList:function(){ this.mapCtx = wx.createMapContext("map"); let types = ['','scenic','venue','post','restaurant','relic','tenscenic','cinema'],that = this; this.mapCtx.getRegion({ type: 'gcj02', success: function(res) { console.log(res) commonApi._post("act/map_travel",{ type:types[that.data.type], title:that.data.keywords, m_lon:res.southwest.longitude-0.05, l_lon:res.northeast.longitude+0.05, m_lat:res.southwest.latitude-0.05, l_lat:res.northeast.latitude+0.05 }).then(res=>{ let list = []; res.data.map((item,index)=>{ let mapItem = {}; mapItem.latitude = Number(item.lat); mapItem.longitude = Number(item.lon); mapItem.id = index; mapItem.info = item; mapItem.iconPath = "https://fastadmin.oss-cn-shenzhen.aliyuncs.com/xcxImages/map/"+item.type+".png"; mapItem.width = 20; mapItem.height=23; if(mapItem.latitude<40){ list.push(mapItem) } }) that.setData({ list:list }) }) // that.mapCtx.getRegion({ // success:function(r){ // let location = r.longitude+","+r.latitude; // that.getParkList(res.northeast.longitude,res.northeast.latitude,res.southwest.longitude,res.southwest.latitude,location) // } // }) } }) }, search:function(e){ console.log(e) this.setData(e.detail) this.getList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })