<template>
	<view class="scenic-detail">
		<zs-skeleton type="scenicDetail" :loading="loading"></zs-skeleton>
		<zs-header :background="background"></zs-header>
		<image class="top-banner" :src="info.defaultPic" mode=""></image>
		
		<view class="content">
			<view class="info">
				<view class="title">
					{{info.scenicName}}
				</view>
				<view class="address-box">
					<view class="province">
						{{info.cityName}}
					</view>
					<view class="address">
						{{info.scenicAddress}}
					</view>
				</view>
				<view class="open-time">
					营业时间：{{info.openTime}}
				</view>
			</view>
			<view class="navigation-box">
				<view class="address">
					{{info.scenicAddress}}
				</view>
				<view class="btn" @click="handleNavigation">
					导航
				</view>
			</view>
			
			<view class="list">
				<view class="item">
					<view class="sub-title">
						<!-- {{item.title}} -->
					</view>
					<view class="ticket-list">
						<view class="ticket-item" :class="[index != info.ticketList.length-1?'border-bottom':'']" v-for="(item,index) in info.ticketList" :key="index">
							<view class="top">
								<view class="title">
									{{item.productName}}
								</view>
								<view class="price-box">
									<view class="unit">
										￥
									</view>
									<view class="price">
										{{item.salePrice}}
									</view>
									<view class="text">
										起
									</view>
								</view>
							</view>
							
							<view class="bottom">
								<view class="left">
								<!-- 	<view class="desc">
										{{i.desc}}
									</view> -->
									<view class="notice-box" @click="handleBuy(item)">
										预定须知
										<image class="more" src="../static/right.png" mode=""></image>
									</view>
								</view>
								<view class="btn" @click="handleBuy(item)">
									立即预订
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			
			<view class="sub-title">
				景区简介
			</view>
			<rich-text class="intro border-bottom" :nodes="info.scenicDescription"></rich-text>
		<!-- 	<view class="intro border-bottom">
				{{info.scenicDescription|| '-'}}
			</view> -->
			
			<view class="sub-title">
				交通信息
			</view>
			<view class="intro">
				{{info.trafficBus || '-'}}
			</view>
			
		</view>
		
		<u-popup :show="show" round="16rpx" mode="bottom" @close="close">
			<view class="popup-title">
				{{info.scenicName}}
			</view>
			<view class="box">
				<template v-if="ticketInfo.drawAddress">
					<view class="sub-title">
						取票地点
					</view>
					<view class="intro">
						{{ticketInfo.drawAddress}}
					</view>
				</template>
				<view class="sub-title">
					入园方式
				</view>
				<view class="intro">
					{{ticketInfo.admissionVoucher.admissionVoucherCode | filterVoucherType}}
				</view>
				<view class="sub-title">
					有效期
				</view>
				<view class="intro">
					{{ticketInfo.indate || '-'}}
				</view>
				<view class="sub-title">
					预定截止
				</view>
				<view class="intro">
					{{ticketInfo.advanceDay}}天 {{ticketInfo.advanceHour}}小时
				</view>
				<view class="sub-title">
					退改规则
				</view>
				<rich-text class="intro" :nodes="ticketInfo.mpLossInfo"></rich-text>
				<view class="sub-title">
					预定须知
				</view>
				<rich-text class="intro" :nodes="ticketInfo.bookNotice"></rich-text>
				<view class="sub-title">
					其他说明
				</view>
				<rich-text class="intro" :nodes="ticketInfo.info"></rich-text>
				
				<!-- <template v-for="item in info.bookNotice">
					<view class="sub-title">
						{{item.name}}
					</view>
					<rich-text class="intro" :nodes="item.value"></rich-text>
				</template> -->
				
			</view>
				<view class="btn-box">
					<view class="left">
						<view class="num">
							共1件
						</view>
						<view class="total">
							合计 <view class="price-box">
								<view class="unit">
									￥
								</view>
								<view class="price">
									{{total}}
								</view>
							</view>
						</view>
					</view>
					<view class="buy-btn" @click="handleBtn">
						立即预订
					</view>
				</view>
		</u-popup>
		
		<map class="map" id="map"></map>
	</view>
</template>

