carLocation.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="">
  3. <!-- #ifndef APP -->
  4. <map @touchmove="hiddenNav" @markertap="showNav" style="width: 100%; height: calc(100vh - 506rpx);" :latitude="latitude"
  5. :longitude="longitude" :markers="markers" show-location>
  6. </map>
  7. <!-- #endif -->
  8. <!-- #ifdef APP -->
  9. <googleMap keyId="1" width='100%' height='calc(100vh - 506rpx)' v-if="myLocation.latitude" :mapData="{type:3,markers,zoom:13}" :myLocation='myLocation'></googleMap>
  10. <!-- #endif -->
  11. <!-- 由于cover-view一些样式及点击事件不支持 -->
  12. <!-- 气泡内容 -->
  13. <view v-if="is_show_nav" class="block-view">
  14. <view class="custom-bubble-name">{{address}}</view>
  15. <view class="flex-row flex-between">
  16. <view class="flex-row block-car-time align-center">
  17. <img style="width: 52rpx;height: 52rpx;" src="https://qiniu.bms16.com/FhKkijkN__9UzhYNgamBFSggIlYo" alt="">
  18. <text class="car-time-text">已驻车 <text class="car-time-text-b">9</text>分钟</text>
  19. </view>
  20. <img style="width: 112rpx;height: 64rpx;" src="https://qiniu.bms16.com/Fts38M35doVjK09GfOza5qD-wwkK" alt="">
  21. </view>
  22. <view v-if="car_info.heart_time" class="updata-time">更新于 {{car_info.heart_time}} </view>
  23. <view class="car-config-btn">闪灯鸣笛</view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import dayjs from "dayjs";
  29. import googleMap from "@/component/googleMap/googleMap";
  30. const http = require('../../common/request.js');
  31. const config = require('../../common/config.js');
  32. const common = require('../../common/common.js');
  33. export default {
  34. components:{
  35. googleMap
  36. },
  37. data() {
  38. return {
  39. id: 0, // 使用 marker点击事件 需要填写id
  40. latitude: 39.909,
  41. longitude: 116.39742,
  42. address: '',
  43. city_name: '',
  44. is_show_nav: true,
  45. car_info:{},
  46. myLocation:{},
  47. markers: [], // 标记点
  48. plate_number: '',
  49. carLocationTimer: null, // 定时器变量,用于清除定时器
  50. }
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function(options) {
  56. this.car_info = uni.getStorageSync('car_info') || {}
  57. this.car_info.heart_time = this.car_info.heart_time ? dayjs(this.car_info.heart_time).format('YYYY-MM-DD hh:mm:ss') : '未知时间'
  58. this.init()
  59. // this.longitude = {
  60. // longitude:car_info.longitude,
  61. // latitude:car_info.latitude
  62. // }
  63. // this.plate_number = options.plate_number
  64. // this.latitude=options.latitude||''
  65. // this.longitude=options.longitude||''
  66. // this.loadCarAddress()
  67. // // 五秒后重新调用加载车辆位置信息的方法
  68. // this.carLocationTimer = setTimeout(() => {
  69. // this.loadCarAddress();
  70. // }, 5000)
  71. },
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function() {},
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload() {
  80. // 页面卸载时清除定时器
  81. if (this.carLocationTimer) {
  82. clearTimeout(this.carLocationTimer);
  83. this.carLocationTimer = null; // 确保定时器引用被清除
  84. }
  85. },
  86. methods: {
  87. init(){
  88. this.latitude = this.car_info.latitude || 39.909
  89. this.longitude = this.car_info.longitude || 116.39742
  90. this.getAddressName(this.latitude,this.longitude)
  91. let _this = this
  92. uni.getLocation({
  93. success(res) {
  94. _this.myLocation.latitude = res.latitude
  95. _this.myLocation.longitude = res.longitude
  96. _this.markers = [
  97. {
  98. width: 80 / 2,
  99. height: 108 / 2,
  100. id: _this.car_info.car_sn,
  101. longitude: _this.longitude,
  102. latitude: _this.latitude,
  103. iconPath: 'https://qiniu.bms16.com/Fim2CWvIaWVoqPwQsJbNn-fcS-Ku',
  104. iconPathActive: 'https://qiniu.bms16.com/Fim2CWvIaWVoqPwQsJbNn-fcS-Ku',
  105. content:''
  106. },
  107. {
  108. width: 22,
  109. height: 40,
  110. id: 50000,
  111. iconPath: "https://zxappfile.bms16.com/zx_client/location_n.png",
  112. longitude: res.longitude,
  113. latitude: res.latitude,
  114. }
  115. ]
  116. }
  117. })
  118. },
  119. navAddress() {
  120. const that = this;
  121. uni.openLocation({
  122. latitude: that.latitude - 0,
  123. longitude: that.longitude - 0,
  124. scale: 15,
  125. name: that.city_name,
  126. address: that.address_name,
  127. success: function(res) {}
  128. });
  129. },
  130. async loadCarAddress() {
  131. const that = this
  132. http.postApi(config.API_DAYHIRE_CAR_LOCATION, {
  133. plate_number: this.plate_number
  134. }, (resp) => {
  135. if (resp.data.code === 200) {
  136. this.latitude = resp.data.data.latitude
  137. this.longitude = resp.data.data.longitude
  138. this.markers[0].latitude = resp.data.data.latitude
  139. this.markers[0].longitude = resp.data.data.longitude
  140. } else {
  141. // 默认返回上一个页面再提示报错
  142. uni.navigateBack({
  143. delta: 1
  144. })
  145. common.simpleToast(resp.data.msg)
  146. }
  147. })
  148. },
  149. async getAddressName(latitude, longitude) {
  150. const that = this
  151. //#ifdef MP-ALIPAY
  152. var _pi = "ali_index"
  153. //#endif
  154. //#ifdef MP-WEIXIN
  155. var _pi = "wx_index"
  156. //#endif
  157. //#ifdef APP
  158. var _pi = "APP"
  159. //#endif
  160. const location = {
  161. lat: that.latitude,
  162. lng: that.longitude,
  163. pi: _pi
  164. }
  165. let {data} = await http.postApi(config.API_MAP_REGEO, location)
  166. console.log(data.data.data)
  167. if(data.code == 200){
  168. this.address = data.data.data.address
  169. }
  170. },
  171. hiddenNav() {
  172. this.is_show_nav = false
  173. },
  174. showNav() {
  175. this.is_show_nav = true
  176. }
  177. }
  178. };
  179. </script>
  180. <style>
  181. @import './carLocation.css';
  182. </style>