<template>
	<view>
		
		<view class="top">
			<view class="title">{{reportdata.examName}}</view>
			<view class="desc">交卷时间：{{$method.timestampToTime(reportdata.updateTime,false)}}</view>
			
			<view class="box">
				<view class="left">
					<view>{{(reportdata.rightQuestionNum / reportdata.totalQuestionNum * 100).toFixed(0)}}%</view>
					<view>正确率</view>
					<view>不含简答/案例题</view>
				</view>
				<view class="right">
					<view class="flex up">
						<image src="/static/5-4_03.png" mode=""></image>
						<view class="text">正确题数</view>
						<text class="red">{{reportdata.rightQuestionNum}}</text>
					</view>
					<view class="flex down">
						<image src="/static/5-4_03.png" mode=""></image>
						<view class="text">错误题数</view>
						<text class="green">{{reportdata.totalQuestionNum - reportdata.rightQuestionNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom">
			
			<view class="circle-wrap">
				<view class="circle-list">
					<view class="item">
						<view class="title">
							试卷得分
							<text>（不含简答和案例题）</text>
						</view>
						<canvas class="canvas" canvas-id="Canvas1"></canvas>
					</view>
					<view class="item">
						<view class="title">
							答题时长
						</view>
						<canvas  canvas-id="Canvas2"></canvas>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	data() {
		return {
			id:'',
			reportdata:{},
			context1:null,
			context2:null,
		};
	},
	onUnload() {
		
	},
	computed: { ...mapGetters(['userInfo']) },
	onLoad(option) {
		this.id = option.id;
		this.examReport();
	},
	onShow() {
		uni.getSystemInfo({
			success:(res) => {
				var winW = res.screenWidth;
				var winH = res.screenHeight;
				 uni.createSelectorQuery().in(this).select('.canvas').boundingClientRect().exec((newRes)=>{  
					  var width = newRes[0].width;
					  var height = newRes[0].height;
					  var caculateX = winW/750;
					  var caculateY = winH/1334;
					  console.log(caculateX)
					  var context1 = uni.createCanvasContext('Canvas1')
					  this.context1 = context1;
					  context1.setStrokeStyle("#EEEEEE")
					  context1.setLineWidth(caculateX * 20)
					  context1.arc(caculateX * 90, caculateX * 90, caculateX * 80, 0, 2 * Math.PI, true)
					  context1.stroke()
					  context1.beginPath()
					  context1.setStrokeStyle("#32D74B")
					  context1.setFillStyle('#32D74B')
					  context1.setTextAlign('center')
					  context1.setTextBaseline('middle')
					  context1.setLineCap('round')
					  context1.setFontSize(caculateX * 64)
					  context1.fillText('60', caculateX * 90, caculateX * 90, caculateX * 180)
					  context1.setFillStyle('#999999')
					  context1.setFontSize(caculateX * 20)
					  context1.fillText('满分100', caculateX * 90, caculateX * 130, caculateX * 180)
					  context1.arc(caculateX * 90, caculateX * 90, caculateX * 80, 0,  Math.PI, true)
					  context1.stroke()
					  context1.draw()
					  
					  
					  
					  
					  var context2 = uni.createCanvasContext('Canvas2')
					  this.context2 = context2;
					  context2.setStrokeStyle("#EEEEEE")
					  context2.setLineWidth(caculateX * 20)
					  context2.arc(caculateX * 90, caculateX * 90, caculateX * 80, 0, 2 * Math.PI, true)
					  context2.stroke()
					  context2.beginPath()
					  context2.setStrokeStyle("#007AFF")
					  context2.setFillStyle("#007AFF")
					  context2.setTextAlign('center')
					  context1.setTextBaseline('middle')
					  context2.setLineCap('round')
					  context2.setFontSize(caculateX * 64)
					  context2.fillText("12'", caculateX * 90, caculateX * 90, caculateX * 180)
					  context2.setFillStyle('#999999')
					  context2.setFontSize(caculateX * 20)
					  context2.fillText("限时120'", caculateX * 90, caculateX * 130, caculateX * 180)
					  context2.arc(caculateX * 90, caculateX * 90, caculateX * 80, 0,  Math.PI, true)
					  context2.stroke()
					  context2.draw()
				})  
				
			}
		})
		
	},
	methods: {
		examReport() {
			this.$api.examReport(this.id).then(res => {
				this.reportdata = res.data.data;
			})
		}
	}
};
</script>
<style >
	page{
		background-color: #EAEEF1;
	}
</style>
<style lang="scss" scope>
	
	.top {
		margin:16rpx 16rpx 0;
		border-radius: 16rpx;
		padding:40rpx 24rpx 16rpx;
		background:#fff;
		.title {
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
		}
		
		.desc {
			margin-top:20rpx;
			font-size: 24rpx;
			color: #999999;
		}
		
		.box {
			margin-top:30rpx;
			display: flex;
			
			.left {
				width: 250rpx;
				height: 176rpx;
				background: #F5F5F5;
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				margin-right:16rpx;
				
				view {
					text-align: center;
					
					&:nth-of-type(1) {
						font-size: 60rpx;
						font-weight: bold;
						color: #007AFF;
					}
					&:nth-of-type(2) {
						font-size: 32rpx;
						font-weight: bold;
						color: #333333;
					}
					&:nth-of-type(3) {
						font-size: 24rpx;
						color: #999999;
					}
				}
			}
			
			.right{
				flex:1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				
				.flex {
					background:#F5F5F5;
					display: flex;
					height: 80rpx;
					align-items: center;
					padding:0 40rpx;
					border-radius: 16rpx;
					
					image {
						width: 30rpx;
						height: 30rpx;
						margin-right:28rpx;
					}
					
					.text {
						flex:1;
						font-size: 30rpx;
						color: #666666;
					}
					
					text {
						font-size: 48rpx;
						color: #E12626;
						
						&.red {
							color:red;
						}
						
						&.green {
							color:green;
						}
					}
				}
			}
		}
	}
	
	.bottom {
		.circle-wrap {
			
			.circle-list {
				display: flex;
				
				.item {
					padding:20rpx;
					border-radius: 16rpx;
					background:#fff;
					margin:16rpx;
					flex:1;
					
					.title {
						font-weight: bold;
						font-size: 30rpx;
						line-height: 24rpx;
						color: #333333;
						
						text {
							font-size: 20rpx;
							color: #999999;
						}
					}
					
					canvas {
						margin:36rpx auto 0;
						width:180rpx;
						height:180rpx;
					}
					
					.text {
						text-align: center;
						margin-top:16rpx;
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}
	}
	
</style>
