<template> <view> </view> </template> <script> const app = getApp(); import { findByLatAndLng } from '../../Utils/Api.js' export default { name: 'Postion', data() { return { } }, created() { if(!app.globalData.companyId){ this.postionIng(); } }, methods: { postionIng() { let that = this; uni.getLocation({ type: 'wgs84', success: function(res) { app.globalData.latitude = res.latitude; app.globalData.longitude = res.longitude; that.findByLatAndLng(res.longitude, res.latitude); }, fail: (err) => { if (err.errCode == 2) { uni.showToast({ title: '请开启系统定位', duration: 3000, icon: 'none' }) } else { uni.showToast({ title: '定位失败,请重新进入小程序', duration: 3000, icon: 'none' }) } } }) }, findByLatAndLng(item, item1) { let that = this; let datas = { lng: item, lat: item1 } findByLatAndLng(datas).then(res => { if (res.return_code == '000000') { that.city = res.return_data.provinceName; app.globalData.cityName = res.return_data.provinceName; app.globalData.qianzhuCityName = res.return_data.cityName; app.globalData.cityId = res.return_data.regionId; app.globalData.companyId = res.return_data.companyId; uni.setStorage({ key: "cityId", data: res.return_data.regionId }) uni.setStorage({ key: "cityName", data: res.return_data.provinceName }) uni.setStorage({ key: "qianzhuCityName", data: res.return_data.cityName }) uni.setStorage({ key: "companyId", data: res.return_data.companyId }) } else { uni.showToast({ title: res.return_msg, icon: 'none', duration: 2000 }) } }); }, } } </script> <style> </style>