zoneCar copy.vue
20.4 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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<template>
<v-full-layout ref="vFullLayout">
<template slot="main">
<div
ref="map"
id="map"
class="map-container"
v-loading="mapLoading"
></div>
<div class="row_box_hide" v-if="hideRowBox" @click="onShow">
<glsx-image src="car.png" class="img img_normal" />
<glsx-image src="car_hover.png" class="img img_hover" />
<!-- <img src="@/assets/images/car.png" class="img img_normal" alt="" />
<img src="@/assets/images/car_hover.png" class="img img_hover" alt="" /> -->
</div>
<div class="row_box" v-else>
<div class="hide_icon" @click="onShow">
<!-- <img src="@/assets/images/hide.png" class="img" alt="" /> -->
<glsx-image src="hide.png" class="img" />
</div>
<div class="row_head">
<div
class="cell"
:class="menuId == item.id ? 'active' : ''"
v-for="(item, index) in menus"
:key="`menu_${index}`"
@click="menuEvent(item)"
>
{{ item.name }}
</div>
</div>
<div class="row_content">
<el-form
ref="form"
:model="form"
class="el_form"
label-position="top"
>
<div v-show="menuId == 1">
<el-form-item label="行政区域">
<CitySelect
ref="citySelect"
v-model="form.area"
class="el_select"
@change="onChange"
/>
</el-form-item>
<el-form-item label="详细地址">
<el-input v-model="form.address" placeholder="请输入详细地址" />
</el-form-item>
</div>
<div v-show="menuId == 2">
<el-form-item label="设备号">
<div class="device_label" slot="label">
<span>设备号</span>
<el-tooltip
content="请先设备号精准搜索设备定位后,再进行“选择区域”操作"
placement="top"
>
<i class="el-icon-warning-outline"></i>
</el-tooltip>
</div>
<div class="device_item">
<el-input
v-model="form.sn"
placeholder="请输入您要查询的设备号"
/>
<el-button
type="primary"
class="btn"
:disabled="!form.sn"
@click="getLocation"
>搜索</el-button
>
</div>
</el-form-item>
</div>
<el-form-item label="">
<div>
<el-button class="area_btn" @click="chooseArea"
>选择区域</el-button
>
<span class="clear_link" @click="onClear">清除</span>
</div>
</el-form-item>
<div class="tips_info">
<span
>长度:<i>{{ rectangleWidth || "--" }}</i
>m</span
>
<span
>宽度:<i>{{ rectangleHeight || "--" }}</i
>m</span
>
</div>
<div class="btn_group">
<el-button
type="primary"
class="search_btn"
:loading="loading"
:disabled="!rectangle"
@click="getAreaLocation"
>查询</el-button
>
</div>
</el-form>
</div>
</div>
<!-- 底部 开始 -->
<div class="bottom_list_hide" v-if="hideFooter" @click="onHide">
<i class="el-icon-arrow-up"></i>
<span>显示</span>
</div>
<div class="bottom_list" :style="`height:${bHeight}px;`" v-else>
<div class="head">
<div class="left">
<span>已查询到设备共计</span>
<span class="cred">{{ deviceList.length }}</span>
<span>条</span>
<el-button
class="btn"
:loading="dloading"
:disabled="!deviceList || deviceList.length <= 0"
@click="downloadExcel"
>导出</el-button
>
</div>
<div class="right">
<a href="javascript:void(0)" class="link" @click="unfold">展开</a>
<a href="javascript:void(0)" class="link" @click="packUp">收起</a>
<a href="javascript:void(0)" class="link" @click="onHide">隐藏</a>
</div>
</div>
<div class="content">
<!-- <vxe-grid
:columns="columns"
ref="xGrid"
max-height="100%"
:data="deviceList"
size="small"
show-overflow
v-if="drawDone"
>
</vxe-grid> -->
<!-- <el-table :data="deviceList" size="small">
<el-table-column
label="业务工单号"
prop="workOrderNo"
show-overflow-tooltip
/>
<el-table-column
label="店面名称"
prop="shopName"
show-overflow-tooltip
/>
<el-table-column
label="姓名"
prop="ownerName"
show-overflow-tooltip
/>
<el-table-column label="车架号" prop="vin" show-overflow-tooltip />
<el-table-column label="设备号" prop="sn" show-overflow-tooltip />
<el-table-column
label="激活时间"
prop="activeDate"
show-overflow-tooltip
/>
<el-table-column
label="设备类型"
prop="deviceTypeStr"
show-overflow-tooltip
/>
<el-table-column
label="最后GPS定位时间"
prop="finalGpsTime"
show-overflow-tooltip
/>
</el-table> -->
</div>
</div>
<!-- 底部 end -->
</template>
</v-full-layout>
</template>
<script>
import mapService from "@/utils/mapService.js";
import "@/utils/mapEvent.js";
import { CONSTANT } from "@/constant";
import CitySelect from "@/components/area";
import {
GER_REGIONAL_SEARCH,
GER_REGIONAL_EXPORT,
} from "@/api/services/zooneCar";
import { GET_DEVICEINFO_BYSNS } from "@/api/services/monitor";
import EventBus from "@/event-bus";
import { showToast, deepClone } from "@/utils/utils.js";
import moment from "moment";
export default {
components: {
CitySelect,
},
data() {
return {
menus: [
{ name: "区域查车", id: 1 },
{ name: "设备号查车", id: 2 },
],
menuId: 1,
map: null,
mapLoading: true,
form: {},
rectangle: null,
rectangleEditor: null,
rectangleWidth: 0, // 矩形宽度
rectangleHeight: 0, // 矩形高度
bHeight: 313,
hInterval: null,
hideRowBox: false,
hideFooter: true,
//rectangleInfo:{}, // 矩形坐标点信息
deviceList: [],
loading: false,
dloading: false,
autoOpenLastInfoWindow: false,
columns: [
{ type: "seq", title: "序号", width: "55px" },
{ field: "workOrderNo", title: "业务工单号" },
{ field: "shopName", title: "店面名称" },
{ field: "ownerName", title: "姓名" },
{ field: "vin", title: "车架号" },
{ field: "sn", title: "设备号" },
{ field: "activeDate", title: "激活时间" },
{ field: "deviceTypeStr", title: "设备类型" },
{ field: "finalGpsTime", title: "最后GPS定位时间" },
{ field: "finalGpsAddress", title: "最后GPS定位地址", width: "300px" },
],
drawDone: false,
location: {}, // 设备维度查询的位置点
};
},
mounted() {
this.initMap();
},
methods: {
// 地图初始化
initMap() {
let _this = this;
let plugins = CONSTANT.MAP_PLUGINS.concat([
"AMap.LngLat",
"AMap.Rectangle",
"AMap.RectangleEditor",
"AMap.LabelsLayer",
"AMap.LabelMarker",
]);
_this.$mapInit({ plugins: plugins }).then((AMap) => {
_this.mapLoading = false;
window.AMap = AMap;
_this.map = mapService.init("map");
});
},
// 画矩形
drawRectangle(lnglat) {
let _this = this;
let lng = lnglat.southWest.lng;
let lat = lnglat.southWest.lat;
let nlng = lnglat.northEast.lng;
let nlat = lnglat.northEast.lat;
let southWest = new AMap.LngLat(lng, lat);
let northEast = new AMap.LngLat(nlng, nlat);
let rectangle = this.rectangle;
let rectangleEditor = this.rectangleEditor;
// if (rectangle || rectangleEditor) {
// //rectangleEditor.close();
// // this.map.remove([rectangle, rectangleEditor]);
// this.clearMap();
// }
this.clearMap();
let bounds = new AMap.Bounds(southWest, northEast);
rectangle = new AMap.Rectangle({
bounds: bounds,
strokeColor: "#f00",
strokeWeight: 3,
strokeOpacity: 1,
strokeDasharray: [30, 10],
// strokeStyle还支持 solid
strokeStyle: "dashed",
fillColor: "blue",
fillOpacity: 0.2,
cursor: "pointer",
zIndex: 50,
});
rectangleEditor = new AMap.RectangleEditor(this.map, rectangle);
rectangleEditor.open();
rectangleEditor.on("adjust", function (event) {
_this.calculateWidthHeight(event.bounds);
});
this.map.add(rectangle);
this.map.setFitView(rectangle);
// rectangle.on("dragend", function (event) {
// console.log("拖动:", event);
// });
this.rectangleEditor = rectangleEditor;
this.rectangle = rectangle;
this.rectangleHeight = 500;
this.rectangleWidth = 500;
this.map.setZooms([12, 30]);
},
/**
* 计算对应点的位置
* lng:中心点经度 lat:中心点维度 距离默认500m
* 垂直距离lath(所求点在已知点上方(北方)为正,否则为负)
* 水平距离longw(所求点在已知点右方(东方)为正,否则为负)
* lat = latitude + lath / (ARC * math.pi / 180);
* lng = longitude + longw / (ARC * math.cos(latitude) * math.pi / 180);
*/
getLngLat(lng, lat, w) {
let ARC = 6371.393 * 1000;
let pi = Math.PI;
let num = w ? w / 2 : 500 / 2;
// 中心点-左边点的经纬度
let leftLng = lng - num / ((ARC * Math.cos(lat) * pi) / 180);
// let leftLat = lat;
// 中心点-下边点的经纬度
// let bottomLng = lng;
let bottomLat = lat - num / ((ARC * pi) / 180);
// 中心点-右边点经纬度
let rightLng = lng + num / ((ARC * Math.cos(lat) * pi) / 180);
// let rightLat = lat;
// 中心点-上边点经纬度
// let topLng = lng;
let topLat = lat + num / ((ARC * pi) / 180);
// 左下角 经纬度 leftLng bottomLat
let southWest = { lng: leftLng, lat: bottomLat };
// 右上角 经纬度 rightLng topLat
let northEast = { lng: rightLng, lat: topLat };
let lnglats = { southWest, northEast };
return lnglats;
},
// 第二种算法
/**
* 距离dis的单位是米(默认500M),deg是方位角,需要化为弧度。lon1,lat1是起始点经纬度信息
* 左侧开始,角度0,逆时针方向360度
* long1 + dis*math.sin(deg)/(arc*math.cos(lati1)*2*math.pi/360)
* lati1 + dis*math.cos(deg)/(arc*2*math.pi/360)
*/
getLngLat2(lng, lat, w) {
let arc = 6371.393 * 1000;
let pi = Math.PI;
let num = w ? w / 2 : 500 / 2;
// 中心点-左边点的经纬度
let leftLng =
lng + (num * Math.sin(180)) / ((arc * Math.cos(lat) * 2 * pi) / 360);
// let leftLat = lat;
// 中心点-下边点的经纬度
// let bottomLng = lng;
let bottomLat = lat + (num * Math.cos(270)) / ((arc * 2 * pi) / 360);
// 中心点-右边点经纬度
let rightLng =
lng + (num * Math.sin(0)) / ((arc * Math.cos(lat) * 2 * pi) / 360);
// let rightLat = lat;
// 中心点-上边点经纬度
// let topLng = lng;
let topLat = lat + (num * Math.cos(90)) / ((arc * 2 * pi) / 360);
// 左下角 经纬度 leftLng bottomLat
let southWest = { lng: leftLng, lat: bottomLat };
// 右上角 经纬度 rightLng topLat
let northEast = { lng: rightLng, lat: topLat };
let lnglats = { southWest, northEast };
return lnglats;
},
// 根据地址获取经纬度
getAddressLngLat(address) {
return new Promise((resolve) => {
AMap.plugin("AMap.Geocoder", function () {
var geocoder = new AMap.Geocoder();
geocoder.getLocation(address, function (status, result) {
resolve({ status, result });
});
});
});
},
// 选择区域
async chooseArea() {
let _type = this.menuId;
let o = this.form;
let location = {};
if (_type == 1) {
let address = `${o.name || ""}${o.address || ""}`;
let { status, result } = await this.getAddressLngLat(address);
if (status === "complete" && result.info === "OK") {
// 以解析出来经纬度为中心点来画矩形
let arr = result.geocodes ? result.geocodes : [];
location = arr[0] ? arr[0].location : {};
}
} else {
location = this.location;
}
// 如果location 不存在,则以地图中心点来画矩形
if (!location.lng || !location.lat) {
location = this.map.getCenter();
}
console.log(location);
let lnglats = this.getLngLat(location.lng, location.lat);
console.log(lnglats);
console.log(this.getLngLat2(location.lng, location.lat));
this.drawRectangle(lnglats);
},
// 计算矩形宽度、高度
calculateWidthHeight(lnglats) {
if (!lnglats) {
return {};
}
// 左下角点坐标
let southWest = lnglats.southWest || {};
// 右上角点坐标
let northEast = lnglats.northEast || {};
// 计算高度
let _height = AMap.GeometryUtil.distance(
[southWest.lng, southWest.lat],
[southWest.lng, northEast.lat]
);
// 计算宽度
let _width = AMap.GeometryUtil.distance(
[southWest.lng, southWest.lat],
[northEast.lng, southWest.lat]
);
this.rectangleHeight = _height.toFixed(0);
this.rectangleWidth = _width.toFixed(0);
},
// 清空地图覆盖物
clearMap() {
let rectangle = this.rectangle;
let rectangleEditor = this.rectangleEditor;
if (rectangle || rectangleEditor) {
rectangleEditor.close();
}
if (this.map) {
this.map.clearMap();
}
this.rectangleHeight = 0;
this.rectangleWidth = 0;
this.rectangle = null;
this.rectangleEditor = null;
this.map.setZooms([2, 30]);
},
// 清空筛选条件
onClear() {
this.clearMap();
this.rectangleHeight = 0;
this.rectangleWidth = 0;
this.form = {};
this.deviceList = [];
this.$refs.citySelect.reset();
},
// 展开
unfold() {
let _this = this;
let h = this.bHeight;
let m = Number(this.$refs.map.offsetHeight);
let max = (m * 0.8).toFixed(0);
if (_this.hInterval) {
clearInterval(_this.hInterval);
}
_this.hInterval = setInterval(function () {
if (h >= max) {
clearInterval(_this.hInterval);
return false;
}
h += 30;
_this.bHeight = h;
}, 10);
},
// 收起
packUp() {
let _this = this;
let min = 313;
if (_this.hInterval) {
clearInterval(_this.hInterval);
}
_this.hInterval = setInterval(function () {
let h = _this.bHeight;
if (h <= min) {
clearInterval(_this.hInterval);
return false;
}
h -= 30;
_this.bHeight = h;
}, 10);
},
// 隐藏
onHide() {
this.hideFooter = !this.hideFooter;
},
// 展开
onShow() {
this.hideRowBox = !this.hideRowBox;
},
// 添加位置点
addLocation(row, showInfoWindow) {
let drawData = row;
EventBus.$emit("uiMap.monitor.drawMaker", drawData, showInfoWindow);
},
// 获取参数
getParams() {
if (!this.rectangle) {
return {};
}
let params = {};
let o = this.rectangle.getOptions();
let bounds = o.bounds || {};
params.leftLngLat = `${bounds.southWest.lng},${bounds.southWest.lat}`;
params.rightLngLat = `${bounds.northEast.lng},${bounds.northEast.lat}`;
return params;
},
// 导出excel
async downloadExcel() {
let params = this.getParams();
this.dloading = true;
let res = await GER_REGIONAL_EXPORT(params);
this.dloading = false;
if (res.code != 200) {
showToast({
message: res.message,
});
return false;
}
if (res.data) {
window.location.href = res.data;
}
},
// 监听地区选择
onChange(e) {
console.log(e);
let code = e.code;
let o = e.name;
let str = o[0] + o[1] + o[2];
this.$set(this.form, "name", str);
this.drawDistrict(code);
},
// 切换类型
menuEvent(row) {
this.menuId = row.id;
},
// 设备号查车
async getLocation() {
let params = {};
this.clearMap();
params.sns = this.form.sn;
params.deviceCode = "gps";
let res = await GET_DEVICEINFO_BYSNS(params);
let list = res.data || [];
if (list.length <= 0) {
showToast({
message: "暂无车辆",
});
return false;
}
let arr = [];
list.forEach((item) => {
let o = deepClone(item || {});
let m = o.gpsLocation || {};
o.lng = m.elng;
o.lat = m.elat;
o.address = m.address;
o.type = 2;
o.time = m.dateTime;
o.standNo = item.standNo || item.vin;
o.isSource = item.source;
arr.push(o);
// this.autoOpenLastInfoWindow = true;
// if (this.autoOpenLastInfoWindow) {
// this.autoOpenLastInfoWindow = false;
// }
//this.addLocation(o, this.autoOpenLastInfoWindow);
this.location = o;
});
this.addMarkers(arr);
},
// 区域查车
async getAreaLocation() {
let _this = this;
let params = this.getParams();
if (!_this.rectangle) {
showToast({
message: "请先划定区域",
});
return false;
}
_this.loading = true;
let res = await GER_REGIONAL_SEARCH(params);
_this.loading = false;
if (res.code != 200) {
showToast({
message: res.message,
});
return false;
}
let list = res.data || [];
_this.deviceList = list;
_this.hideFooter = false;
_this.addMarkers(list);
},
// 在地图上画行政区域
drawDistrict(areaCode) {
EventBus.$emit("uiMap.fence.drawDistrict", areaCode);
},
// 添加海量点
addMarkers(arr) {
console.log(arr);
let _this = this;
let markers = [];
let icon = {
type: "image",
image: require("images/icon_car.png"),
size: [24, 15],
anchor: "bottom-center",
};
this.drawDone = false;
var layer = new AMap.LabelsLayer({
zooms: [0, 20],
zIndex: 1000,
collision: false,
});
this.map.add(layer);
for (let i = 0, len = arr.length; i < len; i++) {
let k = arr[i];
let curData = {
position: [k.lng, k.lat],
icon,
//extData: k,
};
let labelMarker = new AMap.LabelMarker(curData);
labelMarker.on("click", function (e) {
console.log(labelMarker.getExtData());
let _position = labelMarker.getExtData();
let infoWindow = mapService.createAraeInfowindow(_position);
infoWindow.open(_this.map);
});
markers.push(labelMarker);
}
layer.add(markers);
console.log("画点结束", new Date().getTime());
this.drawDone = true;
this.map.setFitView();
},
},
};
</script>
<style lang="scss" scoped>
@import "../../assets/scss/zoneCar.scss";
</style>