orderMap.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view>
  3. <map id="map" style="width: 100%; height: 700px;" :latitude="latitude" :longitude="longitude" :markers="covers"
  4. :show-location="true" :polyline="polyline">
  5. </map>
  6. <!-- <cover-view class="controls-title">
  7. <cover-view class="tabs_box">
  8. <cover-image class="pay_img" src="../static/avatar.png"></cover-image>
  9. <cover-view class="flex flex-sub margin-left-sm flex-direction justify-between">
  10. <cover-view class="pay_name">骑手预计{{rider.mDateTime[1]}}送达</cover-view>
  11. <cover-view class="text-gray margin-top" style="margin-top: 5rpx;">
  12. 距离您{{rider.aDouble}}
  13. </cover-view>
  14. </cover-view>
  15. <cover-view class="flex">
  16. <cover-image class="pay_img1 margin-right" @click="goNav" src="../../../static/image/order/im.png"></cover-image>
  17. <cover-image class="pay_img1" @click="call" src="../static/phones.png"></cover-image>
  18. </cover-view>
  19. </cover-view>
  20. <cover-view class="tabs_bottom">
  21. <cover-view class="pay_btn" @click="call">
  22. <cover-image class="pay_img" style="width: 40rpx;height: 40rpx;"
  23. src="../../../static/image/icon_number.png"></cover-image>
  24. <cover-view class="pay_tit">电话骑手</cover-view>
  25. </cover-view>
  26. <cover-view class="pay_btn" @click="goNav">
  27. <cover-image class="pay_img" style="width: 40rpx;height: 40rpx;"
  28. src="../../../static/image/my/8.png"></cover-image>
  29. <cover-view class="pay_tit">联系客服</cover-view>
  30. </cover-view>
  31. </cover-view>
  32. </cover-view>
  33. -->
  34. </view>
  35. </template>
  36. <script>
  37. // 引入SDK核心类,地图组件
  38. import QQMapWX from '@/components/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js'
  39. import { waitForGlobalImages } from '@/utils/globalImageLoader'
  40. export default {
  41. data() {
  42. return {
  43. latitude: '',
  44. longitude: '',
  45. qqmapsdk: {}, // 腾讯地图小程序的SDK
  46. covers: [], // 地图上面的标记点
  47. to: { // 目的地坐标
  48. latitude: '',
  49. longitude: '',
  50. },
  51. polyline: [], //路线
  52. polylines: '',
  53. indentNumber: '',
  54. riderUserId: '',
  55. orderDetails: {},
  56. rider: {},
  57. timer: '',
  58. globalImages: ''
  59. }
  60. },
  61. onLoad(option) {
  62. let that = this
  63. // 实例化API核心类
  64. that.qqmapsdk = new QQMapWX({
  65. key: 'MWDBZ-E32CR-GUHWL-WHLAU-6ES76-3PBNV' // 自己申请的key值
  66. })
  67. that.indentNumber = option.indentNumber
  68. that.getData()
  69. waitForGlobalImages().then((path) => {
  70. console.log('✅ 全局图片路径:', path)
  71. this.globalImages = path
  72. })
  73. },
  74. onShow() {
  75. let that = this
  76. this.timer = setInterval(function() {
  77. that.getLocation()
  78. }, 10000)
  79. },
  80. onHide() {
  81. console.log(this.timer, '定时器')
  82. clearInterval(this.timer)
  83. },
  84. methods: {
  85. getData() {
  86. this.$Request.getT('/app/indent/userIndentMessage?indentNumber=' + this.indentNumber).then(res => {
  87. console.log(res)
  88. if (res.code == 0) {
  89. this.orderDetails = res.data
  90. this.polylines = res.data.polyline
  91. this.to.latitude = res.data.deliveryAddressLatitude
  92. this.to.longitude = res.data.deliveryAddressLongitude
  93. this.riderUserId = this.orderDetails.riderUserId
  94. this.getLocation()
  95. // console.log(this.orderDetails.avatar)
  96. // let marker = {
  97. // id: 1,
  98. // latitude: res.data.deliveryAddressLatitude,
  99. // longitude: res.data.deliveryAddressLongitude,
  100. // iconPath: '../static/01.png',
  101. // width: '30',
  102. // height: '30'
  103. // }
  104. // this.markers.push(marker)
  105. // console.log(this.markers)
  106. }
  107. });
  108. },
  109. getLocation() {
  110. let data = {
  111. riderUserId: this.riderUserId,
  112. // lat: this.orderDetails.deliveryAddressLatitude,
  113. // lng: this.orderDetails.deliveryAddressLongitude
  114. }
  115. this.$Request.getT('/timedtask/selectRiderLocation', data).then(res => {
  116. if (res.code === 0) {
  117. this.latitude = res.data.lat;
  118. this.longitude = res.data.lng;
  119. this.covers = [{
  120. id: 1,
  121. latitude: res.data.lat,
  122. longitude: res.data.lng,
  123. iconPath: '../static/avatar.png',
  124. width:28,
  125. height:28,
  126. // callout: { //自定义标记点上方的气泡窗口 点击有效
  127. // content:res.data.address, //文本
  128. // color: '#333333', //文字颜色
  129. // fontSize: 10, //文本大小
  130. // padding: 10, //附近留白
  131. // borderRadius: 6, //边框圆角
  132. // bgColor: '#FFFFFF', //背景颜色
  133. // display: 'ALWAYS', //常显
  134. // },
  135. }, {
  136. id: 2,
  137. latitude: this.orderDetails.deliveryAddressLatitude,
  138. longitude: this.orderDetails.deliveryAddressLongitude,
  139. iconPath: this.globalImages ? this.globalImages + 'images/static/image/zd.png' : '',
  140. width: 32,
  141. height: 44,
  142. callout: { //自定义标记点上方的气泡窗口 点击有效
  143. content:this.orderDetails.deliveryAddress, //文本
  144. color: '#333333', //文字颜色
  145. fontSize: 10, //文本大小
  146. padding: 10, //附近留白
  147. borderRadius: 6, //边框圆角
  148. bgColor: '#FFFFFF', //背景颜色
  149. display: 'ALWAYS', //常显
  150. },
  151. }]
  152. this.routePlanning()
  153. // this.rider = res.data
  154. // this.rider.mDateTime = res.data.mDateTime.split(' ')
  155. // if (this.rider.aDouble > 1000) {
  156. // this.rider.aDouble = Number((this.rider.aDouble / 1000)).toFixed(2) + "km"
  157. // } else {
  158. // if (this.rider.aDouble == 0) {
  159. // this.rider.aDouble = "0m";
  160. // } else {
  161. // this.rider.aDouble = Number(this.rider.aDouble).toFixed(1) + "m";
  162. // }
  163. // }
  164. // let marker = {
  165. // id: 2,
  166. // latitude: res.data.riderLocation.lat,
  167. // longitude: res.data.riderLocation.lng,
  168. // iconPath: '../../../static/image/rider.png',
  169. // width: '30',
  170. // height: '30',
  171. // }
  172. // this.markers.push(marker)
  173. }
  174. });
  175. },
  176. // 步行路线规划
  177. routePlanning() {
  178. let that = this
  179. that.qqmapsdk.direction({
  180. mode: 'driving', // 驾车
  181. from: { // 起始位置(当前位置)坐标
  182. latitude: that.latitude,
  183. longitude: that.longitude
  184. },
  185. to: that.to, // 目的地位置坐标
  186. success(res) {
  187. // console.log(res, '=======')
  188. var coors = JSON.parse(that.polylines)
  189. // console.log(coors,'11111111111111')
  190. // var coors = res.result.routes[0].polyline
  191. // console.log(coors2,'11111111111111')
  192. var pl = [] // 点串数组
  193. // 坐标解压(返回的点串坐标,通过前向差分进行压缩)
  194. var kr = 1000000
  195. for (var i = 2; i < coors.length; i++) {
  196. coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr
  197. }
  198. // 将解压后的坐标放入点串数组pl中
  199. for (var i = 0; i < coors.length; i += 2) {
  200. pl.push({
  201. latitude: coors[i],
  202. longitude: coors[i + 1]
  203. })
  204. }
  205. // 设置polyline属性,将路线显示出来,将解压坐标第一个数据作为起点
  206. that.polyline = [{
  207. points: pl,
  208. color: '#346EF6',
  209. width: 4
  210. }]
  211. }
  212. })
  213. },
  214. call() {
  215. uni.makePhoneCall({
  216. phoneNumber: this.orderDetails.phone
  217. });
  218. },
  219. goNav() {
  220. uni.navigateTo({
  221. url: '/pageA/kefu/kefu'
  222. })
  223. }
  224. },
  225. }
  226. </script>
  227. <style>
  228. .controls-title {
  229. width: 90%;
  230. /* height: 220upx; */
  231. /* line-height: 220upx; */
  232. background: #FFFFFF;
  233. position: fixed;
  234. bottom: 0rpx;
  235. margin: 40upx;
  236. border-radius: 26upx;
  237. box-shadow: 0upx 30upx 40upx 0upx rgba(187, 170, 163, 0.20);
  238. /* margin: 0 40rpx; */
  239. margin-bottom: 50rpx;
  240. }
  241. .tabs_box {
  242. display: flex;
  243. justify-content: space-between;
  244. align-items: center;
  245. padding: 10rpx;
  246. margin: 20rpx;
  247. }
  248. .pay_tit {
  249. flex: 1;
  250. display: flex;
  251. flex-direction: column;
  252. justify-content: space-between;
  253. }
  254. .pay_img {
  255. width: 100rpx;
  256. height: 100rpx;
  257. border-radius: 10rpx;
  258. }
  259. .pay_img1 {
  260. width: 60rpx;
  261. height: 60rpx;
  262. border-radius: 10rpx;
  263. }
  264. .tabs_bottom {
  265. margin: 0 20rpx 20rpx;
  266. display: flex;
  267. }
  268. .pay_btn {
  269. padding: 5rpx 16rpx;
  270. border: solid 2rpx #999999;
  271. margin-right: 20rpx;
  272. display: flex;
  273. align-items: center;
  274. border-radius: 10rpx;
  275. }
  276. .pay_name {
  277. font-size: 32rpx;
  278. font-weight: bold;
  279. }
  280. .pay_line {
  281. height: 2rpx;
  282. background-color: #afafaf;
  283. margin: 10rpx 0;
  284. }
  285. </style>