<script>
	import {getScenicDetail,getTicketDetail} from '@/api/scenic.js'
	export default {
		data() {
			return {
				show:false,
				background: false,
				loading:false,
				map:null,
				total:0,
				info:{
					"scenicName": "",
					"glocation": "",
					"scenicId": 0,
					"recommend": "",
					"scenicDescription": "",
					"scenicAddress": "",
					"trafficBus": "",
					"bookNotice": "",
					"cityName": "",
					"blocation": "",
					 "defaultPic": "",
					"provinceName": "",
					"openTime": "",
					"disTickets": []
				},
				ticketInfo:{},
				scenicId:0,
				epId:''
			}
		},
		filters: {
			filterVoucherType: function(val) {
				if(val == 1){
					return '实体票入园'
				}else if(val == 201){
					return '换票入园短信'
				}else if(val == 202){
					return '换票入园二维码'
				}else if(val == 203){
					return '换票入园数字码'
				}else if(val == 204){
					return '换票入园换票证'
				}else if(val == 205){
					return '换票入园邮件'
				}else if(val == 206){
					return '换票入园身份证'
				}else if(val == 207){
					return '换票入园护照'
				}else if(val == 208){
					return '换票入园港澳通行证'
				}else if(val == 209){
					return '换票入园军官证'
				}else if(val == 210){
					return '换票入园台胞证'
				}else if(val == 301){
					return '直接验证入园二维码'
				}else if(val == 302){
					return '直接验证入园邮件'
				}else if(val == 303){
					return '直接验证入园身份证'
				}else if(val == 304){
					return '直接验证入园护照'
				}else if(val == 305){
					return '直接验证入园港澳通行证'
				}else if(val == 306){
					return '直接验证入园军官证'
				}else if(val == 307){
					return '直接验证入园台胞证'
				}
			}
		},
		methods: {
			close(){
				this.show = false
			},
			handleBuy(item){
				console.log(item);
				this.show = true
				this.total = item.salePrice
				this.getTicketDetail(item.productId)
			},
			handleNavigation() {
				let blocation = this.info.glocation.split(',')
				console.log(blocation);
				uni.openLocation({
					latitude: Number(blocation[0]) ,
					longitude: Number(blocation[1]),
					name:this.info.scenicName,
					address:this.info.scenicAddress,
					success: function () {
						console.log('success');
					}
				});
			},
			handleBtn(){
				let that = this
				uni.navigateTo({
					url:'/scenic/makeOut?id='+this.scenicId,
					success: function(res) {
					  // 通过eventChannel向被打开页面传送数据
					  let obj = that.ticketInfo
					  obj.epId = that.epId
					  obj.shopName = that.info.scenicName
					  res.eventChannel.emit('pay', obj)
					}
				})
			},
			getScenicDetail(scenicId){
				this.loading = true
				getScenicDetail({scenicId}).then(res=>{
					this.loading = false
					if(res.state == 'Success'){
						this.info = res.content.data
						this.info.bookNotice = JSON.parse(this.info.bookNotice)
						this.info.scenicDescription = this.info.scenicDescription.replace(/<img/gi, '<img class="img_class" ')
						console.log(this.info.bookNotice);
					}
				})
			},
			getTicketDetail(productId){
				getTicketDetail({productId}).then(res=>{
					if(res.state == 'Success'){
						this.ticketInfo = res.content.data
						this.ticketInfo.mpLossInfo = this.ticketInfo.mpLossInfo.replace(/\n/g, "<br>")
						this.ticketInfo.info = this.ticketInfo.info.replace(/\n/g, "<br>")
						this.ticketInfo.bookNotice = this.ticketInfo.bookNotice.replace(/\n/g, "<br>")
					}
				})
			},
			
		},
		onPageScroll(e) {
			if (e.scrollTop >= 50) {
				this.background = true
			} else {
				this.background = false
			}
		},
		onReady() {
			this.map = uni.createMapContext("map", this);
		},
		onLoad(options) {
			this.getScenicDetail(options.id)
			this.scenicId = options.id
			this.epId = options.epId
		}
	}
</script>

