<template>
	<view class="content">
		<view class="bg-box">
			<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/71014b69fdcc4b56ae2a84bdc28f11c3.png"></image>
			<view class="title-box">
				<view class="title">
					{{item.name}}
				</view>
			</view>
		</view>
		
		<view class="cont">
			<view class="msg-box">
				<view class="msg">{{item.msg}}</view>
			</view>
			<view class="line"></view>
			<view class="desc-box">
				<view class="desc" v-html="item.descs"> </view>
			</view>
			<view class="btn-box">
				<view class="btn" @click="navTo('/pages/article/test?tempId='+item.tempId)">立即开始测试</view>
				<view class="btn share" @click="doShare()">邀请好友测试</view>
			</view>
			<view class="logo">
				<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/b95950e4208c493d8b74ce0de220c65c.png"></image>
			</view>
		</view>
		
		<!-- 分享弹窗 -->
		<u-popup :show="showShare" @close="showShare = false" >
			<share-box :shareItem="shareItem"  @closeShare='showShare = false' ></share-box>
		</u-popup>
		
	</view> 
</template>

<script>
	import {getTestDetails} from '@/api/test.js'
	export default {
		data() {
			return {
				tempId:null,
				item:{},
				showShare:false,
				shareItem:{ imageUrl:"",title:"",path:"",isMini:true },
			};
		},
		onLoad(option) {
			this.tempId=option.tempId;
		},
		onUnload() {
		    //this.handleBeforeUnload();
			
		},
		onHide(){
		   //this.handleBeforeUnload();
		},
		mounted() {
		    document.addEventListener('visibilitychange', this.handleVisibilityChange);
		},
		beforeDestroy() {
		    document.removeEventListener('visibilitychange', this.handleVisibilityChange);
		},
		
		onShow() {
			if(!this.$isLogin()) {
				uni.navigateTo({
					url: '/pages/auth/loginIndex'
				})
				return
			}
			this.getTestDetails();
		},
		//发送给朋友
		onShareAppMessage(res) {
			if(this.$isLogin()){
				return {
					title: "健康自测",
					path: '/pages_index/testDetails?tempId='+this.tempId,
					imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20230106/6b459adfb1004c1a96219bcdf07e337c.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
				}
			}
		},
		//分享到朋友圈
		onShareTimeline(res) {
			if(this.$isLogin()){
				return {
					title: "健康自测",
					path: '/pages_index/testDetails?tempId='+this.tempId,
					imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20230106/6b459adfb1004c1a96219bcdf07e337c.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
				}
			}
			
		},
		methods:{
			handleVisibilityChange(){
				if (document.visibilityState === 'hidden') {    // 用户正在离开页面
					  console.log("handleBeforeUnload 退出onaLod");
					  uni.showToast({title:"退出onaLod",icon:'none',duration:3000 });
				}
			},
			navTo(url) {
				if(!this.$isLogin()){
					uni.navigateTo({
						url: '/pages/auth/loginIndex'
					})
					return;
				}
				uni.navigateTo({
					url: url
				});
			},
			getTestDetails(){
				let data = {tempId:this.tempId};
				getTestDetails(data).then(
					res => {
						if(res.code==200){
							this.item=res.data;
							uni.setNavigationBarTitle({
							      title: this.item.name+"自测"
							});
							 
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			doShare(){
				//#ifdef APP-PLUS
				this.shareItem.title= "健康自测";
				this.shareItem.imageUrl="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/71014b69fdcc4b56ae2a84bdc28f11c3.png";
				this.shareItem.compressImage = 1
				this.shareItem.isMini=true;
				this.shareItem.path='/pages_index/testDetails?tempId='+this.tempId;
				let cdn=uni.getStorageSync('h5Path');
				this.shareItem.url=cdn+'/pages/article/testDetails?tempId='+this.tempId;
				this.showShare=true;
				//#endif 
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		height: 100%;
	}
	.content{
		position: relative;
		height: 100%;
		display: flex;
		flex-direction: column;
		.bg-box{
			position: absolute;
			width: 100%;
			height: 600rpx;
			.title-box{
				top: 50rpx;
				left:50rpx;
				position: absolute;
				
				.title{
					border-radius: 5rpx;
					border: 1rpx solid #fff;
					padding: 20rpx 30rpx;
					font-size: 36rpx;
					font-family: Source Han Sans CN;
					font-weight: bold;
					color: #fff;
				}
				
				
				
			}
			image{
				position: absolute;
				width: 100%;
				height: 100%;
			}
			
		}
		.cont{
			position: relative;
			margin-top: 550rpx;
			z-index: 9999;
			padding: 30rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			background-color: #fff;
			border-radius: 30rpx 30rpx 0rpx 0rpx;
			.msg-box{
				.msg{
					font-size: 36rpx;
					font-family: Source Han Sans CN;
					font-weight: bold;
					color: #111;
				}
			}
			.line{
				margin: 15rpx 0rpx;
				background-color: #F6F6F6;
				height:5rpx;
				width: 100%;
			}
			.desc-box{
				margin-top: 20rpx;
				background: #FFFFFF;
				.desc{
					color: #814E1B;
				}
			}
			.logo{
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 60rpx 0rpx;
				width: 100%;
				image{
					width: 200rpx;
					height:100rpx;
				}
			}
			.btn-box{
				margin-top: 60rpx;
			 	height: 140upx;
			 	width: 100%;
			 	box-sizing: border-box;
			 	display: flex;
				flex-direction: column;
			 	align-items: center;
			 	justify-content: center;
				
			 	.btn{
			 		width: 100%;
			 		height: 88upx;
			 		line-height: 88upx;
			 		text-align: center;
			 		font-size: 34upx;
			 		font-family: PingFang SC;
			 		font-weight: bold;
			 		color: #FFFFFF;
			 		background: #FF5C03;
			 		border-radius: 50upx;
			 	}
				.share{
					color: #FFFFFF;
					background: #2BC7B9;
					margin-top: 20rpx;
				}
			 }
		}
		
		
	}
	 
</style>
