<template>
	<view class="safety" id="container">
		<map style="width: 100%; height: 75%;" :latitude="latitude" :longitude="longitude" scale="10"  
			:markers="markers" :show-location="true" @markertap="markertap">
		</map>
		<view class="model">
			<view class="info">
				<image class="img" src="/static/logo9.png"></image>
				<view class="info-data">
					<view class="info-title">名称：{{model.shopsName ? model.shopsName : '-'}}</view>
					<view class="info-text">电话：{{model.shopsTel ? model.shopsTel : '-'}}</view>
					<view class="info-shopsIntroduce">地址：{{model.shopsAddress ? model.shopsAddress : '-'}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import amap from '@/lib/amap-wx.130.js'
	import server from "@/api/index";
	import http from '@/common/http.js'
	export default {
		data() {
			return {
				pageNo: 1,
				pageSize: 10,
				id: 0,
				clickable: true,
				latitude: 43.616996,
				longitude: 125.323643,
				mapKey: '1dc63f21c12985e199a715faf4c02f36',
				markers: [],
				list: [],
				model:{
					shopsName: '',
					shopsTel: '',
					shopsPic: '',
					shopsAddress: ''
				}
			}
		},
		onLoad() {
			let that = this;
			this.amapPlugin = new amap.AMapWX({
				key: this.mapKey //该key 是在高德中申请的微信小程序key
			});
			this.amapPlugin.getRegeo({
				type: 'gcj02', //map 组件使用的经纬度是国测局坐标， type 为 gcj02
				success: function(res) {
					const latitude = res[0].latitude;
					const longitude = res[0].longitude;
					that.longitude = longitude;
					that.latitude = latitude;
					console.log(that.longitude, that.latitude)
					that.mapInfo = res[0];
				},
				fail: (res) => {
					console.log(JSON.stringify(res));
				}
			});
			this.getFn()
		},
		methods: {
			image(e) {
				return http.webUrl + e
			},
			getFn() {
				server.getServiceList().then(res =>{
					res.forEach((item, index) => {
						this.markers.push({
							id: item.id,
							latitude: item.latitude,
							longitude: item.longitude,
							iconPath: '../../../../static/logo3.png',
							width: 24,
							height: 24,
							clickable: true,
							shopsName: item.name,
							shopsTel: item.phone,
							shopsAddress: item.position
						})
					})
					if (this.markers[0]) {
						this.model.shopsName = this.markers[0].shopsName
						this.model.shopsTel = this.markers[0].shopsTel
						this.model.shopsAddress = this.markers[0].shopsAddress
					}
				})
			},
			markertap(e) {
				this.markers.forEach(item => {
					if (e.detail.markerId === item.id) {
						this.model.shopsName = item.shopsName
						this.model.shopsTel = item.shopsTel
						this.model.shopsAddress = item.shopsAddress
					}
				})
			
			}
		}
	}
</script>

<style lang="scss" scoped>
	.safety {
		position: absolute;
		width: 100%;
		height: 100%;
		box-sizing: border-box;
	}
	.model {
		width: 100%;
		height: 25%;
		position: absolute;
		left: 0upx;
		bottom: 0upx;
		background-color: #FFFFFF;
		z-index: 9999;
		padding: 0rpx 30rpx;
		.info {
			width: 100%;
			height: 100%;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			.img{
				width: 180rpx;
				height: 200rpx;
			}
			.info-data{
				width: calc(100% - 180rpx);
				padding-left: 20upx;
				
			}
			.info-title{
			}
			.info-text{
				padding-top: 10upx;
			}
			.info-shopsIntroduce{
				padding-top: 10upx;
				line-height: 40rpx;
				height: auto;
				overflow: visible;
			}
		}
	}
</style>
