<template>
	<view class="">
		<uni-popup ref="siteDetailsPopupRef" type="bottom">
			<view class="details-box">

				<view class="details-content" :style="{'height':contentH  +'px' }">
					<template v-if="info">
						<view class="site-info">
							<view class="site-name">{{info.locationName}}</view>
							<view class="site-location">
								{{`${info.provinceName}${info.cityName}${info.areaName}${info.address}`}}
							</view>
							<view class="site-distance">距离{{getDistance(info.distance)}}</view>
							<view class="site-time">
								<text class="time-lable">办公时间</text>
								<text class="site-time-val">{{info.workTimeRemark}}</text>
							</view>
						</view>
						<view class="sever-box" :style="{'height':serveH  +'px' }">
							<siteServe :height="serveH" :mapLocationId="info.mapLocationId" />
						</view>
					</template>
				</view>
				<!-- 		<scroll-view :style="{'height':scrollH  +'px' }" scroll-y="true" :show-scrollbar="false">
					
				</scroll-view> -->
				<view class="details-btn">
					<view class="site-btn" @click.stop="getPhoneCall(info.mapContactList)">
						<svg t="1733972888261" class="icon" viewBox="0 0 1024 1024" version="1.1"
							xmlns="http://www.w3.org/2000/svg" p-id="4331" xmlns:xlink="http://www.w3.org/1999/xlink">
							<path
								d="M575.7 647.1l69.4-69.2 13.3 2.3c1.7 0.3 4.9 0.9 9.4 1.7 7.4 1.3 15.7 2.9 24.6 4.5 25.5 4.8 50.9 9.8 74.8 14.9 17.3 3.7 33.1 7.3 47 10.7 27.6 6.8 47.3 12.9 59.1 18.6 43 20.8 60 65.5 53.4 122-9.7 81.3-97 174.3-204.4 175.4-121 1.2-291.4-87.7-411.9-214.7C165.3 560.4 81.8 406.9 98 278.3c8.5-67.1 40.2-115.9 87.8-147.2 32.4-21.3 69.4-32.5 97.9-34.6 38.2-2.8 69.6 9.6 92.5 38 9.7 12 19.7 36.1 32.2 73.3 3.6 10.9 7.4 22.8 11.3 35.4 7 23 14.1 47.6 20.9 72.2 2.4 8.6 4.5 16.6 6.4 23.7 1.1 4.3 2 7.4 2.4 9.1l3.7 14.2-80.4 81.8c44.5 89 122.6 169.8 203 202.9z m13.5 60l-15.3-5.1c-105.4-35.6-205.4-139.4-256.3-252.3l-7.3-16.2 85-86.4c-1.5-5.6-3.1-11.6-4.9-17.9-6.6-24.1-13.5-48.2-20.4-70.7-3.8-12.3-7.4-23.7-10.9-34.2-10.2-30.5-19.1-52-23.3-57.2-11.8-14.6-26.4-20.4-48.2-18.8-20.2 1.5-48.7 10.1-73.1 26.2-35.2 23.2-58.3 58.6-64.8 110.3-13.8 108.7 63.1 250.2 198.4 392.7C459.5 794.9 617 877 721.8 876c79.2-0.8 146.4-72.5 153.2-129.4 4.3-36.6-4.3-59.4-24.4-69.1-7.5-3.6-24.7-8.9-48.9-14.9-13.4-3.3-28.6-6.8-45.4-10.4-23.3-5-48.4-10-73.5-14.7-7.2-1.3-13.9-2.6-20.1-3.7l-73.5 73.3z"
								p-id="4332">
							</path>
						</svg>
						<text class="site-text">立即联系</text>
					</view>
					<view class="site-btn" @click.stop="openLocation(info)">
						<svg t="1733972953937" class="icon" viewBox="0 0 1024 1024" version="1.1"
							xmlns="http://www.w3.org/2000/svg" p-id="8440" xmlns:xlink="http://www.w3.org/1999/xlink">
							<path
								d="M894.185422 128.023792 129.814578 445.743994 445.99982 577.744353 571.860343 893.929596Z"
								p-id="8441"></path>
						</svg>
						<text class="site-text">一键导航</text>
					</view>
				</view>
			</view>
		</uni-popup>


		<telList ref="telListRef" />
	</view>
</template>

