const wxmap = require('../../libs/wxmap.js') const app = getApp() Page({ data: { safeBottom: app.globalData.safeBottom, fHeight: app.globalData.safeFragmentHeight, tabList: [ { value: 'source', badge: 0, name: '首页', blue: '/assets/icon/mall-blue.png', gray: '/assets/icon/mall-gray.png' }, { value: 'manager', badge: 0, name: '纸掌柜', blue: '/assets/icon/store-blue.png', gray: '/assets/icon/store-gray.png' }, { value: 'package', badge: 0, name: '我的', blue: '/assets/icon/home-blue.png', gray: '/assets/icon/home-gray.png' } ], tabIndex: 0, cityName: '', }, onLoad: function (options) { if (options.url) { var path = options.url if (options.key && options.value) { path += '?' + options.key + '=' + options.value } wx.navigateTo({ url: path }) } const fHeight = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100 this.setData({ fHeight: fHeight, safeBottom: app.globalData.safeBottom, cityName: this.data.cityName, customHeight: app.globalData.customHeight, customWidth: app.globalData.Custom.left, StatusBar: app.globalData.StatusBar || 40, }) this.locationing() }, /********************************************************getLocation**************************************************************/ locationing: function() { var that = this wx.getLocation({ type: 'gcj02', success (res) { app.nowLocation = res wxmap.geocoder(app.nowLocation.latitude, app.nowLocation.longitude).then(resp => { app.nowLocation.cityName = resp.result.address_component.city.replace('市', '') app.nowLocation.cityCode = resp.result.ad_info.city_code.replace('156', '') app.nowLocation.address = resp.result.address app.nowLocation.districtCode = resp.result.ad_info.adcode if(!app.nowCity){ app.nowCity = { cityName: app.nowLocation.cityName, cityCode: app.nowLocation.cityCode } app.nowCity.latitude = parseFloat(app.nowLocation.latitude.toFixed(6)) app.nowCity.longitude = parseFloat(app.nowLocation.longitude.toFixed(6)) that.setData({ cityName: app.nowLocation.cityName }) } }) }, fail (e){ if (e && (e.errCode == 2 || e.errCode == 404)) { Dialog.alert({ title: '温馨提示', message: '位置信息获取失败,请检查手机“位置信息”是否未开启' }).then(() => {}) } else if (e && ((e.errMsg.indexOf('getLocation:fail auth deny') != -1) || (e.errMsg.indexOf('system permission denied') != -1))) { wx.getSetting({ success(res){ if(res && (res.authSetting["scope.userLocation"] !== undefined && res.authSetting["scope.userLocation"] !==true)){ that.detectSettings() } else { Dialog.alert({ title: '温馨提示', message: '位置信息获取失败,请检查微信是否有定位权限' }).then(() => {}) } } }) } else if (e && e.errMsg.indexOf('getLocation:fail connect ETIMEDOUT') != -1) { Dialog.alert({ title: '温馨提示', message: '位置信息获取失败,请检查网络是否连接' }).then(() => {}) } } }) }, detectSettings: function(){ var message = '小程序没有定位权限,无法提供您周边的纸厂报价和相关信息服务,请前往设置微信小程序的定位权限。' Dialog.confirm({ title: '温馨提示', message, confirmButtonText: '前往设置' }).then(() => { wx.openSetting({ success(result){ if(result && (result.authSetting["scope.userLocation"] !== undefined && result.authSetting["scope.userLocation"] === true)){ this.locationing() } } }) }) }, /********************************************************Tabbar*************************************************************/ onTabClick: function(e){ if(this.data.tabIndex == e.currentTarget.dataset.index){ return } this.setData({ tabIndex: e.currentTarget.dataset.index }) this.onShow() }, stopTouchMove: function(e){ return false }, onShow: function () { var pageView = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value) if (pageView && pageView.onRestart) { pageView.onRestart() } }, onShareAppMessage: function (e) { console.log(e) return { title: '纸通宝工厂版——', path: 'pages/login/index?qrcode=562333739288498176', imageUrl: '/assets/image/icon_logo.png', success: function (res) {} } } })