vehicle.vue
8.8 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
<template>
<div>
<el-row>
<el-card style="background-color: #F5F7FA">
<el-row>
<el-form :model="queryInfo" :rules="rules" ref="ruleForm">
<el-col :span="6">
<el-form-item label="" prop="vno">
<div class="my-text-area">
<div class="el-input-group__prepend prepand">车牌号</div>
<el-select v-model="queryInfo.vno"
@click.native="getCreden"
default-first-option
:loading="loading" clearable placeholder="请选择" style="width: 100px">
<el-option
v-for="item in vnos"
:key="item.lisenceNo"
:label="item.lisenceNo"
:value="item.lisenceNo"
:disabled="item.disabled">
</el-option>
</el-select>
</div>
<!-- <el-input v-model="queryInfo.vno" size="small" style="width: 200px"-->
<!-- placeholder="车牌号" clearable required>-->
<!-- <template slot="prepend">车牌号</template>-->
<!-- </el-input>-->
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="" prop="vnocolor">
<div class="my-text-area">
<div class="el-input-group__prepend prepand">车牌类型</div>
<el-select required v-model="queryInfo.vnocolor" placeholder="车牌类型" style="width: 100px">
<el-option label="蓝牌" value="1"></el-option>
<el-option label="黄牌" value="2"></el-option>
<el-option label="绿牌" value="3"></el-option>
</el-select>
</div>
</el-form-item>
</el-col>
<el-col :span="3">
<el-button type="primary" icon="el-icon-search" size="mini" @click="getList()">
查询
</el-button>
</el-col>
</el-form>
</el-row>
</el-card>
</el-row>
<div id="mapContainer" style="width: 100%; height: 500px;"></div>
</div>
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';
import { selectVehicle,selectNameList } from '../../api/consigner/vehicle';
import {loginedUserInfo} from "../../api/user";
export default {
name: 'MapComponent',
data() {
return {
mapInstance: null,
queryInfo: {
vno: '',
vnocolor: '2'
},
vnos:[],
loading:false,
rules: {
vno: [
{ required: true, message: '请输入车牌号', trigger: 'blur' },
// { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
],
vnocolor: [
{ required: true, message: '请选择车牌类型', trigger: 'change' }
],
}
};
},
methods: {
//获取车牌号
getCreden(){
this.vnos=[];
//let params={};
this.loading = true;
console.log(loginedUserInfo().username)
selectNameList({'username':loginedUserInfo().username}).then(res =>{
console.log(res)
if (res!=null) {
console.log(res.data.data)
setTimeout(() => {
this.loading = false;
this.vnos=res.data.data;
}, 200);
} else {
this.vnos = [];
}
});
},
getList() {
this.$refs.ruleForm.validate(valid => {
if (!valid) return;
const _this = this;
selectVehicle(this.queryInfo).then((response) => {
const res = response.data;
if (res.code !== '200') {
return _this.$message.error('获取车辆位置失败!');
}
if(res.data.data!=='' && res.data.data!=null){
// 获取车辆位置信息
const vehicle = res.data.data.firstVcl;
// 在获取车辆位置成功的部分,创建信息窗口或者自定义标记
const markerContent = document.createElement('div');
markerContent.innerHTML = `
<div class="rounded-corner" STYLE="width: 200px;background-color: rgba(255,255,255,0.7);text-align: center">
<p>车牌号:${vehicle.vno}</p >
<p>已行驶距离:${vehicle.runDistance}公里</p >
<p>剩余距离:${vehicle.remainDistance}公里</p >
</div>
`;
if (vehicle.lon && vehicle.lat) {
const lon = parseFloat(vehicle.lon) / 600000.0; // 将经度字符串转换为数值并除以 600000.0
const lat = parseFloat(vehicle.lat) / 600000.0; // 将纬度字符串转换为数值并除以 600000.0
//const coords = wgs84togcj02(lon, lat);
// 添加车辆位置标记
const marker = new AMap.Marker({
position: [lon, lat],
map: _this.mapInstance,
content: markerContent
});
const defaultMarker = new AMap.Marker({
position: [lon, lat],
map: _this.mapInstance,
});
// 移动地图中心到车辆位置
_this.mapInstance.setCenter([lon, lat]);
_this.$message.success('获取车辆位置成功!');
} else {
_this.$message.warning('车辆位置信息不完整!');
}
}else{
return _this.$message.error('无相关车辆信息返回');
}
}).catch(error => {
_this.$message.error('获取车辆位置失败:' + error.toString());
});
})
},
initMap() {
AMapLoader.load({
key: 'fdb27c13681d084e85ff8457b5cbe540',
version: '2.0',
plugins: [], // 可以加载地图插件,比如定位、地图工具等
}).then((AMap) => {
this.mapInstance = new AMap.Map('mapContainer', {
zoom: 10,
center: [116.397428, 39.90923], // 设置地图中心点
});
}).catch((err) => {
console.error(err);
});
},
},
mounted() {
this.initMap();
},
};
</script>
<style scoped>
.my-text-area .prepand{
float: left;
width:89px;
height: 28px;
font-size: 12px;
line-height: 28px;
}
</style>
<style>
.my-text-area .el-textarea__inner{
min-height: 28px;
height: 28px;
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}
.rounded-corner {
border-radius: 10px; /* 设置圆角的半径为10像素 */
background-color: #f0f0f0; /* 背景颜色 */
padding: 10px; /* 内边距 */
margin: 10px; /* 外边距 */
box-shadow: 0 0 5px #ddd; /* 盒子阴影效果 */
}
</style>