<script>
	// import { EventBus } from "@/utils/vueBus.js"
	import { openMap } from "@/utils/openApp.js"
	import { distanceCalculate } from "@/utils/tool.js";
	import telList from "./telList.vue"
	import siteServe from "./siteServe.vue"
	export default {
		data() {
			return {
				contentH: 0,
				serveH: 0,
				info: null,
			}
		},
		components: { telList, siteServe },
		created() {

		},
		mounted() {



			// EventBus.$on('TianDiTuSite', (res) => {
			// 	const { longitude, latitude } = res;
			// 	this.openDetails(res);
			// });
			// const aaa = {
			// 	"deleteFlag": "NOT_DELETE",
			// 	"createTime": "2024-12-11 16:56:18",
			// 	"createUser": "1543837863788879871",
			// 	"updateTime": "2024-12-18 09:08:07",
			// 	"updateUser": "1543837863788879871",
			// 	"mapLocationId": "1866768964909047810",
			// 	"locationName": "武汉市民之家 出入境办证大厅",
			// 	"mapTypeId": "1867023355423547393",
			// 	"mapTypeName": "市公安政务服务中心",
			// 	"mapTypeIcon": "https://sly-ga-zwserver.obs.cn-north-4.myhuaweicloud.com/2024/12/16/1868630815665283073.png",
			// 	"provinceCode": "420000",
			// 	"provinceName": "湖北省",
			// 	"cityCode": "420100",
			// 	"cityName": "武汉市",
			// 	"areaCode": "420102",
			// 	"areaName": "江岸区",
			// 	"address": "江岸区金桥大道117号",
			// 	"workTimeRemark": "周一至周五：上午9:00-12:00；下午13:30-17:00 周六：上午9:00-12:00；下午13:00-16:00",
			// 	"outerPhone": "12367",
			// 	"mapStatus": "ENABLE",
			// 	"orderIndex": 1,
			// 	"longitude": "114.28986",
			// 	"latitude": "30.66223",
			// 	"centerPoint": false,
			// 	"distance": 0,
			// 	"centerDistance": 50.825090552695464,
			// 	"mapContactList": [{
			// 		"deleteFlag": "NOT_DELETE",
			// 		"createTime": "2024-12-18 09:08:07",
			// 		"createUser": "1543837863788879871",
			// 		"updateTime": null,
			// 		"updateUser": null,
			// 		"mapContactsId": "1869187854787371009",
			// 		"phone": "12367",
			// 		"remark": null,
			// 		"mapLocationId": "1866768964909047810"
			// 	}]
			// }
			// this.openDetails(aaa)
		},
		beforeDestroy() {
			// EventBus.$off('someEvent'); // 确保在组件销毁前移除事件监听
		},
		watch: {
			contentH: {
				handler(newH) {
					if (newH) {
						const query = uni.createSelectorQuery().in(this);
						query
							.select(".site-info")
							.boundingClientRect((data) => {
								const { height } = data || {};
								const h = this.contentH - height;
								this.serveH = h;
							})
							.exec();
					}
				},

			}
		},
		methods: {

			getDistance(num) {
				return distanceCalculate(num)
			},
			getPhoneCall(tel) {
				this.$refs.telListRef.open({ tel })
			},
			openLocation(info) {
				const { areaCode, cityCode, provinceCode, provinceName, cityName, areaName, address } = info
				const name = `${provinceName}${cityName}${areaName}${address}`;
				const code = areaCode || cityCode || provinceCode
				openMap({ name, code: code, type: "baidu" })
			},
			openDetails(res) {
				this.info = res;
				this.$refs.siteDetailsPopupRef.open()
				this.calculateHeight()
			},
			calculateHeight() {
				this.$nextTick(() => {
					try {
						const query = uni.createSelectorQuery().in(this);
						query
							.select(".details-box")
							.boundingClientRect((data) => {
								if(data){
									this.contentH = data.height - uni.upx2px(150);
								}
							})
							.exec();
					} catch (error) {
						//TODO handle the exception
						const windowHeight = uni.getSystemInfoSync().windowHeight;
						this.contentH = windowHeight * 0.8 - uni.upx2px(150);
					}

					if (!this.contentH) {
						setTimeout(() => {
							this.calculateHeight()
						}, 100)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-popup {
		z-index: 1002;

		.details-box {
			height: 80vh;
			padding: 0 30rpx;
			background-color: #fff;
			border-radius: 20rpx 20rpx 0 0;

			.site-name {
				font-size: 36rpx;
				padding-top: 30rpx;
				padding-bottom: 15rpx;
			}

			.site-location,
			.site-distance {
				padding-top: 10rpx;
				// color: #8e8c8c;
				font-size: 28rpx;
			}

			.site-distance {
				color: #7D7D7D;
			}

			.site-time {
				margin-top: 15rpx;
				background-color: #fff;
				border-top: 1rpx solid #F0F0F0;
				padding: 15rpx 0;
				display: flex;
				justify-content: space-between;
				font-size: 28rpx;

				text {
					flex-shrink: 0;
				}

				.time-lable {
					color: #7D7D7D;
				}

				.site-time-val {
					width: 1rpx;
					flex: 1;
					padding-left: 30rpx;
					// text-align: right;
				}
			}


			.details-btn {
				width: 100%;
				height: 120rpx;
				padding-top: 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				.site-btn {
					width: 260rpx;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #fff;
					border-radius: 10rpx;
					background-color: #3291F8;

					&+.site-btn {
						margin-left: 50rpx;
					}

					.icon {
						width: 50rpx;
						height: 50rpx;

						path {
							fill: #fff;
						}
					}

					.site-text {
						font-size: 30rpx;
						padding-left: 20rpx;
					}
				}
			}
		}



		.sever-box {

			width: 100%;
			// background-color: hotpink;
		}
	}
</style>