carLocation.vue 6.3 KB

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