map.vue 9.74 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
<template>
<view style="width: 100vw; height: 100vh; position: relative;">
<map style="width: 100vw; height: 100vh;" id="navi_map" :longitude="longitude" :latitude="latitude" scale="10" :markers="markers" :polyline="polyline"></map>
<!--剩余公里数 -->
<view class="Highways">
<view class="stactInfo-title">
进行中
</view>
<view class="stactInfo-hend">
剩余里程<span>{{distance}}公里</span>
</view>
</view>
<!-- 送往到信息 -->
<view class="userInfo">
<!-- <img src="../../static/toes.png" alt="" /> -->
<view class="carInfp">
<img style="width: 32rpx;height: 32rpx;margin:0 20rpx;" src="/static/lindang.png" alt="" />
<view class="item" style="margin-right: 80rpx;">
车牌:{{userInfo.licencePlate || ''}}
</view>
<view class="item">
驾驶员:{{userInfo.driver || ''}}
</view>
</view>
<view class="doctorInfp">
<view class="stactInfo">
<view class="stactInfo-title">
进行中
</view>
<view class="logo">
<img style="" src="/static/toes.png" alt="" />
</view>
</view>
<!-- 医生 -->
<view class="doctor-name" style="margin-top: -30rpx;">
<view class="item">
操作人员:{{userInfo.doctorName || ''}} | 跟车人员:{{userInfo.nurseName || ''}}
</view>
</view>
<!-- 医院 -->
<view class="hospital" >
<img style="width: 32rpx;height: 32rpx;margin:0 20rpx;" src="/static/lindang.png" alt="" />
<view class="hospital-title">
送往{{userInfo.hospital || ''}}
</view>
</view>
<view class="patient">
<view> 患者信息<span>:{{PatientAray.name || ''}} <span style="margin: 0 10rpx;" v-if="PatientAray.sex == 0">男 </span><span style="margin: 0 10rpx;" v-if="PatientAray.sex == 1">女 </span> {{PatientAray.age || ''}}</span></view>
</view>
</view>
</view>
<!-- 到地方到对话框 完成-->
<u-modal :show="showModal" width="200px" :showConfirmButton="false">
<view class="slot-content">
<view class="slot-content-item">
<img src="/static/toes.png" style="width: 220rpx; height: 150rpx;" alt="" />
<view style="margin-top: 20rpx; margin-bottom: 40rpx;text-align: center;">
已到达医院
</view>
<u-button style="width: 183rpx;
height: 57rpx;
background: #5581FF;
border-radius: 29rpx 29rpx 29rpx 29rpx;"
type="primary" text="我已知晓" @click="showModal=false"></u-button>
</view>
</view>
</u-modal>
</view>
</template>

<script>
// 引入高德地图JSAPI(请替换你的API Key)
// 引入haversine库
import haversine from 'haversine-distance';
import {request} from '../../request/request.js'
export default {
data(){
return {
longitude:null,
latitude:null,
markers:null,
cost: '',
polyline: [],
showModal:false,
distance:'',//米
userInfo:{
},
PatientAray:{}
}
},
mounted() {
},
onLoad() {
this.getRouter()
this.getPatient()
console.log(longitude,latitude);
},
onUnload() {
// 页面销毁时的处理
// 比如取消网络请求、清除定时器、解绑事件等
clearInterval(this.walkInterval)
},
methods:{
Setpolyline(points){
this.polyline = [
{
points: points,
color: "#0091ff",
width: 6
}
]
},
// 计算公里数
onRegionChange(startCoords,endCoords){
// 使用haversine库计算距离
const distance = haversine(startCoords, endCoords);
const distance1 = distance.toFixed(1)
this.distance = (distance1 / 1000).toFixed(1); //计算公里数
},
// 添加标记点
setMarker(origin,currentLocation,points,location) {
const location1 = location.split(',')
const origin1 = origin.split(',')
const currentLocation1 = currentLocation.split(',')
const iconPathDoctor = "/static/toes.png";
const markerWidth = 23;
const markerHeight = 33;
this.markers = [
{
id: 0,
latitude: 116.434446 ,
longitude: 39.90816 ,
width: markerWidth,
height: markerHeight
},
{

id: 0,
latitude: 116.434446 ,
longitude: 39.90816 ,
width: markerWidth,
height: markerHeight
},
{
iconPath: "../../static/toes.png",
id: 2,
latitude: 116.434446 ,
longitude:39.90816 ,
width: 50,
height: 50
}
];
console.log( this.markers,' this.markers');
// 起点和终点的经纬度
const startCoords = { latitude: location1[0], longitude: location1[1] };
const endCoords = { latitude: currentLocation1[0], longitude: currentLocation1[1] };
// 行走动态图
this.getTrajectory(points,startCoords,endCoords,location)
},
getTrajectory(trajectory ,startCoords,endCoords ,location){
uni.hideLoading();
this.showModal = false
// // // 定义当前标记的索引
let currentIndex = 0;
this.onRegionChange(startCoords,endCoords)

// 定义行走速度(单位:毫秒)
const walkSpeed = 40000;
// 定义setInterval函数,每隔一定时间更新标记位置 怎么进行销毁
this.walkInterval = setInterval(async () => {
const res = await request({url:'/dispatchOrder'})
const location = res[0].location.split(',')
// 更新标记位置
const startCoords = {latitude: location[0], longitude: location[1]}
this.onRegionChange(startCoords,endCoords)
if (this.distance == 0.0) {
clearInterval(this.walkInterval); // 停止行走
this.showModal = true
} else {
currentIndex++; // 更新当前索引
}
}, walkSpeed);
},
// 唤醒

// 获取患者信息
async getPatient(){
const res = await request({url:'/patient'})
this.PatientAray = res
},
async getRouter(){
uni.showLoading({
title: '加载中’'
});
const _that = this
const res = await request({url:'/dispatchOrder'})
const location = res[0].location
console.log(location,'location');
_that.latitude = +location.split(',')[1]
_that.longitude = +location.split(',')[0]
var amapFile = require('../../utils/amap-wx.130.js');
var myAmapFun = new amapFile.AMapWX({key: 'd4d729753f518b7b925d2f1046fa2cf5'});
const origin = res[0].orderLocation
_that.userInfo = res[0]
const currentLocation = res[0].hospitalLocation
myAmapFun.getDrivingRoute({
origin: `${origin}`,
destination: `${currentLocation}`,
success:function(data){
console.log(data,'data');
var points = [];
if(data.paths && data.paths[0] && data.paths[0].steps){
var steps = data.paths[0].steps;
for(var i = 0; i < steps.length; i++){
var poLen = steps[i].polyline.split(';');
for(var j = 0;j < poLen.length; j++){
points.push({
longitude: parseFloat(poLen[j].split(',')[0]),
latitude: parseFloat(poLen[j].split(',')[1])
})
}
}
}
// 添加汽车标记
_that.setMarker(origin,currentLocation,points,location)
_that.Setpolyline(points)
},
fail: function(info){
console.log(info);
}
})
}
}
}
</script>


