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
<template>
<div class="myMap">
<mt-header title="药具领取">
<router-link to="/" slot="left">
<mt-button icon="back"></mt-button>
</router-link>
</mt-header>
<div id="map-container" class="containerMap"></div>
<div class="scanCode">
<mt-button icon="saoma" type="primary" @click="ScanCode">扫码领取</mt-button>
</div>
<div class="right_item">
<div class="item">
<div class="img" @click="toCollectRecords">
<img src="../assets/img/personal.png"/>
</div>
<label>个人信息</label>
</div>
<div class="item">
<div class="img">
<img src="../assets/img/artificial.png"/>
</div>
<label>人工网点</label>
</div>
<div class="item">
<div class="img" @click="toRealHome">
<img src="../assets/img/homePage.png"/>
</div>
<label>返回首页</label>
</div>
</div>
</div>
</template>
<script>
import AMap from 'AMap';
import {location} from "../utils/mapUtils";
import machinesImg from '../assets/img/machines.png';
import closeImg from '../assets/img/close.png';
import presonImg from '../assets/img/preson.png';
import sharpImg from '../assets/img/sharp.png';
import { MessageBox } from 'mint-ui';
import {getNetworkInfo, getUserReceiveNum} from '../utils/api';
import {callMobile, getQueryVariable} from "../utils/common";
import { Toast } from 'mint-ui';
export default {
name: "myMap",
data() {
return {
recordNum: 0,
jumpHref: {},
lngLat: [],
showMap: false,
machines: []
}
},
created() {
this.urltext()
},
mounted() {
this.createMap();
// 将qrcodeContent方法绑定到window下面,提供给外部调用
document.addEventListener("qrcodeContent",this.subscanQRCallBack);
},
beforeDestroy() {//销毁
document.removeEventListener("qrcodeContent",this.subscanQRCallBack);
},
methods: {
// 接收url后的数据
urltext() {
let mobileToken = getQueryVariable('token')
let userId = getQueryVariable('userId')
let mobilePhone= getQueryVariable('mobile')
let mobileTokenIno = {
token: mobileToken,
userId: userId,
phone: mobilePhone
}
window.sessionStorage.setItem('mobileTokenIno', JSON.stringify(mobileTokenIno))
},
ScanCode() {
callMobile("qrcode", {});
},
async subscanQRCallBack(result){
/*先判断是否有没有回访的领取记录*/
let par = {residentId: 1}//居民id
await getUserReceiveNum(par).then(({data}) => {
this.recordNum = data.data
})
Toast({
message: 'ceshi'+this.recordNum,
position: 'top',
duration: 100000
});
if (this.recordNum = 0) {
this.$router.push({path: `/choiceContraceptives`,query:{info:result}});
} else {
this.$router.push({path: `/returnVisit`,query:{info:result}});
}
},
toCollectRecords() {
this.$router.push({path: `/returnVisit`,query:{info:4}});
// this.$router.push('/collectRecords');
},
toRealHome() {
callMobile("goIndex", {});
},
createMap() {
let geolocation = location.initMap("map-container"); //定位
AMap.event.addListener(geolocation, "complete", result => {
this.lngLat = [result.position.lng, result.position.lat];
getNetworkInfo({latitude:result.position.lat,longitude:result.position.lng}).then(res=>{
if(res.data.code==='SUCCESS'){
this.machines=res.data.data;
this.createSign();
}
})
});
},
createSign() {
// 创建一个机器Icon
let map = location.gatMap();
var machinesIcon = new AMap.Icon({
size: new AMap.Size(25, 50),
image: machinesImg,
imageSize: new AMap.Size(25, 50),
imageOffset: new AMap.Pixel(0, 0)
});
// 创建一个机器Icon
var personIcon = new AMap.Icon({
size: new AMap.Size(40, 40),
image: presonImg,
imageSize: new AMap.Size(32, 32),
imageOffset: new AMap.Pixel(0, 0)
});
let markers = [];
this.machines.forEach(x => {
if(x.netType===0){
let marker = new AMap.Marker({
map: map,
icon: personIcon,
position: [x.netLongitude,x.netLatitude]
});
this.createInfoWindow(map, marker, x);
markers.push(marker);
}else {
let marker = new AMap.Marker({
map: map,
icon: machinesIcon,
position: [x.netLongitude,x.netLatitude]
});
this.createInfoWindow(map, marker, x);
markers.push(marker);
}
});
},
/*为标记绑定弹窗事件*/
createInfoWindow(map, marker, info) {
var infoWindow = new AMap.InfoWindow({ //创建信息窗体
isCustom: true, //使用自定义窗体
content: this.windowStyle(marker, info), //信息窗体的内容可以是任意html片段
offset: new AMap.Pixel(16, -45)
});
var onMarkerClick = function (e) {
infoWindow.open(map, e.target.getPosition());//打开信息窗体
//e.target就是被点击的Marker
}
marker.on('click', onMarkerClick);//绑定click事件
},
/*弹窗样式*/
windowStyle(marker, info) {
let _that = this;
let content = document.createElement("div");
content.className = "custom-info input-card content-window-card";
let top = document.createElement("div");
let titleD = document.createElement("div");
let closeX = document.createElement("img");
top.className = "info-top";
titleD.innerHTML = info.netName;
closeX.src = closeImg;
closeX.onclick = this.closeInfoWindow;
top.appendChild(titleD);
top.appendChild(closeX);
content.appendChild(top);
// 定义中部内容
let middle = document.createElement("div");
middle.className = "info-middle";
middle.innerHTML = "管理员:" + info.netPerson + "</br>联系电话:" + info.netPhone + "</br>" + "地址:" + info.netAddress + "</br>";
let infoButton = document.createElement("input");
infoButton.type = "button";
infoButton.className = "text-button";
infoButton.value = "详情"
infoButton.onclick = function () {
_that.jumpInfo(info)
};
let navigationButton = document.createElement("input");
navigationButton.type = "button";
navigationButton.className = "text-button button-right";
navigationButton.value = "导航"
navigationButton.onclick = function () {
_that.navigation(info)
};
middle.appendChild(infoButton);
middle.appendChild(navigationButton);
content.appendChild(middle);
// 定义底部内容
let bottom = document.createElement("div");
bottom.className = "info-bottom";
bottom.style.position = 'relative';
bottom.style.top = '0px';
bottom.style.margin = '0 auto';
let sharp = document.createElement("img");
sharp.src = sharpImg;
bottom.appendChild(sharp);
content.appendChild(bottom);
return content;
},
/*关闭弹窗*/
closeInfoWindow() {
let map = location.gatMap();
map.clearInfoWindow();
},
navigation(info) {
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid) {
//这个是安卓操作系统
window.location.href="androidamap://viewMap?sourceApplication=appname&poiname="+info.netName+"&lat="+info.netLatitude+"&lon="+info.netLongitude+"&dev=0";
//判断是否切出浏览器
setTimeout(function(){
let hidden = window.document.hidden || window.document.mozHidden || window.document.msHidden ||window.document.webkitHidden
if(typeof hidden =="undefined" || hidden ==false){
//应用宝下载地址
MessageBox('提示', '请下载高德地图进行导航')
}
}, 2500);
}
if (isIOS) {
//这个是ios操作系统
window.location.href="iosamap://viewMap?sourceApplication=appname&poiname="+info.netName+"&lat="+info.netLatitude+"&lon="+info.netLongitude+"&dev=0"
//判断是否切出浏览器
setTimeout(function(){
let hidden = window.document.hidden || window.document.mozHidden || window.document.msHidden ||window.document.webkitHidden
if(typeof hidden =="undefined" || hidden ==false){
//应用宝下载地址
MessageBox('提示', '请下载高德地图进行导航')
}
}, 2500);
}
/*this.$router.push({path: '/navigation', query: {Lng: Lng, Lat: Lat}})*/
},
jumpInfo(info) {
this.$router.push({path: `/siteDetails`,query:{info:JSON.stringify(info)}});
},
},
}
</script>
<style>
.right_item {
position: absolute;
z-index: 2;
right: 15px;
top: 50%
}
.right_item .item .img {
padding: 9px;
width: 36px;
height: 36px;
margin: 0 auto;
border-radius: 1.5rem;
background: white;
}
.right_item .item {
color: #00CA9D;
margin-top: 20px;
}
.myMap {
height: 100%;
margin: 0px;
padding: 0px;
}
.containerMap {
width: 100%;
height: calc(100% - 40px);
margin: 0px;
font-size: 13px;
position: relative;
z-index: 1;
}
.scanCode {
position: fixed;
z-index: 2;
left: calc(50% - 155px);
bottom: 20px;
}
.scanCode .mint-button {
width: 311px;
height: 44px;
background: linear-gradient(242deg, #dff9b9 -27%, #1bd09f 85%);
border-radius: 22px;
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.1);
}
.content-window-card {
position: relative;
box-shadow: none;
bottom: 0;
left: 0;
width: auto;
padding: 0;
}
.content-window-card p {
height: 2rem;
}
.custom-info {
border: solid 1px silver;
}
div.info-top {
position: relative;
background: none repeat scroll 0 0 #F9F9F9;
border-bottom: 1px solid #CCC;
border-radius: 5px 5px 0 0;
}
div.info-top div {
display: inline-block;
color: #333333;
font-size: 14px;
font-weight: bold;
line-height: 31px;
padding: 0 10px;
}
div.info-top img {
position: absolute;
top: 10px;
right: 10px;
transition-duration: 0.25s;
}
div.info-top img:hover {
box-shadow: 0px 0px 5px #000;
}
div.info-middle {
padding: 5px;
width: 196px;
height: 118px;
color: #ffffff;
line-height: 17px;
background: rgba(0, 0, 0, 0.7);;
border-radius: 2px;
}
.input-card {
background-color: transparent !important;
}
div.info-top div {
color: #ffffff;
background: #000000;
}
div.info-top {
background: #000000;
}
div.info-bottom {
height: 0px;
width: 100%;
clear: both;
text-align: center;
}
div.info-bottom img {
position: relative;
z-index: 104;
}
span {
margin-left: 5px;
font-size: 11px;
}
.info-middle img {
float: left;
margin-right: 6px;
}
/*弹窗内按钮样式预留*/
.text-button {
border: 0px;
height: 24px;
width: 60px;
margin-left: 20px;
color: white;
background: #00CA9D;
margin-top: 10px;
opacity: 1;
border-radius: 12px;
}
.button-right {
margin-right: 20px;
float: right;
}
#container {
width: 100%;
height: 100%;
}
#panel {
position: fixed;
background-color: white;
max-height: 90%;
overflow-y: auto;
top: 10px;
right: 10px;
width: 280px;
}
#panel .amap-call {
background-color: #009cf9;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
#panel .amap-lib-walking {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
overflow: hidden;
}
.showMap {
width: 100%;
height: 100%;
}
div.info-top img {
width: 15px;
}
.myMap >>> .pg-navigation .nearby_top_goback {
margin-left: 10px;
width: 0px !important;
height: 0px !important;
}
</style>