<template>
	<view class="content">
		<view class="cont">
			<view class="bg">
				<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/8e52ab17eabc4534b3ce56026fd5c624.jpg" ></image>
			</view>
			<view class="cont-box" v-if="report!=null">
				<view class="user">
					<image :src="JSON.parse(report.patientJson).avatar==null?'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/22cb9518a55040dea74d8f730551a7a2.jpg':JSON.parse(report.patientJson).avatar"></image>
					<view class="user-box">
						<view class="sex">性别 {{JSON.parse(report.patientJson).sex==1?"男":"女"}}</view>
						<view class="username">年龄 {{JSON.parse(report.patientJson).age}}岁</view>
					</view>
				</view>
				<view class="items">
					
					<view class="result-box">
						<view class="time">检测时间 {{report.createTime}}</view>
						<view class="title">您属于{{report.testResult}}</view>
						<view class="name">{{report.testResult}}</view>
						<!-- <view class="descs">{{report.testResult}}是一种身心和谐的表现，努力保持吧！</view> -->
					</view>
					<view class="item-box" v-for="(item,index) in JSON.parse(report.conditioningPlanJson) ">
						<view class="item">
							<view class="title-box">
								<view class="title">{{item.name}}</view>
								
							</view>
							<view class="descs" >{{item.value}}</view>
							
						</view>
						<view v-if="index<JSON.parse(report.conditioningPlanJson).length-2" class="line"></view>
					</view>
					
				</view>
				<view class="tips">
					注：报告内容仅供参考，具体情况以医生建议为准
				</view>
				<view class="banner" v-if="advImgs.length>0">
					<u-swiper
							:list="advImgs"
							circular
							@click="handleAdvClick"
					></u-swiper>
				</view>
			</view>
		</view>
		<view class="share" @click="shareImg()">
			<text>分享</text>
		</view>
	</view> 
</template>

<script>
	import {getAdvList} from '@/api/adv.js'
	import {getTestReport,getTestReportImg} from '@/api/test.js'
	export default {
		data() {
			return {
				advImgs:[],
				advs:[],
				reportId:null,
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
				report:null,
			};
		},
		onLoad(option) {
			this.reportId=option.reportId;
			this.getTestReport();
		},
		onShow() {
			this.getAdvList();
		},
		methods:{
			shareImg(){
				var data={reportId:this.reportId}
				getTestReportImg(data).then(
					res => {
						if(res.code==200){
							console.log(res)
							wx.downloadFile({
								url: res.img,
								success: (res1) => {
								   console.log(res1)
							     wx.showShareImageMenu({
							       path: res1.tempFilePath
							     })
							   },
							   fail:(res2)=>{
								   console.log(res2)
							   }
							})
						}
					},
					err => {
					}
				);
				
				// uni.navigateTo({
				// 	url: '/pages_index/testResultImg?reportId=' + this.reportId
				// })
			},
			handleAdvClick(index){
				var ad=this.advs[index];
				console.log(ad.advUrl);
				if(ad.showType==1){
					uni.setStorageSync('url',ad.advUrl);
					uni.navigateTo({
						url:"h5"
					})
				}
				else if(ad.showType==2){
					uni.navigateTo({
						url:ad.advUrl
					})
				}
				else if(ad.showType==3){
					 uni.setStorageSync('content',ad.content);
					 uni.navigateTo({
					 	url:"content"
					 })
				}
				
			},
			getAdvList() {
				//联网加载数据
				var that = this;
				var data = {
					advType:3
				};
				getAdvList(data).then(res => {
					if(res.code==200){
						that.advImgs=[];
						that.advs=res.data;
						that.advs.forEach(function(element) {
							if(element.imageUrl!=null&&element.imageUrl!=""){
								that.advImgs.push(element.imageUrl);
							}
						});
						console.log(that.advImgs)
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			getTestReport(){
				var data={reportId:this.reportId}
				getTestReport(data).then(
					res => {
						if(res.code==200){
							this.report=res.report;
						}
					},
					err => {
					}
				);
				
			},
			goBack(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FDF7F0;
		height: 100%;
	}
	.content{
		.cont{
			position: relative;
			width: 100%;
			display: flex;
			flex-direction: column;
			.bg{
				width: 100%;
				height:100%;
				// background-color: #2BC7B9;
				// background: linear-gradient(#2BC7B9, #88e2da);
				position: fixed;
				image{
					width: 100%;
					height:100%;
				}
				z-index: 1;
			}
			.cont-box{
				z-index: 1000;
				margin-top: 88rpx;
				.user{
					width: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					padding: 30rpx;
					image{
						border-radius: 50%;
						border: 2rpx solid #ffffff;
						width:120rpx;
						height:120rpx;
					}
					.user-box{
						padding: 30rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						.sex{
							font-weight: bold;
							font-size: 40supx;
							font-family: PingFang SC;
							color: #925924;
						}
						.username{
							margin-left: 15rpx;
							font-size: 40supx;
							font-family: PingFang SC;
							color: #925924;
						}
						
					}
				}
				.items{
					width: 100%;
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					justify-content: flex-start;
					padding: 20rpx;
					.result-box{
						width: 100%;
						display: flex;
						flex-direction: column;
						align-items:center;
						justify-content: center;
						padding: 30rpx;
						background-color: #fff;
						border-radius: 15rpx;
						margin-bottom: 15rpx;
						.time{
							margin-top: 15rpx;
							font-family: PingFang SC;
							font-size: 24rpx;
							color: #9B9B9B;
						}
						.title{
							margin-top: 15rpx;
							font-family: PingFang SC;
							font-size: 28rpx;
							color: #626468;
							
						}
						.name{
							margin-top: 30rpx;
							font-family: PingFang SC;
							font-weight: bold;
							font-size: 60rpx;
							color: #925924;
						}
						.descs{
							font-family: PingFang SC;
							font-size: 28rpx;
							color: #2A2B2E;
							padding: 30rpx;
							margin-top: 30rpx;
							background-color: #F5F6F6;
							border-radius: 10rpx;
						}
					}
					.item-box{
						width: 100%;
						.item{
							width: 100%;
							padding: 30rpx;
							background-color: #fff;
							border-radius:30rpx;
							.title-box{
								display: flex;
								align-items:center;
								justify-content: flex-start;
								.title{
									margin-left: 10rpx;
									font-size: 32supx;
									font-family: PingFang SC;
									color: #925924;
									font-weight: bold;
								}
								.title-line{
									width: 8rpx;
									height: 28rpx;
									background: #2BC7B9;
									border-radius: 2px 2px 2px 2px;
									opacity: 1;
								}
								
							}
							.descs{
								white-space: pre-line; 
								margin-top: 10rpx;
								font-size: 28supx;
								font-family: PingFang SC;
								color: #2A2B2E;
							}
							
						}
						.line{
							margin: 0rpx 30rpx;
							border-bottom: #b5b5b5 3rpx dashed;
						}
						
					}
				
					
					
				}
				.tips{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					margin: 15rpx 0rpx;
					color: #9B9B9B;
					font-size: 24rpx;
				}
				.banner{
					height:250rpx;
					width: 100%;
					padding: 15rpx 20upx;
				 
				}
			}
		}
		
	}
	.share{
		width: 100rpx;
		height:100rpx;
		z-index: 9999;
		border-radius: 50%;
		position: fixed;
		bottom: 100rpx;
		right:50rpx;
		background-color: #925924;
		color: #fff;
		font-weight: bold;
		font-size: 28rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>
