<template>
	<view class="container">
		<view class="header">
			<view class="now-location">
				<u-icon name="map" size="36" class="icon"></u-icon>
				<text class="text Medium title">{{address}}</text>
			</view>
			<view class="selectType">
				<text @click="selectType" class="header-type Regular">{{typeStr}}</text>
				<!-- 				<u-icon :style="{transform:(showType?'rotate(180deg)':'')}" name="arrow-down-fill" size="8"
					color="#AFB3BF" class="icon"></u-icon> -->
			</view>
		</view>
		<view class="uni-common-mt">
			<view class="content">
				<map class="map" @markertap="markertap" :latitude="nowLocation.latitude"
					:longitude="nowLocation.longitude" :markers="covers" :enable-poi="true">
				</map>
			</view>
		</view>
		<view class="alert">
			<view class="select-alert" v-if="showType">
				<view class="select-top">
					<text class="cancel" @click="cancel">取消</text>
					<text class="confirm" @click="confirm">确定</text>
				</view>
				<view class="select">
					<text class="select-item" v-for="(item,index) in typeList" :key="index">
						{{item.name}}
					</text>
				</view>
			</view>
		</view>

		<view class="content2">
			<view class="no-enterprise Regular" v-if="enterpriseList.length!=0">
				附近暂无相关企业
			</view>
			<view class="warp">
				<view class="top-line"></view>
				<view class="bottom-list-item">
					<view class="left"><img src="../../../static/img/location.png" alt=""></view>
					<view class="middle">
						<view class="title Medium">中天昊元粮库中天昊元粮库</view>
						<view class="location Regular">辽宁省营口市鲅鱼圈区xx路108号</view>
					</view>
					<view class="line"></view>
					<view class="right">
						<view class="top">
							<img src="../../../static/img/location.png" alt="">
						</view>
						<view class="bottom Regular">500m</view>
					</view>
				</view>
				<view class="bottom-list-item">
					<view class="left"><img src="../../../static/img/location.png" alt=""></view>
					<view class="middle">
						<view class="title Medium">中天昊元粮库中天昊元粮库</view>
						<view class="location Regular">辽宁省营口市鲅鱼圈区xx路108号</view>
					</view>
					<view class="line"></view>
					<view class="right">
						<view class="top">
							<img src="../../../static/img/location.png" alt="">
						</view>
						<view class="bottom Regular">500m</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>
<script>
	// import amap from '@/js_sdk/js-amap/amap-wx.130.js'
	export default {
		data() {
			return {
				address: {},
				nowLocation: {
					longitude: '',
					latitude: ''
				},
				showType: false,
				enterpriseList: [],
				typeStr: '全部类型',
				typeList: [{
						name: "全部"
					},
					{
						name: "粮库"
					},
					{
						name: "加工厂"
					}
				],
				title: 'map',
				latitude: 39.909,
				longitude: 116.39742,
				covers: [{
					id: 0,
					latitude: 39.9085,
					longitude: 116.39747,
					iconPath: '../../../static/img/location.png',
				}]
			}
		},
		onShow() {

		},
		onLoad() {
			//获取当前位置
			this.getLocation()
			// var subnvue = uni.getSubNVueById('popup') // 获取nvue
			// 	subnvue.show()  // 显示nvue
			// uni.$on('popup', (data) => {
			// 	console.log(data)
			// })  
		},
		methods: {
			confirm() {
				console.log('确定')
				this.showType = false
			},
			cancel() {
				console.log('取消')
				this.showType = false
			},
			selectType() {
				this.showType = true
				console.log(1)
			},
			typeConfirm(e) {
				console.log(e)
				this.typeStr = this.typeList[e[0]].name

			},
			getLocation() {
				let that = this;
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						that.nowLocation.longitude = res.longitude
						that.nowLocation.latitude = res.latitude
						that.covers[0].longitude = res.longitude
						that.covers[0].latitude = res.latitude
						let _coverrsData = []
						for (let i = 0; i < 50; i++) {
							let _obj = {
								id: i,
								latitude: res.latitude += 0.00150,
								longitude: res.longitude + 0.00150,
								iconPath: '../../../static/img/location.png',
								width:30,
								height:30,
								callout: {
									content: '中天昊元粮库',
									color: '#333333',
									fontSize: 24,
									borderRadius: 20,
									padding:10,
									bgColor: 'white',
									display: 'ALWAYS',
								},
							}
							_coverrsData.push(_obj)
						}
						that.covers = _coverrsData
						console.log('获取位置数据：', res);
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						//拼接当前定位回显地址
						let _address = res.address

						that.address = _address.province + _address.city + _address.district + _address.poiName
						console.log(that.address)
					}
				});
			},
			markertap(e) {
				console.log(e)
				uni.showToast({
					title: "点击id为" + e.detail.markerId + "的坐标",
					icon: 'none',
					duration: 2000
				})
			}

		}
	}
</script>
<style scoped>
	.header {
		flex-direction: row;
		justify-content: space-between;
		margin-bottom: 20rpx;
		padding: 20rpx;
	}

	.title {
		font-size: 32rpx;
	}

	.content {
		width: 750px;
		flex: 1;
	}

	.map {
		height: 1350rpx;
	}

	.content2 {
		position: fixed;
		bottom: 0;
		width: 750rpx;
		flex: 1;
		font-size: 34px;
		background: pink;
	}

	.header-type {
		font-size: 26rpx;
	}

	.alert {
		flex: 1;
	}

	.select-alert {
		background-color: green;
		position: fixed;
		bottom: 0;
		width: 750rpx;
		flex: 1;
	}

	.select-top {
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
		background: yellow;
		height: 80rpx;
	}


	.select {
		width: 750rpx;
		flex: 1;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background: white;
	}
	.cancel{
		font-size: 24rpx;
		color: white;
		font-weight: bold;
	}
	.confirm{
		font-size: 24rpx;
		color: green;
		font-weight: bold;
	}
	.select-item{
		font-size: 24rpx;
	}
</style>
