carLocation.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="">
  3. <map @touchmove="hiddenNav" @markertap="showNav" style="width: 100%; height: 100vh;" :latitude="latitude"
  4. :longitude="longitude" :markers="markers" show-location>
  5. </map>
  6. <!-- 由于cover-view一些样式及点击事件不支持 -->
  7. <!-- 气泡内容 -->
  8. <view v-if="is_show_nav" class="block-view">
  9. <view class="custom-bubble-name">广东省深圳市宝安区西乡街道普宁升记炒饭肠粉(绿海名苑店)</view>
  10. <view class="flex-row flex-between">
  11. <view class="flex-row block-car-time align-center">
  12. <img style="width: 52rpx;height: 52rpx;" src="https://qiniu.bms16.com/FhKkijkN__9UzhYNgamBFSggIlYo" alt="">
  13. <text class="car-time-text">已驻车 <text class="car-time-text-b">9</text>分钟</text>
  14. </view>
  15. <img style="width: 112rpx;height: 64rpx;" src="https://qiniu.bms16.com/Fts38M35doVjK09GfOza5qD-wwkK" alt="">
  16. </view>
  17. <view class="updata-time">更新于 11-25 23:05 </view>
  18. <view class="car-config-btn">闪灯鸣笛</view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. const http = require('../../common/http.js');
  24. const config = require('../../common/config.js');
  25. const common = require('../../common/common.js');
  26. export default {
  27. data() {
  28. return {
  29. id: 0, // 使用 marker点击事件 需要填写id
  30. latitude: 39.909,
  31. longitude: 116.39742,
  32. address_name: '',
  33. city_name: '',
  34. is_show_nav: true,
  35. markers: [{
  36. id: 1345,
  37. latitude: 39.909,
  38. longitude: 116.39742,
  39. iconPath: 'https://qiniu.bms16.com/Fim2CWvIaWVoqPwQsJbNn-fcS-Ku',
  40. width: 30,
  41. height: 30,
  42. customCallout: {
  43. anchorY: -45, // Y轴偏移量
  44. anchorX: -100, // X轴偏移量
  45. display: 'ALWAYS', // 'BYCLICK':点击显示; 'ALWAYS':常显
  46. },
  47. }], // 标记点
  48. plate_number: '',
  49. carLocationTimer: null, // 定时器变量,用于清除定时器
  50. }
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function(options) {
  56. this.plate_number = options.plate_number
  57. this.latitude=options.latitude||''
  58. this.longitude=options.longitude||''
  59. // this.loadCarAddress()
  60. // // 五秒后重新调用加载车辆位置信息的方法
  61. // this.carLocationTimer = setTimeout(() => {
  62. // this.loadCarAddress();
  63. // }, 5000)
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function() {},
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload() {
  73. // 页面卸载时清除定时器
  74. if (this.carLocationTimer) {
  75. clearTimeout(this.carLocationTimer);
  76. this.carLocationTimer = null; // 确保定时器引用被清除
  77. }
  78. },
  79. methods: {
  80. navAddress() {
  81. const that = this;
  82. uni.openLocation({
  83. latitude: that.latitude - 0,
  84. longitude: that.longitude - 0,
  85. scale: 15,
  86. name: that.city_name,
  87. address: that.address_name,
  88. success: function(res) {}
  89. });
  90. },
  91. loadCarAddress() {
  92. const that = this
  93. http.postApi(config.API_DAYHIRE_CAR_LOCATION, {
  94. plate_number: this.plate_number
  95. }, (resp) => {
  96. if (resp.data.code === 200) {
  97. this.latitude = resp.data.data.latitude
  98. this.longitude = resp.data.data.longitude
  99. this.markers[0].latitude = resp.data.data.latitude
  100. this.markers[0].longitude = resp.data.data.longitude
  101. this.getAddressName()
  102. } else {
  103. // 默认返回上一个页面再提示报错
  104. uni.navigateBack({
  105. delta: 1
  106. })
  107. common.simpleToast(resp.data.msg)
  108. }
  109. })
  110. },
  111. getAddressName(latitude, longitude, type) {
  112. const that = this
  113. //#ifdef MP-ALIPAY
  114. var _pi = "ali_index"
  115. //#endif
  116. //#ifdef MP-WEIXIN
  117. var _pi = "wx_index"
  118. //#endif
  119. const location = {
  120. lat: that.latitude,
  121. lng: that.longitude,
  122. pi: _pi
  123. }
  124. http.postApi(config.API_MAP_REGEO, location, (resp) => {
  125. if (resp.data.code === 200) {
  126. that.address_name = resp.data.data.data.address
  127. that.city_name = resp.data.data.data.province + resp.data.data.data.city
  128. } else {
  129. common.simpleToast('获取车辆定位失败')
  130. }
  131. })
  132. },
  133. hiddenNav() {
  134. this.is_show_nav = false
  135. },
  136. showNav() {
  137. this.is_show_nav = true
  138. }
  139. }
  140. };
  141. </script>
  142. <style>
  143. @import './carLocation.css';
  144. </style>