<style lang="scss" >
.scenic-detail{
	.img_class{
		max-width: 100% !important;
	}
	.top-banner{
		width: 750rpx;
		height: 382rpx;
		vertical-align: bottom;
	}
	.map{
		position: absolute;
		top: -9999rpx;
		left: -9999rpx;
	}
	.content{
		position: relative;
		top: -20rpx;
		z-index: 2;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		padding: 28rpx 24rpx;
		.info{
			.title{
				font-weight: 600;
				font-size: 32rpx;
				color: #222222;
			}
			.address-box{
				display: flex;
				align-items: center;
				font-weight: 300;
				font-size: 24rpx;
				color: #AAAAAA;
				margin-top: 26rpx;
				.province{
					padding-right: 12rpx;
					border-right: 2rpx solid #F0F0F0;
				}
			}
			.open-time{
				font-weight: 300;
				font-size: 24rpx;
				color: #AAAAAA;
				margin-top: 20rpx;
			}
		}
		.navigation-box{
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 702rpx;
			height: 140rpx;
			background-image: url('../static/white-map.png');
			background-repeat: repeat;
			background-size: 100% 140rpx;
			// background: linear-gradient( 101deg, rgba(246,246,246,0.89) 0%, #FFFFFF 100%);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 0 24rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			.address{
				font-weight: 600;
				font-size: 24rpx;
				color: #222222;
				width: 490rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
			.btn{
				width: 120rpx;
				height: 52rpx;
				line-height: 52rpx;
				text-align: center;
				background: #E2ECFF;
				border-radius: 26rpx 26rpx 26rpx 26rpx;
				font-weight: 300;
				font-size: 28rpx;
				color: #3879F9;
			}
		}
		.sub-title{
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
			margin: 20rpx 0;
		}
		.intro{
			font-weight: 300;
			font-size: 24rpx;
			color: #AAAAAA;
			line-height: 40rpx;
			padding-bottom: 24rpx;
		}
		.border-bottom{
			border-bottom: 1rpx solid #F0F0F0!important;
		}
		
		.list{
			.item{
				.ticket-list{
					background: #F9F9F9;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					padding: 0 24rpx;
					
					.ticket-item{
						padding: 28rpx 0;
						.top{
							display: flex;
							align-items: center;
							justify-content: space-between;
							.title{
								font-weight: 400;
								font-size: 28rpx;
								color: #222222;
								overflow: hidden;
								text-overflow: ellipsis;
								/* 弹性伸缩盒子模型显示 */
								display: -webkit-box;
								/* 限制在一个块元素显示的文本的行数 */
								-webkit-line-clamp: 2;
								/* 设置或检索伸缩盒对象的子元素的排列方式 */
								-webkit-box-orient: vertical;
							}
							.price-box{
								display: flex;
								align-items: flex-end;
								margin-top: 12rpx;
								.unit{
									font-weight: 600;
									font-size: 20rpx;
									color: $uni-color-primary;
								}
								.price{
									font-weight: 600;
									font-size: 32rpx;
									color: $uni-color-primary;
								}
								.text{
									font-weight: 300;
									font-size: 24rpx;
									color: #AAAAAA;
									margin-left: 6rpx;
								}
							}
						}
						.bottom{
							display: flex;
							align-items: center;
							justify-content: space-between;
							margin-top: 20rpx;
							.left{
								display: flex;
								align-items: center;
								font-weight: 300;
								font-size: 24rpx;
								color: #AAAAAA;
								.notice-box{
									display: flex;
									align-items: center;
									.more{
										width: 48rpx;
										height: 48rpx;
									}
								}
							}
							.btn{
								width: 120rpx;
								height: 52rpx;
								line-height: 52rpx;
								text-align: center;
								background: #EE4320;
								border-radius: 26rpx 26rpx 26rpx 26rpx;
								font-weight: 400;
								font-size: 24rpx;
								color: #FFFFFF;
							}
						}
					}
				}
			}
		}
	}
	.u-popup__content{
		padding: 0 24rpx 28rpx;
		position: relative;
		.popup-title{
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
			padding: 28rpx 0;
			border-bottom: 1rpx solid #F0F0F0;
		}
		.box{
			max-height: 70vh;
			overflow: auto;
			.sub-title{
				font-weight: 600;
				font-size: 28rpx;
				color: #222222;
				margin: 20rpx 0;
			}
			.intro{
				font-weight: 300;
				font-size: 24rpx;
				color: #AAAAAA;
				line-height: 40rpx;
				padding-bottom: 24rpx;
			}
			.border-bottom{
				border-bottom: 1rpx solid #F0F0F0!important;
			}
		}
		.btn-box{
			// position: absolute;
			left: 0%;
			bottom: env(safe-area-inset-bottom);
			width: 100%;
			padding: 10rpx 24rpx;
			box-sizing: border-box;
			border-top: 1rpx solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.left{
				display: flex;
				align-items: flex-end;
				.num{
					font-weight: 300;
					font-size: 24rpx;
					color: #AAAAAA;
				}
				.total{
					font-weight: 300;
					font-size: 24rpx;
					color: #222222;
					display: flex;
					align-items: flex-end;
					margin-left: 6rpx;
					.price-box{
						display: flex;
						align-items: flex-end;
						font-weight: 400;
						font-size: 32rpx;
						color: #222222;
						.unit{
							font-size: 20rpx;
						}
						.price{
							font-weight: bold;
						}
					}
				}
			}
			.buy-btn{
				width: 240rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				background: #EE4320;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				font-weight: 600;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}
}
</style>