<style scoped lang="scss">
::v-deep .slot-content-item{
height: 300rpx;
width: 200rpx;
}
.Highways{
position: absolute;
left: 50%;
transform: translateX(-50%);
top:30rpx;
width: 363rpx;
height: 167rpx;
background: #FFFFFF;
box-shadow: 8rpx 0rpx 16rpx 0rpx #171B25;
border-radius: 8rpx 8rpx 8rpx 8rpx;
.stactInfo-title{
font-family: SourceHanSansSC, SourceHanSansSC;
font-weight: 400;
font-size: 32rpx;
color: #2F3135;
margin: 30rpx 50rpx;
}
.stactInfo-hend{
font-family: SourceHanSansSC, SourceHanSansSC;
font-weight: 400;
font-size: 26rpx;
color: #ADB0B8;
margin: -20rpx 50rpx;
span {
color: #51B343;
}
}
}
.userInfo{
position: absolute;
margin: 0 auto;
bottom: 20rpx;
// width: 670rpx;
padding: 30rpx;
.doctorInfp{
// width: 670rpx;
height: 265rpx;
background: #FFFFFF;
padding: 30rpx;
border-radius: 20rpx 20rpx 20rpx 20rpx;
margin-top: 40rpx;
.patient{
margin-top: 30rpx;
view{
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 400;
font-size: 22rpx;
color: #747474;
span{
font-size: 28rpx;
color: #5580FF;
}
}
}
.hospital{
display: flex;
margin-top: 30rpx;
width: 267rpx;
height: 30rpx;
background: rgba(255,117,42, .1);
border-radius: 3rpx 3rpx 3rpx 3rpx;
.hospital-title{
// margin-left: 10rpx;
font-family: SourceHanSansCN, SourceHanSansCN;
font-weight: 400;
font-size: 22rpx;
color: #FF7529;

}
}
.doctor-name{
display: flex;
}
.stactInfo{
display: flex;
justify-content: space-between;
.stactInfo-title{
ont-family: SourceHanSansCN, SourceHanSansCN;
font-weight: bold;
font-size: 32rpx;
color: #333333;
}
.logo{
width: 78rpx;
height: 78rpx;
margin-top: 20rpx;
border-radius: 2rpx 2rpx 2rpx 2rpx;
background-color: rgba(85,129,255,.1);
display: flex;
align-items: center;
justify-content: center;
margin-right: 20rpx;
img{
width: 65rpx;
height: 46rpx;
}
}
}
}
.item{
font-family: SourceHanSansSC, SourceHanSansSC;
font-weight: 400;
font-size: 28rpx;
color: #818387;
}
.carInfp{
width: 690rpx;
height: 100rpx;
background: #FFFFFF;
display: flex;
align-items: center;
border-radius: 20rpx 20rpx 20rpx 20rpx;
}
}
</style>