<template>
	<view class="content">
		<iframe id="mapPage" width="100%" height="100%" frameborder=0
		    src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=SOUBZ-3EQWO-FVRWG-SFXV2-O3WYO-VJBMP&referer=myapp">
		</iframe>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				is_true:true,
			}
		},
		onLoad() {

		},   
		
		mounted() {
			this.ReceiveMessage();
		},
		
		onShow(e) {

		},
		
		onReady() {
			// window.addEventListener("message", this.ReceiveMessage);
		},
		
		methods: {
			
			ExchangeJoinArea(loc) {
				this.request({
					url: "exchange/ExchangeJoinArea",
					data: {
						token: uni.getStorageSync("token"),
						is_area_exchange: "Y",
						longitude: loc.latlng.lng,
						latitude: loc.latlng.lat,
						address:loc.poiaddress,
					},
				}).then(res => {
					if (res.code === '200' && res.message == '加入成功') {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						setTimeout(()=>{
							uni.navigateBack();
						},2000)
					}else{
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				}).catch((res) => {
					console.log(res, "res")
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				})
			},
			
		  ReceiveMessage(event) {
			   window.addEventListener('message', (event)=>{
			                  // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
							  
			                  var loc = event.data;
							  
							  // console.log(this.is_true,loc,"this.is_true")
							  
			               if (loc && loc.module == 'locationPicker' && this.is_true) {//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
								this.is_true=false;
								  // console.log(this.is_true,"false")
								this.ExchangeJoinArea(loc)  // 获取的选中的地址数据
			                }
			              return false
			    }, false);
			},

		},
	}

		
</script>

<style>
	page{
		width: 100%;
		height: 100%;
	}
	.content{
		width: 100%;
	height: 100%;
	}
	#mapPage{
		width: 100%;
		height: 100%;
	}
</style>
