123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // components/navbar/index.js
- const app = getApp();
- const config = require('../../utils/config.js');
- var util = require("../../utils/util.js")
- Component({
- options: {
- addGlobalClass: true,
- },
- /**
- * 组件的属性列表
- */
- properties: {
- pageName: String,
- showNav: {
- type: Boolean,
- value: true
- },
- showHome: {
- type: Boolean,
- value: true
- },
- backHome: {
- type: [Boolean, String],
- value: false
- },
- none: {
- type: [Boolean, String],
- value: false
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- branche_name: '上海'
- },
- lifetimes: {
- attached: function() {
- this.setData({
- navH: app.globalData.navHeight
- })
- }
- },
- ready: function() {
- const that = this
- let branche_code = wx.getStorageSync('branche_code');
- let branche_name = wx.getStorageSync('branche_name');
- if (!branche_code) {
- wx.getLocation({
- type: 'wgs84',
- success: function(res) {
- let latitude = res.latitude
- let longitude = res.longitude
- wx.request({
- url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
- success: res => {
- let branche_code = res.data.result.ad_info.city_code.substring(3, 6) + '000';
- wx.setStorageSync(
- 'branche_name', res.data.result.ad_info.city.substring(0, 2)
- )
- util.getData('/checkMkt', {
- branche_code: branche_code
- }).then(res => {
- that.setData({
- branche_name: res[0].branche_name,
- branche_code: res[0].branche_code
- });
- wx.setStorageSync(
- 'branche_code', res[0].branche_code
- )
- if (that.data.branche_name != '上海' && that.data.branche_name != '北京' && that.data.branche_name !=
- '苏州') {
- that.setData({
- branche_name: '上海'
- })
- }
- })
- },
- fail: (res) => {
- //获取城市失败
- }
- })
- },
- fail: (res) => {
- // 获取位置失败
- }
- })
- } else {
- let cityname = wx.getStorageSync('branche_name')
- that.setData({
- branche_name: cityname
- })
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- //回退
- navBack: function() {
- wx.navigateBack({
- delta: 1
- })
- },
- //回主页
- toIndex: function() {
- wx.navigateTo({
- url: '/pages/admin/home/index/index'
- })
- },
- tocity() {
- wx.navigateTo({
- url: '/pages/city/city'
- })
- }
- }
- })
|