<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">
						<image class="mrt-image" src="https://hy.liuniu946.com/app/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="https://hy.liuniu946.com/app/img/store2.png" mode=""></image>
			<view class="store-font">营业时间：{{ info.day_time }}</view>
		</view>
		<view class="store-item" v-if="info.phone">
			<image class="store-image2" src="https://hy.liuniu946.com/app/img/store3.png" mode=""></image>
			<view class="store-font">预约电话：{{ info.phone }}</view>
		</view>
		<view class="store-item">
			<image class="store-image3" src="https://hy.liuniu946.com/app/index/index10.png" mode=""></image>
			<view class="store-font">门店地址：{{ info.detailed_address }}</view>
		</view>
		<view class="store-item">
			<image class="store-image1" src="https://hy.liuniu946.com/app/img/store2.png" mode=""></image>
			<view class="store-font">商家介绍：{{ info.introduction }}</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" @click="openImg(info.slider_image, item)">
					</image>
				</view>
			</scroll-view>
		</view>
		<view class="" style="height: 100rpx;"></view>
		<view class="btn-box flex" v-if="info.phone">
			<view class="btn-left" @click="tocall()">拨打电话</view>

			<!-- #ifdef H5 -->
			<view class="btn-right" @click="toGaodeMap()">导航到店</view>
			<!-- #endif -->
			<!-- #ifdef MP -->
			<view class="btn-right" @click="dh()">导航到店</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="btn-right" @click="gomapApp(info.latitude, info.longitude, info.name)">导航到店</view>
			<!-- #endif -->
		</view>
		<view class="btn-box dhdd flex" v-if="!info.phone">
			<!-- #ifdef H5 -->
			<view class="btn-right" @click="toGaodeMap()">导航到店</view>
			<!-- #endif -->
			<!-- #ifdef MP -->
			<view class="btn-right" @click="dh()">导航到店</view>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<view class="btn-right" @click="gomapApp(info.latitude, info.longitude, info.name)">导航到店</view>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
	import jyfParser from "@/components/jyf-parser/jyf-parser.vue";
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		getVip
	} from '@/api/index.js';
	// #ifdef H5
	import {
		weixindata,
		shareLoad
	} from '@/utils/wxAuthorized';
	// #endif
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		getStoreDetail
	} from '@/api/user.js';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	export default {
		components: {
			uniLoadMore,
			jyfParser
		},
		data() {
			return {
				money: '',
				vipList: [], //商品列表
				page: 1,
				limit: 10,
				loadingType: 'more',
				id: '',
				info: {},
				art: '',
				address: '',
			};
		},
		computed: {
			...mapState(['loginInterceptor', 'baseURL', 'latitude', 'longitude']),
			...mapMutations('user', ['setUserInfo', 'setOrderInfo'])
		},

		onLoad(option) {
			let obj = this;
			this.id = option.id;
			this.getStoreDetail();
		},
		methods: {
			navToDetailPage(item) {
				let id = item.id;
				uni.navigateTo({
					url: '/pages/product/product?id=' + id + '&isVip=' + 8 + '&store_id=' + item.store_id
				});
			},
			cancel() {
				this.money = '';
				this.$refs.popup.close();
			},
			// 获取门店详情
			getStoreDetail() {
				let obj = this;
				console.log('进入');
				getStoreDetail({}, obj.id).then(res => {
					obj.info = res.data.info;
					obj.info.jl = obj.getFlatternDistance(obj.latitude, obj.longitude, obj.info.latitude, obj.info
						.longitude);
				});
			},
			markertap(e) {
				let obj = this;
				// #ifdef H5
				weixindata().then(wxOjb => {
					console.log(wxOjb, '获取微信');
					wxOjb.openLocation({
						latitude: obj.info.latitude, // 纬度，浮点数，范围为90 ~ -90
						longitude: obj.info.longitude, // 经度，浮点数，范围为180 ~ -180。
						name: obj.info.name, // 位置名
						address: obj.info.detailed_address, // 地址详情说明
						scale: 28, // 地图缩放级别,整型值,范围从1~28。默认为最大
						infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转
					});
				});
				// #endif
			},
			//根据经纬度计算距离
			getFlatternDistance(lat1, lng1, lat2, lng2) {
				console.log(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;
				s = s.toFixed(2) * 1;
				return s;
			},
			scroll(e) {
				console.log(e, '123456');
			},
			tocall() {
				let num = this.info.phone;
				console.log(num);
				uni.makePhoneCall({
					phoneNumber: num //仅为示例
				});
			},
			getaddress() {
				console.log('dizhi+++++++++++');

				let obj = this;
				//  #ifndef H5
				uni.getLocation({
					type: 'gcj02',
					success: res => {
						console.log(res, 123456);
						obj.setLat(res.latitude);
						obj.setLon(res.longitude);

						obj.getStoreDetail();
					},
					fail: err => {
						console.log(err, 'shi+++++++++++++++');
						openMap().then(e => {
							this.getaddress();
						});
					}
				});
				// #endif

				// #ifdef H5
				uni.getLocation({
					type: 'wgs84',
					success: res => {
						console.log(res, 123456);
						let wz = obj.wgs84Togcj02(res.longitude, res.latitude);
						obj.setLat(wz[1]);
						obj.setLon(wz[0]);

						obj.getStoreDetail();
					},
					fail: err => {
						console.log(err, 'shi+++++++++++++++');
						openMap().then(e => {
							this.getaddress();
						});
					}
				});
				// weixindata().then(wxOjb => {
				// 	console.log(wxOjb, '获取微信');
				// 	wxOjb.getLocation({
				// 		type: 'gcj02',
				// 		success: res => {
				// 			console.log(res, 123456);
				// 			obj.setLat(res.latitude);
				// 			obj.setLon(res.longitude);
				// 			obj.getStoreDetail();
				// 		},
				// 		fail: err => {
				// 			console.log(err, 'shi+++++++++++++++');
				// 			openMap().then(e => {
				// 				obj.getaddress();
				// 			});
				// 		}
				// 	});
				// });
				// #endif
			},
			wgs84Togcj02(lng, lat) {
				if (this.out_of_china(lng, lat)) {
					return [lng, lat];
				}
				//定义一些常量
				//GCJ02 转换为 WGS84
				var that = this;
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let dlat = that.transformlat(lng - 105.0, lat - 35.0);
				let dlng = that.transformlng(lng - 105.0, lat - 35.0);
				let radlat = (lat / 180.0) * PI;
				let magic = Math.sin(radlat);
				magic = 1 - ee * magic * magic;
				let sqrtmagic = Math.sqrt(magic);
				dlat = (dlat * 180.0) / (((a * (1 - ee)) / (magic * sqrtmagic)) * PI);
				dlng = (dlng * 180.0) / ((a / sqrtmagic) * Math.cos(radlat) * PI);
				var mglat = lat + dlat;
				var mglng = lng + dlng;
				return [mglng, mglat];
			},

			out_of_china(lng, lat) {
				return lng < 72.004 || lng > 137.8347 || (lat < 0.8293 || lat > 55.8271 || false);
			},

			transformlat(lng, lat) {
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(
					lng));
				ret += ((20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0) / 3.0;
				ret += ((20.0 * Math.sin(lat * PI) + 40.0 * Math.sin((lat / 3.0) * PI)) * 2.0) / 3.0;
				ret += ((160.0 * Math.sin((lat / 12.0) * PI) + 320 * Math.sin((lat * PI) / 30.0)) * 2.0) / 3.0;
				return ret;
			},
			transformlng(lng, lat) {
				const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
				const PI = 3.1415926535897932384626;
				const a = 6378245.0;
				const ee = 0.00669342162296594323;
				let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
				ret += ((20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0) / 3.0;
				ret += ((20.0 * Math.sin(lng * PI) + 40.0 * Math.sin((lng / 3.0) * PI)) * 2.0) / 3.0;
				ret += ((150.0 * Math.sin((lng / 12.0) * PI) + 300.0 * Math.sin((lng / 30.0) * PI)) * 2.0) / 3.0;
				return ret;
			},
			//
			openImg(list, item) {
				uni.previewImage({
					current: item,
					urls: list
				});
			},
			// 调用高德
			toGaodeMap() {
				let obj = this;
				window.location.href =
					`https://uri.amap.com/marker?position=${obj.info.longitude},${obj.info.latitude}&name=${obj.info.name}`;
			},
			// 导航
			dh() {
				let obj = this;
				wx.openLocation({
					latitude: obj.info.latitude * 1,
					longitude: obj.info.longitude * 1,
					name: obj.info.name,
					address: obj.info.detailed_address
				});
			},
			gomapApp(latitude, longitude, name) {
				let url = '';
				if (plus.os.name == 'Android') {
					//判断是安卓端
					plus.nativeUI.actionSheet({
							//选择菜单
							title: '选择地图应用',
							cancel: '取消',
							buttons: [{
								title: '腾讯地图'
							}, {
								title: '百度地图'
							}, {
								title: '高德地图'
							}]
						},
						function(e) {
							switch (e.index) {
								//下面是拼接url,不同系统以及不同地图都有不同的拼接字段
								case 1:
									//注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
									url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
									break;
								case 2:
									url =
										`baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
									break;
								case 3:
									url =
										`androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
									break;
								default:
									break;
							}
							if (url != '') {
								url = encodeURI(url);
								//plus.runtime.openURL(url,function(e){})调起手机APP应用
								plus.runtime.openURL(url, function(e) {
									plus.nativeUI.alert('本机未安装指定的地图应用');
								});
							}
						}
					);
				} else {
					// iOS上获取本机是否安装了百度高德地图，需要在manifest里配置
					// 在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加
					//（如urlschemewhitelist:["iosamap","baidumap"]）
					plus.nativeUI.actionSheet({
							title: '选择地图应用',
							cancel: '取消',
							buttons: [{
								title: '腾讯地图'
							}, {
								title: '百度地图'
							}, {
								title: '高德地图'
							}]
						},
						function(e) {
							switch (e.index) {
								case 1:
									url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
									break;
								case 2:
									url =
										`baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
									break;
								case 3:
									url =
										`iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
									break;
								default:
									break;
							}
							if (url != '') {
								url = encodeURI(url);
								plus.runtime.openURL(url, function(e) {
									plus.nativeUI.alert('本机未安装指定的地图应用');
								});
							}
						}
					);
				}
			}
		}
	};
</script>

<style lang="less">
	.center,
	page {
		background: #f8f8f8;
		height: 100%;
	}

	.dhdd {
		view {
			margin: 0 auto;
		}
	}

	.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;
			// }
		}
	}

	.shop-dhq {
		width: 702rpx;
		height: 171rpx;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.15);
		margin: auto;
		border-radius: 20rpx;
		background-color: #fff;
		padding: 0 48rpx 0 26rpx;
		margin-bottom: 20rpx;

		.dhq-left {
			.dhq-name {
				overflow: hidden;
				width: 28%;
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
			}

			.dhq-price {
				padding-top: 20rpx;

				.j-price {
					font-size: 38rpx;
					font-weight: bold;
					color: #ff4c4c;

					&::before {
						content: '￥';
						font-size: 24rpx;
						color: #ff4c4c;
					}
				}

				.j-zk {
					margin: 10rpx;
					display: inline-block;
					margin-left: 10rpx;
					line-height: 32rpx;
					height: 32rpx;
					border: 1px solid #ff4c4c;
					border-radius: 5rpx;
					font-size: 22rpx;
					font-weight: 500;
					color: #ff4c4c;
					padding: 0 8rpx;
				}
			}
		}

		.dhq-right {
			.right-btn {
				width: 105rpx;
				line-height: 56rpx;
				background: linear-gradient(143.2747deg, #ff6a00, #ee0979);
				border: 1rpx solid #ff4c4c;
				border-radius: 27rpx;
				text-align: center;
				color: #fff;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}

	.jx-box-content {
		display: flex;

		.content-left {
			margin: 20rpx 15rpx;
			width: 236rpx;
			height: 236rpx;
			background: #e2e2e2;
			border-radius: 10rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.content-right {
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			.shop-name {
				width: 382rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;

				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
			}

			.shop-content {
				width: 455rpx;
				display: flex;
				justify-content: space-between;

				.shop-content-left {
					display: flex;
					flex-direction: column;

					.price-box {
						display: flex;
						align-items: center;

						.yuan-price {
							font-size: 26rpx;
							font-weight: 500;
							text-decoration: line-through;
							color: #999999;
						}

						image {
							margin: 0 10rpx;
							width: 16rpx;
							height: 18rpx;
						}

						.j-price {
							font-size: 24rpx;
							font-weight: bold;
							color: #b59467;
						}
					}

					.price-x {
						font-size: 36rpx;
						font-weight: bold;
						color: #ff4c4c;
					}
				}

				.shop-content-right {
					margin-top: 20rpx;
					align-items: center;
					text-align: center;
					width: 137rpx;
					height: 52rpx;
					font-size: 26rpx;
					font-weight: 500;
					color: #fff;
					background: #f75022;
					border-radius: 26rpx;
					line-height: 52rpx;
				}
			}
		}
	}

	.main {
		padding: 10rpx;
		display: flex;
		flex-direction: column;
	}

	/deep/ .main {
		.rich-img {
			width: 100% !important;
			height: auto;
		}
	}
</style>