// pages/login/login.js import WxValidate from '../../utils/wxValidate' const app = getApp() Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '位置信息登记', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', // 查询 form: {}, // 地图 key: 'AFMBZ-7LJC6-TKWSZ-E232O-TUK7K-TIBPU', markers: [], positionInfo: { longitude: 126.414274, latitude: 41.944132 } }, initValidate() { const rules = { boundary: { required: true, }, keyword: { required: true } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { boundary: { required: '请输入城市名称', }, keyword: { required: '请输入关键词', } }; this.WxValidate = new WxValidate(rules, messages) }, back: function () { wx.navigateBack({ url: '/pages/merchant/index' }) }, // 查询数据 onSubmit: function (e) { const params = e.detail.value; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { wx.serviceMarket.invokeService({ service: 'wxc1c68623b7bdea7b', api: 'poiSearch', data: { "boundary": `region(${params.boundary})`, "keyword": params.keyword, page_size: 20 }, }).then(res => { const markers = res.data.data.map((i) => ({ title: i.title, longitude: i.location.lng, latitude: i.location.lat })) if (markers) this.setData({ markers: markers }) if (markers) this.setData({ positionInfo: markers[0] }) }).catch(err => { console.log(err); }) } }, // 选点 toOne: function (e) { const data = e.detail; this.setData({ positionInfo: data }) this.setData({ markers: [data] }) }, // 确认选点 toCheck: function () { let data = this.data.positionInfo; console.log(data); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //验证规则函数 this.initValidate() // 计算高度 this.searchHeight(); }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; // 减去状态栏 let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2); // 是否减去底部菜单 if (frameStyle.useBar) infoHeight = infoHeight - 50; if (infoHeight) this.setData({ infoHeight: infoHeight }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })