<template>
	<view>
		<view class="head-box"></view>
		<uv-navbar autoBack :title="$t('pages_order.lvyou_detail.title')" leftIconColor="#fff" :bgColor="bgColor" height="100rpx" :titleStyle="{color:'#fff'}"></uv-navbar><!-- 旅行详情 -->
		
		<view class="content">
			<view class="content-head">
				
				<uv-swiper :list="travelDetails.travel.image
				&& travelDetails.travel.image.split(',')"
				keyName="image" 
				height="406rpx" radius="30rpx" 
				bgColor="transparent" indicator
				indicatorMode="dot"></uv-swiper>
				
				<!-- <image class="image-box" :src="travelDetails.travel.image" mode="aspectFill"></image> -->
				<view class="msg-box">
					<view class="msg-box-title">{{$ot(travelDetails.travel, 'travel', 'title')}}</view>
					<view class="msg-box-time">{{$t('pages_order.lvyou_detail.start_time')}}{{travelDetails.travel.startTime}}</view><!-- 开始时间： -->
					<view class="lingdui-box">
						<image class="use-img" :src="travelDetails.adminUserInfo.headImage" mode=""></image>
						<view class="lingdui-msg">
							<view class="lingdui-msg-name">
								<view>{{travelDetails.adminUserInfo.nickName}}</view>
								<view class="name-tip">{{$t('pages_order.lvyou_detail.tour_guide')}}</view><!-- 领队 -->
							</view>
							<view>
								<uv-rate :count="count" 
								disabled
								v-model="travelDetails.adminUser.num" size="23" activeColor="#FFA200"></uv-rate>
							</view>
						</view>
						<view class="add-wx" @click="$refs.ewmpopup.open()">{{$t('pages_order.lvyou_detail.add_wechat')}}</view><!-- 添加微信 -->
					</view>
				</view>
			</view>
			
			<view class="iconImages">
				<uv-parse :content="travelDetails.travel.iconImage"></uv-parse>
			</view>
			
			<view class="lv-miaoshu">
				<view class="title-box">{{$t('pages_order.lvyou_detail.travel_description')}}</view><!-- 旅行描述 -->
				<view class="value-box">
					<view class="tabs-box">
						<uv-tabs :list="list" @click="tabsClick" lineColor="#FE5E5E" :activeStyle="{color:'#FE5E5E',fontSize:'29rpx',fontWeight: 'bold'}" :inactiveStyle="{color:'#D6D6D6',fontSize:'29rpx',fontWeight: 'bold'}"></uv-tabs>
					</view>
					<view class="lv-msg-box">
						<uv-parse :content="content"></uv-parse>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="price-box">
				<view class="peice-val"><text>￥</text>{{travelDetails.travel.price}}</view>
				<view>{{$t('pages_order.lvyou_detail.registration_fee')}}</view><!-- 报名费用 -->
			</view>
			<view class="caozuo-box">
				<view class="caozuo-item border-r"
				@click="collect"
				v-if="!isCollect">
					<image src="./static/shoucang-icon.png" 
					mode=""></image>
					<text>{{$t('pages_order.lvyou_detail.collect')}}</text><!-- 收藏 -->
				</view>
				
				<view class="caozuo-item border-r isCollect"
				@click="collect"
				style=""
				v-else>
					<text>{{$t('pages_order.lvyou_detail.collected')}}</text><!-- 已收藏 -->
				</view>
				<button type="primary" style="background-color: transparent;height: 100rpx;font-size: 20rpx;padding: 0;" open-type="share" >
					<view class="caozuo-item">
						<image src="./static/zhuanfa-icon.png" mode=""></image>
						<text style="line-height: initial;">{{$t('pages_order.lvyou_detail.forward')}}</text><!-- 转发 -->
					</view>
				</button>
			</view>
			
			<view class="btn-box" 
			v-if="travelDetails.travel.state == 0"
			@click="toBaoming">{{$t('pages_order.lvyou_detail.sign_up_now')}}</view><!-- 立即报名 -->
			
			<view class="btn-box-2" 
			v-if="travelDetails.travel.state == 1"
			>{{$t('pages_order.lvyou_detail.ended')}}</view><!-- 已结束 -->
		</view>
		<uv-popup ref="ewmpopup" mode="center" round="30rpx">
			<view class="pop-cont">
				<uv-image :src="travelDetails.adminUser.img" width="380rpx" height="380rpx"></uv-image>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				travelDetails: {
					travel : {},
				},
				bgColor:'transparent',
				count:5,
				value:3,
				content:'',
				current:0,
				list:[
					{
						name: this.$t('pages_order.lvyou_detail.tabs.introduction'), // 介绍
						key:'js'
					},
					{
						name: this.$t('pages_order.lvyou_detail.tabs.route'), // 路线
						key:'lx'
					},
					{
						name: this.$t('pages_order.lvyou_detail.tabs.cost'), // 费用
						key:'fy'
					},
					{
						name: this.$t('pages_order.lvyou_detail.tabs.notice'), // 须知
						key:'xz'
					},
					{
						name: this.$t('pages_order.lvyou_detail.tabs.agent'), // 代理
						key:'dl'
					},
				],
				travelId:'',
				isCollect : false,
			}
		},
		onShareAppMessage(res) {
			console.log(res)
			if (res.from === 'button') {
				// 来自详情页页面内分享按
				return {
					title: this.$ot(this.travelDetails.travel, 'travel', 'title'),
					path: `/pages_order/lvyou-detail?travelId=${this.travelId}`,
					imageUrl: this.travelDetails.travel.image,
					success: function(res) {
						// 转发成功
						console.log('转发成功')
					},
					fail: function(res) {
						// 转发失败
					}
				};
			} 
			// 设置转发的参数
			return {
					title: this.$ot(this.travelDetails.travel, 'travel', 'title'),
					path: `/pages_order/lvyou-detail?travelId=${this.travelId}`,
					imageUrl: this.travelDetails.travel.image,
					success: function(res) {
							console.log(res, '发生过是');
							if (res.errMsg == 'shareAppMessage:ok') {
									console.log("成功", res)
							}
					},
					fail: function(res) {
			
							console.log("失败", res)
			
					}
			}
		},
		onPageScroll(e) {
			if(e.scrollTop > 50) {
				this.bgColor = '#49070c'
			}else{
				this.bgColor = 'transparent'
			}
		},
		onLoad({travelId}) {      
			this.travelId = travelId
			this.travelInfo(travelId)
			if(this.isLogin){
				this.$store.commit('getUserInfo')
			}
		},
		methods:{
			toBaoming() {
				
				if(!this.userInfo.nickName ||
				!this.userInfo.headImage || 
				!this.userInfo.phone || 
				!this.userInfo.sex){
					
					uni.showToast({
						title: this.$t('pages_order.lvyou_detail.complete_info_required'), // 请您先完善必要信息
						icon: 'none'
					})
					
					setTimeout(uni.navigateTo, 800, {
						url: '/pages_login/wxUserInfo'
					})
					
					return
				}
				
				this.$api('createOrder',{
					id : this.travelId,
					typePrice : 1,
					type : 1
				}, res=>{
					if(res.code === 200) {
						uni.navigateTo({
							url: '/pages_order/payOrder?id=' + res.result.id
						})
						// uni.requestPaymentWxPay(res)
						// .then(res => {
						// 	uni.showToast({
						// 		title: '下单成功',
						// 		icon: 'none'
						// 	})
							
						// 	setTimeout(uni.switchTab, 800, {
						// 		url: '/pages/index/cart'
						// 	})
						// }).catch(n => {
							
						// })
					}
				})
			},
			collect(){
				this.$api('collect', {
					id : this.travelId,
					type : 1,
				}, res => {
					this.travelInfo(this.travelId)
					if(res.code == 200){
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})
			},
			tabsClick(val) {
				this.current = val.index
				this.content = this.$ot(this.travelDetails.travel, 'travel', this.list[this.current].key)
			},
			travelInfo(travelId) {
				let data = {travelId}
				if(uni.getStorageSync('token')){
					data.token = uni.getStorageSync('token')
				}
				this.$api('travelInfo', data, res=> {
					if(res.code==200) {
						this.travelDetails = res.result
						this.isCollect =  res.result.collect
						this.content = this.$ot(res.result.travel, 'travel', this.list[this.current].key)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #060504;
	}
</style>
<style lang="scss" scoped>
	.pop-cont {
		border-radius: 30rpx;
		padding: 10rpx;
	}
	.head-box {
		background: url('@/static/image/nav-bg.png') no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 534rpx;
		top: 0;
		position: absolute;
		z-index: -1;
	}
	.content {
		margin-top: 40rpx;
		padding: 0 30rpx 170rpx;
		padding-top: calc(var(--status-bar-height) + 110rpx);
		.content-head {
			position: relative;
			.image-box {
				width: 100%;
				border-radius: 20rpx 20rpx 0 0;
				height: 546rpx;
			}
			.msg-box {
				background: #1B1713;
				border-radius: 27rpx 27rpx 67rpx 67rpx;
				position: absolute;
				top: 429rpx;
				left: 0;
				right: 0;
				padding-top: 38rpx;
				.msg-box-title {
					font-weight: 500;
					font-size: 32rpx;
					color: #FFFFFF;
					margin-bottom: 40rpx;
					padding-left: 38rpx;
				}
				.msg-box-time {
					font-weight: 400;
					font-size: 27rpx;
					color: #999999;
					padding-left: 38rpx;
				}
				.lingdui-box {
					margin-top: 43rpx;
					height: 130rpx;
					background: #26201A;
					border-radius: 60rpx;
					display: flex;
					align-items: center;
					padding: 0 40rpx;
					.use-img {
						width: 86rpx;
						height: 86rpx;
						border-radius: 50%;
					}
					.lingdui-msg {
						flex: 1;
						margin-left: 24rpx;
						.lingdui-msg-name {
							font-weight: 500;
							font-size: 29rpx;
							color: #E6E6E6;
							display: flex;
							align-items: center;
							margin-bottom: 11rpx;
							.name-tip {
								padding: 0 20rpx;
								height: 27rpx;
								background: #3C2D17;
								border-radius: 0rpx 12rpx 12rpx 12rpx;
								font-weight: 500;
								font-size: 19rpx;
								color: #FFA200;
								line-height: 27rpx;
								margin-left: 14rpx;
							}
						}
					}
					.add-wx {
						width: 172rpx;
						height: 51rpx;
						background: #3C2D17;
						border-radius: 23rpx 23rpx 23rpx 23rpx;
						text-align: center;
						line-height: 51rpx;
						font-weight: 400;
						font-size: 25rpx;
						color: #FF8A00;
					}
				}
			}
		}
		.title-box {
			font-weight: 500;
			font-size: 33rpx;
			color: #E6E6E6;
			text-align: center;
			position: relative;
			&::after {
				content: "";
				position: absolute;
				top: 50%;
				left: 0;
				transform: translate(0,-50%);
				width: 100%;
				height: 12rpx;
				background: url(@/static/image/home/title-line.png) no-repeat;
				background-size: 100% 100%;
			}
		}
		.iconImages{
			margin-top: 400rpx;
			padding: 20rpx;
		}
		.lv-miaoshu {
			margin-top: 20rpx;
			.value-box {
				background: #1B1713;
				border-radius: 27rpx;
				margin-top: 35rpx;
				.tabs-box {
					border-bottom: 1px solid #2D241B;
				}
				.lv-msg-box {
					padding: 20rpx 40rpx;
					font-weight: 400;
					font-size: 27rpx;
					color: #E6E6E6;
					line-height: 41rpx;
				}
			}
		}
	}
	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 150rpx;
		background-color: #1B1713;
		display: flex;
		align-items: center;
		padding: 0 40rpx;
		.price-box {
			font-weight: 400;
			font-size: 25rpx;
			color: #999999;
			flex: 1;
			.peice-val {
				font-weight: 500;
				font-size: 40rpx;
				color: #FF3535;
				margin-bottom: 15rpx;
				text {
					font-size: 26rpx;
				}
			}
		}
		.caozuo-box {
			display: flex;
			align-items: center;
			.caozuo-item {
				font-weight: 400;
				font-size: 20rpx;
				color: #999999;
				padding: 0 35rpx;
				text-align: center;
				height: 100rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				image {
					width: 48rpx;
					height: 48rpx;
					margin-bottom: 10rpx;
				}
			}
			.border-r {
				position: relative;
				// border-right: 1px solid #4A3E32;
				&::after {
					content: "";
					width: 2rpx;
					height: 47rpx;
					position: absolute;
					right: 0;
					top: 50%;
					transform: translate(0,-50%);
					background-color: #4A3E32;
				}
			}
			.isCollect{
				color: #f40;
				font-size: 28rpx;
				height: 100%;
				display: flex;
				align-items: center;
			}
		}
		.btn-box {
			width: 252rpx;
			height: 74rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 74rpx;
			background: url(@/static/image/home/hdqd-btn.png) no-repeat;
			background-size: 100% 100%;
		}
		.btn-box-2 {
			width: 252rpx;
			height: 74rpx;
			font-weight: 500;
			font-size: 32rpx;
			text-align: center;
			line-height: 74rpx;
			background-size: 100% 100%;
			background: #333;
			color: #999;
			border-radius: 45rpx;
			margin-bottom: 13rpx;
		}
	}
</style>