// packageE/location/location.js var location = require("../../../mybehaviors/location/location"); // var app = getApp(); Component({ behaviors: [location], properties: { datas: { type: null }, component_id: { type: null }, page_id: { type: null } }, data: { address: "", point: { lat: '', lng: '' }, city: "" }, // 私有数据,可用于模板渲染 lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached() { }, moved() {}, detached() {}, }, // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached() {}, // 此处attached的声明会被lifetimes字段中的声明覆盖 ready() { this._getLocation((mapdata,e)=>{ this.setData({ address: mapdata.address, city: mapdata.address_component.city ? mapdata.address_component.city : mapdata.address_component.province, point: e }); }); }, pageLifetimes: { // 组件所在页面的生命周期函数 show() {}, hide() {}, resize() {}, }, methods: { tolocation() { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; const url = `/${currentPage.route}?page_id=${this.data.page_id}`; wx.setStorageSync('diyurl', url); wx.navigateTo({ url: '/packageC/o2o/o2oLocation/o2oLocation?tag=diy' }); }, tosearch() { if (!this.data.city) { wx.showToast({ icon: 'none', title: '请先选择城市', duration: 1000 }); return; } let search_type = this.data.datas.search_type || 'store'; wx.navigateTo({ url: '/packageC/o2o/o2oSearchMultiple/o2oSearchMultiple?city=' + this.data.city + '&point=' + JSON.stringify(this.data.point)+'&search_type='+search_type }); }, } });