navBar.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // components/navbar/index.js
  2. const app = getApp();
  3. const config = require('../../utils/config.js');
  4. var util = require("../../utils/util.js")
  5. Component({
  6. options: {
  7. addGlobalClass: true,
  8. },
  9. /**
  10. * 组件的属性列表
  11. */
  12. properties: {
  13. pageName: String,
  14. showNav: {
  15. type: Boolean,
  16. value: true
  17. },
  18. showHome: {
  19. type: Boolean,
  20. value: true
  21. },
  22. backHome: {
  23. type: [Boolean, String],
  24. value: false
  25. },
  26. none: {
  27. type: [Boolean, String],
  28. value: false
  29. }
  30. },
  31. /**
  32. * 组件的初始数据
  33. */
  34. data: {
  35. branche_name: '上海'
  36. },
  37. lifetimes: {
  38. attached: function() {
  39. this.setData({
  40. navH: app.globalData.navHeight
  41. })
  42. }
  43. },
  44. ready: function() {
  45. const that = this
  46. let branche_code = wx.getStorageSync('branche_code');
  47. let branche_name = wx.getStorageSync('branche_name');
  48. if (!branche_code) {
  49. wx.getLocation({
  50. type: 'wgs84',
  51. success: function(res) {
  52. let latitude = res.latitude
  53. let longitude = res.longitude
  54. wx.request({
  55. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`,
  56. success: res => {
  57. let branche_code = res.data.result.ad_info.city_code.substring(3, 6) + '000';
  58. wx.setStorageSync(
  59. 'branche_name', res.data.result.ad_info.city.substring(0, 2)
  60. )
  61. util.getData('/checkMkt', {
  62. branche_code: branche_code
  63. }).then(res => {
  64. that.setData({
  65. branche_name: res[0].branche_name,
  66. branche_code: res[0].branche_code
  67. });
  68. wx.setStorageSync(
  69. 'branche_code', res[0].branche_code
  70. )
  71. if (that.data.branche_name != '上海' && that.data.branche_name != '北京' && that.data.branche_name !=
  72. '苏州') {
  73. that.setData({
  74. branche_name: '上海'
  75. })
  76. }
  77. })
  78. },
  79. fail: (res) => {
  80. //获取城市失败
  81. }
  82. })
  83. },
  84. fail: (res) => {
  85. // 获取位置失败
  86. }
  87. })
  88. } else {
  89. let cityname = wx.getStorageSync('branche_name')
  90. that.setData({
  91. branche_name: cityname
  92. })
  93. }
  94. },
  95. /**
  96. * 组件的方法列表
  97. */
  98. methods: {
  99. //回退
  100. navBack: function() {
  101. wx.navigateBack({
  102. delta: 1
  103. })
  104. },
  105. //回主页
  106. toIndex: function() {
  107. wx.navigateTo({
  108. url: '/pages/admin/home/index/index'
  109. })
  110. },
  111. tocity() {
  112. wx.navigateTo({
  113. url: '/pages/city/city'
  114. })
  115. }
  116. }
  117. })