<template>
	<view class="container" :style="'overflow:' + (showPage ? 'hidden' : 'visible')" v-if="info">
		<!-- 顶部轮播图区域 -->
		<swiper indicator-dots indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#fff" circular autoplay :interval="3000" class="swiper">
			<swiper-item v-if="info.show_video">
				<video
					class="video"
					:src="info.show_video"
					id="myVideo"
					:show-fullscreen-btn="false"
					:direction="0"
					@fullscreenchange="fullscreenchange"
					@click="handleClickVideo('myVideo')"
				></video>
			</swiper-item>
			<swiper-item v-for="(item, index) in imgList" :key="index">
				<img class="img" mode="aspectFill" :src="item" @click="handleLookImgs(imgList, index)" />
			</swiper-item>
		</swiper>

		<!-- 周边信息区域 -->
		<view class="info">
			<view class="info_name">{{ info.rname }}</view>
			<view class="info_score">
				<view class="score_msg" @click="goPageInfo">简介</view>
				<img class="score_icon" src="../../static/index/right.png" @click="goPageInfo" />
			</view>
			<view class="info_address">
				<img class="address_icon" src="../../static/index/address.png" />
				<text @click="handleLookAddress">地址：{{ info.radress }}</text>
			</view>
			<view class="info_phone">
				<img class="phone_icon" src="../../static/index/phone3.png" />
				<text @click="handleCallPhone(info.rphone)">联系电话：{{ info.rphone }}</text>
			</view>
		</view>

		<!-- 周边产品区域 -->
		<view class="goods" v-if="goodList.length">
			<view class="goods_title">周边产品</view>
			<!-- 列表区域 -->
			<view class="goods_list">
				<!-- 每一个产品区域 -->
				<view class="item_box" v-for="item in goodList" :key="item.id" @click="handleLookDetail(item)">
					<view class="box_left">
						<view class="left_name">{{ item.product_name }}</view>
						<view class="left_info">产品简介 ></view>
						<view class="left_price">¥{{ item.price }}</view>
					</view>
					<view class="box_right">
						<view class="right_btn">预定</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 查看更多区域 -->
		<view class="more" v-if="showMore" @click="handleShowMore">
			查看更多
			<img class="more_icon" src="../../static/index/down.png" />
		</view>

		<!-- 弹窗区域 -->
		<uv-popup ref="popup" bgColor="none" :safeAreaInsetBottom="false">
			<view class="body_pop">
				<img class="pop_img" mode="aspectFill" :src="info.first_img" />
				<!-- 弹窗关闭图标区域 -->
				<img class="pop_icon" src="../../static/index/close.png" @click="handleClosePop" />
				<view class="pop_name">{{ popInfo.product_name }}</view>

				<view class="pop_desc">
					<mp-html :content="popInfo.product_desc" />
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 滚动穿透控制
			showPage: false,
			goodList: [],
			page: 1,
			rows: 3,
			total: null,
			info: null,
			showMore: true,
			popInfo: null,
			imgList: [],
			// video 上下文 videoContext 对象
			videoContext: null,
			// 是否是全屏状态
			isFullScreen: false
		}
	},
	onLoad(options) {
		this.info = JSON.parse(decodeURIComponent(options.info))
		if (this.info.detail_img) {
			this.imgList = this.info.detail_img.split(',')
		}
		this.getData()
	},
	methods: {
		async getData() {
			const res = await this.$myRequest({
				url: '/mhotel/applistAround_pd.action',
				data: {
					aid: this.info.id,
					page: this.page,
					rows: this.rows
				}
			})
			// console.log(res)
			if (res.code === 200) {
				this.goodList = [...this.goodList, ...res.rows]
				this.total = res.total
				if (this.goodList.length >= this.total) {
					this.showMore = false
				}
			}
		},
		goPageInfo() {
			uni.navigateTo({
				url: `/pages/rimInfo/rimInfo?desc=${this.info.detail}`
			})
		},
		handleLookDetail(item) {
			this.popInfo = item
			this.showPage = true
			this.$refs.popup.open('bottom')
		},
		// 点击弹窗关闭图标回调
		handleClosePop() {
			this.showPage = false
			this.$refs.popup.close()
		},
		handleLookImgs(urls, current) {
			uni.previewImage({
				urls,
				current
			})
		},
		handleLookAddress() {
			let latitude = this.info.jingwei.split(',')[1] * 1
			let longitude = this.info.jingwei.split(',')[0] * 1

			uni.openLocation({
				latitude,
				longitude,
				name: this.info.rname,
				address: this.info.radress,
				success: () => {}
			})
		},
		handleCallPhone(phone) {
			uni.makePhoneCall({
				phoneNumber: phone
			})
		},
		handleShowMore() {
			this.page++
			this.getData()
		},
		// 进入全屏和退出全屏时触发的回调
		fullscreenchange(e) {
			this.isFullScreen = e.detail.fullScreen
		},
		// 点击视频控件时触发的回调
		handleClickVideo(id) {
			this.videoContext = uni.createVideoContext(id)
			if (this.isFullScreen) {
				this.videoContext.pause()
				this.videoContext.exitFullScreen()
			} else {
				this.videoContext.requestFullScreen()
				this.videoContext.play()
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background-color: #fff;

	.swiper {
		width: 100%;
		height: 423rpx;

		.img,
		.video {
			width: 100%;
			height: 100%;
		}
	}

	.info {
		margin-top: 20rpx;
		padding: 0 20rpx;

		.info_name {
			font-size: 34rpx;
			font-weight: bold;
			color: #000000;
		}

		.info_score {
			display: flex;
			align-items: center;
			margin-top: 22rpx;
			font-size: 24rpx;

			.score_left {
				padding: 0 10rpx 0 12rpx;
				line-height: 36rpx;
				color: #fff;
				text-align: center;
				font-weight: bold;
				border-radius: 32rpx 0 0 32rpx;
				background-color: #096562;
			}
			.score_right {
				padding: 0 12rpx 0 10rpx;
				line-height: 36rpx;
				color: #096562;
				text-align: center;
				font-weight: bold;
				border-radius: 0 32rpx 32rpx 0;
				background-color: #dff2f2;
			}
			.score_msg {
				// margin-left: 42rpx;
				color: #096562;
			}

			.score_icon {
				margin-top: 5rpx;
				margin-left: 13rpx;
				width: 10rpx;
				height: 20rpx;
			}
		}

		.info_address {
			display: flex;
			align-items: center;
			margin-top: 24rpx;
			height: 83rpx;
			font-size: 28rpx;
			border-top: 1rpx solid #e6e6e6;

			.address_icon {
				margin-right: 8rpx;
				width: 30rpx;
				height: 30rpx;
			}
		}

		.info_phone {
			display: flex;
			align-items: center;
			height: 83rpx;
			font-size: 28rpx;
			border-top: 1rpx solid #e6e6e6;

			.phone_icon {
				margin-right: 8rpx;
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.goods {
		padding: 0 20rpx;
		border-top: 1rpx solid #cccccc;

		.goods_title {
			margin-top: 30rpx;
			font-size: 32rpx;
			font-weight: bold;
		}

		.goods_list {
			margin-top: 17rpx;

			.item_box {
				display: flex;
				margin-bottom: 20rpx;
				padding: 0 32rpx 0 24rpx;
				height: 170rpx;
				border-radius: 10rpx;
				background-color: #f2f2f2;

				.box_left {
					flex: 2;
					display: flex;
					flex-direction: column;
					justify-content: space-evenly;
					overflow: hidden;

					.left_name {
						font-size: 28rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.left_info {
						color: #808080;
						font-size: 24rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.left_price {
						color: #ff5733;
						font-size: 24rpx;
					}
				}

				.box_right {
					flex: 1;
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.right_btn {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 115rpx;
						height: 60rpx;
						color: #fff;
						font-size: 28rpx;
						border-radius: 10rpx;
						background-color: #ff5733;
					}
				}
			}
		}
	}

	.more {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 20rpx 0 30rpx 0;
		color: #096663;
		font-size: 24rpx;

		.more_icon {
			width: 38rpx;
			height: 48rpx;
		}
	}

	.body_pop {
		position: relative;
		width: 750rpx;
		height: 85vh;
		border-radius: 22rpx 22rpx 0 0;
		background-color: #fff;
		overflow-y: auto;

		.pop_img {
			width: 100%;
			height: 423rpx;
			border-radius: 20rpx 20rpx 0 0;
		}

		.pop_icon {
			position: absolute;
			top: 20rpx;
			right: 30rpx;
			width: 58rpx;
			height: 58rpx;
		}

		.pop_name {
			padding: 0 20rpx;
			line-height: 90rpx;
			font-size: 32rpx;
			font-weight: bold;
		}

		.pop_desc {
			padding: 0 20rpx;
		}
	}
}
</style>
