<template>
	<view class="center">
		<view class="store-info flex">
			<view class="store-top flex">
				<image class="simage" :src="info.image" mode=""></image>
				<view class="stop-main">
					<view class="stop-title">{{ info.name }}</view>
					<view class="stop-address" v-if="info.jl">
						<image class="mrt-image" src="../../static/index/index10.png" mode=""></image>
						<view class="mrt-font">距离{{ info.jl }}KM</view>
					</view>
				</view>
			</view>
		</view>
		<view class="store-item">
			<image class="store-image1" src="../../static/img/store2.png" mode=""></image>
			<view class="store-font">营业时间：{{ info.day_time }}</view>
		</view>
		<view class="store-item">
			<image class="store-image2" src="../../static/img/store3.png" mode=""></image>
			<view class="store-font">商家电话：{{ info.phone }}</view>
		</view>
		<view class="store-item">
			<image class="store-image3" src="../../static/img/store1.png" mode=""></image>
			<view class="store-font">门店地址：{{ info.detailed_address }}</view>
		</view>
		<view class="store-main" v-if="info.slider_image != null">
			<view class="smain-title">门头照片</view>
			<scroll-view class="scroll-box flex" @scroll="scroll" scroll-x="true" :scroll-with-animation="true" scroll-left="10px">
				<view class="scroll-item" v-for="(item, index) in info.slider_image" :key="index"><image class="scroll-image" :src="item" mode="heightFix"></image></view>
			</scroll-view>
		</view>
		<view class="store-main" v-if="info.images != null">
			<view class="smain-title">店内图片</view>
			<scroll-view class="scroll-box flex" @scroll="scroll" scroll-x="true" :scroll-with-animation="true" scroll-left="10px">
				<view class="scroll-item" v-for="(item, index) in info.images" :key="index"><image class="scroll-image" :src="item" mode="heightFix"></image></view>
			</scroll-view>
		</view>
		<view class="btn-box flex">
			<view class="btn-left" @click="tocall()">联系商家</view>
			<view class="btn-right" @click="markertap()">导航到店</view>
		</view>
		<uni-popup ref="popup" type="bottom" @click="close">
			<view class="popup_row">
				<view class="rows">
					<view class="rows-item" @click="toGaodeMap">高德地图</view>
					<view class="rows-item" @click="tobaiDuMap">百度地图</view>
					<!-- <view class="rows-item" @click="totengxunMap">腾讯地图</view> -->
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
import { store_details } from '@/api/index.js';
import uniPopup from '@/components/uni-popup/uni-popup.vue';
export default {
	data() {
		return {
			id: '',
			info: '',
			longitude: '',
			latitude: '',
			latitude1: '',
			longitude1: '',
			address: ''
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.loadData();
	},
	methods: {
		markertap(e) {
			this.$refs.popup.open();
		},
		loadData() {
			const obj = this;
			// store_details({}, this.id).then(({ data }) => {
			// 	console.log(data);
			// 	this.info = data;
			// });
			uni.getLocation({
				type: 'gcj02',
				success: res => {
					console.log('dizhi+++++++++++');
					this.longitude = res.longitude; //经度
					this.latitude = res.latitude; //纬度
					store_details({}, this.id).then(({ data }) => {
						obj.longitude1 = data.longitude;
						obj.latitude1 = data.latitude;
						obj.address = data.detailed_address;
						data.jl = this.getFlatternDistance(this.latitude, this.longitude, data.latitude, data.longitude);
						this.info = data;
					});
				},
				fail: err => {
					console.log(err);
					openMap().then(e => {
						this.getaddress();
					});
				}
			});
		},
		//根据经纬度计算距离
		getFlatternDistance(lat1, lng1, lat2, lng2) {
			let radLat1 = (lat1 * Math.PI) / 180.0;
			let radLat2 = (lat2 * Math.PI) / 180.0;
			let a = radLat1 - radLat2;
			let b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
			let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
			s = s * 6378.137;
			s = Math.round(s * 10000) / 10000;
			return s;
		},
		scroll(e) {
			console.log(e, '123456');
		},
		tocall() {
			let num = this.info.phone;
			console.log(num);
			uni.makePhoneCall({
				phoneNumber: num //仅为示例
			});
		},
		// 调用高德
		toGaodeMap() {
			let latitude = this.latitude1;
			let longitude = this.longitude1;
			let address = this.address;
			console.log('选择高德', latitude, longitude, address);
			window.location.href = `https://uri.amap.com/marker?position=${longitude},${latitude}&name=${address}`;
		},
		// 调用腾讯
		totengxunMap() {
			let latitude = this.latitude1;
			let longitude = this.longitude1;
			let address = this.address;
			console.log('选择腾讯', latitude, longitude);
			window.location.href = `http://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};addr:${address}`;
		},
		// 调用百度
		tobaiDuMap() {
			let latitude = this.latitude1;
			let longitude = this.longitude1;
			let latitude6 = this.latitude;
			let longitude6 = this.longitude;
			let address = this.address;
			console.log('选择百度', latitude, longitude);
			console.log('获取当前经纬度', latitude6, longitude6);
			window.location.href = `http://api.map.baidu.com/direction?origin=latlng:${latitude6},${longitude6}|name:我的位置&destination=${latitude},${longitude}&mode=driving&region=${address}&output=html&src=webapp.baidu.openAPIdemo`;
		}
	}
};
</script>

<style lang="less">
.center,
page {
	background: #f8f8f8;
	height: 100%;
}
.store-info {
	background: #ffffff;
	.store-top {
		padding: 40rpx 20rpx;
		justify-content: flex-start;
		.simage {
			width: 130rpx;
			height: 130rpx;
			background: #f44939;
		}
		.stop-main {
			height: 130rpx;
			padding: 6rpx 0;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: flex-start;
			.stop-title {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #000000;
			}
			.stop-address {
				display: flex;
				justify-content: flex-end;
				align-items: center;

				.mrt-image {
					width: 20rpx;
					height: 28rpx;
				}

				.mrt-font {
					margin-left: 8rpx;
					font-size: 22rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
			}
		}
	}
}
.store-item {
	background: #ffffff;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	padding: 30rpx 30rpx 30rpx 44rpx;
	.store-image1 {
		width: 36rpx;
		height: 36rpx;
	}
	.store-image2 {
		margin: 0 1rpx;
		width: 34rpx;
		height: 34rpx;
	}
	.store-image3 {
		margin: 0 7rpx;
		width: 22rpx;
		height: 28rpx;
	}
	.store-font {
		margin-left: 22rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #2d2d2d;
	}
}
.store-main {
	margin-top: 16rpx;
	background: #ffffff;
	padding: 30rpx 42rpx 40rpx;
	.smain-title {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #464646;
	}
}
.scroll-box {
	white-space: nowrap;
	margin-top: 30rpx;
	height: 240rpx;
	.scroll-item:first-child {
		margin-left: 0;
	}
	.scroll-item {
		margin-left: 20rpx;
		display: inline-block;
		height: 240rpx;
		width: 240rpx;
	}
	.scroll-image {
		height: 240rpx;
		width: 240rpx;
	}
}
.btn-box {
	position: fixed;
	bottom: 0rpx;
	left: 0;
	right: 0;
	width: 750rpx;
	background: rgba(255, 255, 255, 0.6);
	box-shadow: 0rpx 0rpx 20rpx 0px rgba(50, 50, 52, 0.06);
	padding: 22rpx 68rpx;
	.btn-left {
		width: 280rpx;
		height: 80rpx;
		background: linear-gradient(180deg, #ffa30b, #ffd158);
		box-shadow: 0px 3rpx 13rpx 3rpx rgba(255, 164, 13, 0.48);
		border-radius: 40rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
	.btn-right {
		width: 280rpx;
		height: 80rpx;
		background: linear-gradient(180deg, #ff6223, #ffab60);
		box-shadow: 0px 3rpx 13rpx 3rpx rgba(255, 164, 13, 0.48);
		border-radius: 40rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
}
.popup_row {
	width: 100%;
	height: 500rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	display: flex;
	justify-content: center;
	align-items: center;

	.rows {
		width: 100%;
		padding: 0 24rpx;

		.rows-item {
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			width: 100%;
			font-size: 32rpx;
			color: #303133;
			// border-bottom: 1rpx solid #f0f0f0;
		}

		// .row-1 {
		// 	margin: auto;
		// 	.first_aid {
		// 		width: 300rpx;
		// 		height: 300rpx;
		// 	}
		// }
		// .row-2 {
		// 	font-size: 38rpx;
		// 	margin-top: 20rpx;
		// }
	}
}
</style>
