<template>
	<view class="hotel-book">
		<!-- 自定义导航栏 -->
		<u-navbar :leftText='title' fixed safeAreaInsetTop :placeholder='true'  :bgColor="bgColor" @leftClick='back'>
		</u-navbar>
		<!-- 背景图 -->
		<view class="hotel-book-img">
			<uni-swiper-dot :mode="mode" :info="info" :current="current1" :dots-styles="dotsStyles">
				<swiper class="swiper-box" @change="change1" circular>
					<swiper-item v-for="(item ,index) in info" :key="index"  v-if="resource_type == 1 ">
						<view class="swiper-item">
							<image style="width: 100%;height:564rpx;" :src="item.img" mode="aspectFill"></image>
						</view>
					</swiper-item>
					<swiper-item  v-if="resource_type == 2 ">
						<view class="swiper-item">
							<video class="baner-video" id="myVideo" ref="myVideo" style="width: 100%; height: 564rpx;"
								:src="video_url" controls :enable-progress-gesture="false">
							</video>
						</view>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>

		<!-- 酒店介绍 -->
		<view class="hotel-content">
			<view class="hotel-content-top">
				<image style="width: 48rpx;height: 48rpx;" src="/static/icon/local01.png" mode=""></image>
				<view class="hotel-content-top-text">
					<text>{{hotelDetail.name}}</text>
				</view>
			</view>
			<view class="hotel-content-introduce">
				<view class="introduce-top">
					<text class="introduce-top-rule1"></text>
					<text style="margin: 0 8rpx;">酒店介绍</text>
					<text class="introduce-top-rule2"></text>
				</view>
				<view class="introduce-btn-text introduce-btn">
					<view>
						<u-parse :content="hotelDetail.details"></u-parse>
					</view>
					
					
				</view>
			</view>

		</view>

		<view class="hotel-btn">
			<view class="hotel-btn-left">
				<view class="hotel-btn-left-text" @click="goIndex">
					<view style="width: 48rpx;height: 48rpx;display: flex;align-items: center;justify-content: center;">
						<image style="width: 40rpx;height: 42rpx;" src="/static/icon/home04.png" mode=""></image>
					</view>
					<text>首页</text>
				</view>
				<view class="hotel-btn-left-text" @click="goJoin">
					<view
						style="width: 48rpx;height: 48rpx; display: flex;align-items: center;justify-content: center; ">
						<image style="width: 52rpx;height: 46rpx;" src="/static/icon/vip02.png" mode=""></image>
					</view>
					<text>会员</text>
				</view>
				<view class="hotel-btn-left-text"  @click="goLocaltion">
					<view style="width: 48rpx;height: 48rpx;display: flex;align-items: center;justify-content: center;">
						<image style=" width: 44rpx;height: 44rpx;" src="/static/icon/home03.png" mode=""></image>
					</view>
					<text>导航</text>
				</view>
			</view>
			<view class="hotel-btn-right" @click="goJump">
				<text>预订</text>
			</view>
		</view>
		<!-- 弹出层/核销码 -->
		<dialogPanel ref="dialogPanel"/>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//用户信息
				admin:'',
				//跳转h5,小程序,其他页面
				jump_type_vip: '',
				jump_config_vip: {},
				//轮播图
				info: [],
				//自定义导航栏
				bgColor: '#fff',
				title: '',
				//酒店id
				hotel_id: '',
				hotelDetail: '',
				jump_type: '',
				jump_config: '',
				resource_type: '',
				video_url: '',
				//指示点显示位置
				dotsStyles: {
					backgroundColor: 'rgba(255, 255, 255, .3)',
					border: '1px rgba(255, 255, 255, .3) solid',
					color: '#fff',
					selectedBackgroundColor: 'rgba(255, 255, 255, 1)',
					selectedBorder: '1px rgba(255, 255, 255, 1) solid'
				},
				//指示点显示位置
				current1: 0,
				mode: 'dot',
				hotel:{},
			}
		},
		onReady: function(res) {
			this.videoContext = uni.createVideoContext('myVideo')
		},
		
		onShow() {
			this.admin = this.$store.getters.userInfo
		},

		onLoad(params) {
			if(!this.$store.getters.userInfo){
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
			if (params?.hotel_id) {
				params.address = params.address == 'null' ? "" : params.address;
				this.hotel = params;
				this.hotel_id = params.hotel_id;
				this.getDetail()
			}
			//vip跳转
			this.advise = this.$store.getters.allset.add_member
			this.jump_type_vip = this.advise.value.map_jump_type
			if (this.jump_type_vip == 1) {
				this.jump_config_vip = this.advise.value.map_h5_url
			} else if (this.jump_type_vip == 2) {
				this.jump_config_vip.appid = this.advise.value.map_appid
				this.jump_config_vip.path = this.advise.value.map_path
			} else if (this.jump_type_vip == 3) {
				this.jump_config_vip = this.advise.value.map_other_path
			}
		},
		
		methods: {
			// 切换轮播图指示点
			change1(e) {
				this.current1 = e.detail.current;
			},
			//视频自动播放
			openVideoPlay() {
				this.videoContext.play()
			},
			//返回上一级
			back() {
				const pages = getCurrentPages();
				if (pages.length === 2) {
					uni.navigateBack({
						delta: 1
					});
				} else if (pages.length === 1) {
					uni.switchTab({
						url: '/pages/index/index',
					})
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			//预约跳转
			goJump() {
				if(this.hotelDetail.reserve_jump_type == 3){
					this.$refs.dialogPanel.show(this.hotelDetail.reserve_jump_config);
					return	
				}
				
				this.$utils.jump({
					jump_type: this.hotelDetail.reserve_jump_type,
					jump_config: this.hotelDetail.reserve_jump_config
				})
			},
			//获取酒店详情
			getDetail() {
				this.$api.hotel.getHotelDetail({
					hotel_id: this.hotel_id
				}).then(res => {
					this.hotelDetail = res.data
					this.title = res.data.name
					this.info = JSON.parse(res.data.img_urls).map(item => {
						return {
							img: item
						}
					})
					//跳转h5和小程序
					this.jump_type = res.data.jump_type,
						this.jump_config = res.data.jump_config
					//banner展示视频或者图片
					this.resource_type = res.data.resource_type
					this.video_url = res.data.video_url
					console.log(this.video_url, '--->this.video_url');
					//视频自动播放
					this.openVideoPlay()
				})
			},

			// 跳转其他小程序
			// goJoin() {
			// 	wx.navigateToMiniProgram({
			// 		appId: 'wx255b58f0992b3c53', //appid
			// 		path: 'newUIMain/enrollment/enrollment', //path
			// 		extraData: { //参数
			// 			foo: 'bar'
			// 		},
			// 		// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
			// 		success(res) {
			// 			console.log('成功')
			// 			// 打开成功
			// 		},
			// 		fail(e) {
			// 			console.log(e, '失败')
			// 		}
			// 	})
			// },
			
			// 跳转其他小程序
			goJoin() {
				let _this = this
				this.jumpHAppID(this.jump_type_vip, this.jump_config_vip)
			},
			
			// 跳转其他小程序
			jumpHAppID(id, urls) {
				if (id == 1) {
					const url = urls; // 跳转的外链
					const navtitle = 'H5'; // 这个标题是你自己可以设置的
					uni.navigateTo({
						// 跳转到webview页面
						url: `/pages/webview/webview?url=${url}&nav=${navtitle}`,
						success: () => {
							console.log('成功')
						},
						fail: (e) => {
							console.log(e, "失败")
						}
					});
				} else if (id == 2) {
					let _this = this
					let obj = urls;
					console.log(obj, '----->obj');
					wx.navigateToMiniProgram({
						appId: `${obj.appid}`, //appid
						path: `${obj.path}`, //path
						extraData: { //参数
							foo: 'bar'
						},
						// envVersion: 'develop', //开发版develop 开发版 trial   体验版 release 正式版 
						success(res) {
							let page = '/pages/map/map'
							let user_id = ''
							if (_this.admin != null) {
								user_id = _this.admin.id
							} else {
								user_id = 0
							}
							_this.$api.my.userMemberAdd({
								user_id,
								page,
							}).then(res => {
								console.log(res.data);
							})
							// 打开成功
						},
						fail(e) {
							console.log(e, '失败')
						}
					})
				} else if (id == 3) {
					uni.redirectTo({
						url: urls,
						fail: (err) => {
							uni.reLaunch({
								url: urls
							})
						}
					})
				}
			},
			
			
			
			
			
			// 跳转首页
			goIndex() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			goLocaltion(){
				console.log(this.hotel)
				uni.openLocation({
					type: "gcj02",
					latitude: parseFloat(this.hotel.latitude), // 纬度，浮点数，范围为90 ~ -90
					longitude: parseFloat(this.hotel.longitude), // 经度，浮点数，范围为180 ~ -180。
					scale: 12, // 地图缩放级别,整形值,范围从1~28。默认为最大
					name: this.hotel.name, // 位置名
					address: this.hotel.address, // 地址详情说明
				﻿})
			}
		}
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;

	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.hotel-book {
		height: 100%;
		background: #fff;
	}

	.hotel-book-img {
		height: 564rpx;

		.swiper-box {
			height: 564rpx;
		}
	}

	.hotel-btn {
		padding: 0 30rpx;
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 148rpx;
		background: #FFFFFF;
		box-shadow: 0px -2rpx 20rpx 0px rgba(0, 0, 0, 0.04);
		display: flex;
		align-items: center;
		justify-content: space-between;

		.hotel-btn-left {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.hotel-btn-left-text {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: flex-start;
				font-weight: 500;
				color: #999999;
				font-size: 22rpx;
				margin-right: 48rpx;
			}
		}

		.hotel-btn-right {
			width: 396rpx;
			height: 92rpx;
			background: linear-gradient(270deg, #FF6200 0%, #FF9342 100%);
			border-radius: 12rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			color: #FFFFFF;
			font-size: 30rpx;
		}
	}

	.hotel-content {
		width: 100%;
		padding: 40rpx 30rpx 100rpx;

		.hotel-content-top {
			height: 48rpx;
			display: flex;
			align-items: center;
			justify-content: flex-start;

			.hotel-content-top-text {
				margin-top: -2rpx;
				font-weight: bold;
				color: #333333;
				font-size: 32rpx;
				margin-left: 8rpx;
			}
		}

		.hotel-content-introduce {
			margin-top: 32rpx;
			padding: 48rpx 22rpx;
			background: #FFFFFF;
			border-radius: 4rpx;
			border: 2rpx solid #999999;
			margin-bottom: 100rpx;
		}
	}

	.introduce-top {
		height: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: bold;
		letter-spacing: 2rpx;

		.introduce-top-rule1 {
			width: 56rpx;
			height: 4rpx;
			background: linear-gradient(90deg, #FFFFFF 0%, #D9A94D 100%);
		}

		.introduce-top-rule2 {
			width: 56rpx;
			height: 4rpx;
			background: linear-gradient(-90deg, #FFFFFF 0%, #D9A94D 100%);
		}
	}

	.introduce-btn-text {
		margin-top: 72rpx;
		font-size: 28rpx;
		color: #333;
		font-weight: bold;
		line-height: 56rpx;
	}

	.introduce-btn {
		margin-top: 72rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		color: #101010;
		font-weight: bold;
	}
</style>
