<template>
	<view class="page-view">
		<!-- 统计 -->
		<view class="bg1">
			<view class="circle_line1"></view>
			<view class="circle_line2"></view>
			<view class="circle_line3"></view>
			<top-info :timeStamp="timeStamp"></top-info>
			<scroll-view class="scroll_view" scroll-x="true" :scroll-with-animation="true" scroll-left="0">
				<view class="view_box">
					<view class="scroll_view_item" v-for="(item,index) in cardList" :key="index"
						@click="navGradeList(index)">
						<view class="card_info">
							<view :class="item.icon"></view>
							<view class="title">{{item.title}}</view>
						</view>
						<view class="chart_box">
							<qiun-data-charts :type="item.type" :chartData="item.data" />
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

		<!-- 统计卡片 -->
		<view class="card-view">
			<view class="total_card">
				<view class="flex_cloumn" style="justify-content: space-around;margin: 20rpx 0 20rpx 20rpx;">
					<view class="flex_baseline">
						<text class="_title">今日评测</text>
						<text class="_title" style="margin-left: 20rpx;">{{examData.length}}</text>
						<text class="_unit">例</text>
					</view>
					<view class="flex_baseline">
						<text class="_subtitle">已完成</text>
						<text class="_subtitle" style="margin-left: 20rpx;">{{finishData.length}}</text>
						<text class="_unit">例</text>
					</view>
					<view class="flex_baseline">
						<text class="_subtitle">完成情况</text>
						<text class="_subtitle" style="margin-left: 20rpx;">{{performance}}</text>
					</view>
				</view>
				<view class="image" :style="{backgroundImage:`url(${image})`}"></view>
			</view>
			<!-- 列表卡片 -->
			<view class="card-item" style="width: 100%;">
				<view class="card-title">
					<view class="front-tag"></view>
					<view class="title">今日评测</view>
					<view class="flex_row" style="margin: 0 0 0 auto;" @click="navExamList" v-if="examData.length != 0">
						<view class="t-icon t-icon-fenlei"></view>
						<view class="title" style="color: #4169E1;margin-left: 10rpx;">评测列表</view>
					</view>
				</view>
				<view class="class_list">
					<view class="class_item"
						:style="{borderImage: none}"
						v-for="(item,index) in examData" :key="index" @click="navExamData(index)"
						v-if="examData.length != 0">
						<view class="flex_row" style="margin: 0 20rpx;">
							<view class="t-icon t-icon-examicon" style="width: 60rpx; height: 60rpx;"></view>
							<view class="flex_cloumn" style="height:92rpx;justify-content: space-between;">
								<view class="flex_row" style="margin-left: 20rpx;">
									<view class="class_item_title">{{item.examInfo.name}}</view>
								</view>
								<view class="flex_row">
									<view class="tag-fill">
										<view class="tag-text">{{item.examInfo.subjects[0].name}}</view>
									</view>
									<view class="tag-fill">
										<view class="tag-text">{{item.examInfo.examType.name}}</view>
									</view>
									<view class="tag-fill"
										:style="{backgroundColor: item.examInfo.progress === 'finish'? '#23b46c':'#ff5959'}">
										<view class="tag-text">{{item.examInfo.progress === 'finish' ? '已完成' : '进行中'}}
										</view>
									</view>

								</view>
							</view>
						</view>
					</view>
					<view class="image_box" v-if="examData.length === 0">
						<view class="detail_image_none" :style="{backgroundImage:`url(${image1})`}"></view>
						<view class="subtitle">今日孩子暂无评测活动</view>
					</view>
				</view>
			</view>

			<view class="flex_cloumn" style="margin: 15rpx 0 10rpx 20rpx;">
				<view class="title" style="font-size: 32rpx;">评测练习</view>
				<view class="bottom-tag"></view>
			</view>

			<view class="flex_row" style="width: 70%;"></view>
		</view>
		<scroll-view class="scroll_view_bottom" scroll-x="true" :scroll-with-animation="true" scroll-left="0">
			<view class="_item" v-for="(item,index) in examPractice" :key="index" @click="navExercisesInfo(index)">
				<view class="flex_cloumn" style="height: 320rpx;">
					<view class="flex_row" style="margin: 10rpx;">
						<view class="t-icon t-icon-yuwen" v-if="item.subject === '语文'"></view>
						<view class="t-icon t-icon-shuxue" v-if="item.subject === '数学'"></view>
						<view class="t-icon t-icon-yingyu" v-if="item.subject === '英语'"></view>
						<view class="t-icon t-icon-tiyu" v-if="item.subject === '体育'"></view>
						<view class="t-icon t-icon-tianwen" v-if="item.subject === '科学'"></view>
						<view class="t-icon t-icon-zuixinkecheng" v-if="item.subject === '思品'"></view>
						<view class="t-icon t-icon-wuli" v-if="item.subject === '物理'"></view>
						<view class="t-icon t-icon-huaxue" v-if="item.subject === '化学'"></view>
						<view class="t-icon t-icon-meishu" v-if="item.subject === '美术'"></view>
						<view class="t-icon t-icon-yinle" v-if="item.subject === '音乐'"></view>
						<view class="t-icon t-icon-dili" v-if="item.subject === '地理'"></view>
						<view class="t-icon t-icon-lishi" v-if="item.subject === '历史'"></view>
						<view class="flex_cloumn" style="height: 100rpx;justify-content: space-around;">
							<view class="YS-title" style="font-size: 40rpx;">{{item.subject}}</view>
							<view class="tag-fill"
								style="background-color: #d8deff;width:fit-content;margin-left: 0;padding: 5rpx 10rpx;">
								<view class="t-icon t-icon-zhengceguizhang"
									style="width: 30rpx;height: 30rpx;margin-right: 5rpx;"></view>
								<view class="tag-text" style="color: #4169E1;">{{item.type}}</view>
							</view>
						</view>
					</view>
					<view class="flex_cloumn" style="height: 100%;justify-content: space-around;margin: 0 30rpx 20rpx 30rpx;">
						<view class="YS-title">{{item.title}}</view>
						<view class="YS-title" style="font-size: 30rpx;">「 {{item.modality}} 」</view>
						<view class="flex_baseline">
								<view class="subtitle" style="font-weight: 400;font-size: 28rpx;">评测题量,共</view>
								<view class="subtitle" style="font-weight: 400;font-size: 40rpx;margin-left: 4rpx;">{{item.amount}}</view>
								<view class="subtitle" style="font-weight: 400;font-size: 28rpx;margin-left: 4rpx;">题</view>
						</view>

					</view>
				</view>

			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_chart', ['examChartData']),
			...mapState('m_children', ['examData', 'examPractice'])
		},
		data() {
			return {
				cardList: [{
					icon: 't-icon t-icon-zoushi',
					title: '总成绩走势',
					type: 'mini-area',
					data: ''
				}, {
					icon: 't-icon t-icon-shuju',
					title: '单次考试分析',
					type: 'mini-column',
					data: ''
				}, {
					icon: 't-icon t-icon-jiangzhang',
					title: '排行占比分析',
					type: 'mini-area',
					data: ''
				}, {
					icon: 't-icon t-icon-yingyong',
					title: '优劣科目分析',
					type: 'mini-rose',
					data: ''
				}, {
					icon: 't-icon t-icon-yunwei',
					title: '考试能力分析',
					type: 'mini-column',
					data: ''
				}],
				image: 'https://ouch-cdn2.icons8.com/yFl5NWU3aVehLBlQf9ctvnZPqtm5U0hqM3IzWvFDCaQ/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9wbmcvNzY5/LzY1ZTQxZmZjLTg1/YWQtNDYyMi1hYzU0/LWQ3NDEzZmY2NGI1/YS5wbmc.png',
				//完成情况
				performance: '',
				//完成数据
				finishData: '',
				finishRate: '',
				timeStamp: '',
				image1: 'https://image.meiye.art/pic_1631411821365LA63Wc70BLbmyHhj2XjiL',
			};
		},
		onLoad() {
			this.init()
		},
		//刷新页面
		onPullDownRefresh() {
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			//初始化
			init() {
				this.timeStamp = (new Date()).format("hh:mm")
				this.$initExam()
				this.getChartData()
				this.getPerformance()
			},
			//初始化cardList数据
			getChartData() {
				this.cardList[0].data = this.examChartData.totalChartData[0]
				this.cardList[1].data = this.examChartData.singleChartData[0]
				this.cardList[2].data = this.examChartData.rankingChartData[0]
				this.cardList[3].data = this.examChartData.subjectChartData[0]
				this.cardList[4].data = this.examChartData.levelChartData[0]
			},
			//获得评判信息
			getPerformance() {
				if (this.examData.length != 0) {
					this.finishData = this.examData.filter(x => x.examInfo.progress === 'finish')
					this.finishRate = (this.finishData.length * 100 / this.examData.length).toFixed(0)
					this.performance = this.finishData.length / this.examData.length >= 0.4 ?
						(this.finishData.length / this.examData.length >= 0.7 ? '优秀' : '良好') : '较差'
				} else {
					this.finishData = []
					this.finishRate = 0
					this.performance = '无评测'
				}

			},
			//导航
			navGradeList(index) {
				if (index === 0) {
					uni.navigateTo({
						url: '/subpkg/exam/total'
					})
				}
				if (index === 1) {
					uni.navigateTo({
						url: '/subpkg/exam/single'
					})
				}
				if (index === 2) {
					uni.navigateTo({
						url: '/subpkg/exam/ranking'
					})
				}
				if (index === 3) {
					uni.navigateTo({
						url: '/subpkg/exam/subject'
					})
				}
				if (index === 4) {
					uni.navigateTo({
						url: '/subpkg/exam/level'
					})
				}
			},
			navExamList() {
				let value = this.finishRate
				uni.navigateTo({
					url: `/subpkg/datalist/examlist?value=${value}`
				})
			},
			navExamData(index) {
				uni.navigateTo({
					url: `/subpkg/datalist/examdata?index=${index}`
				})
			},
			navExercisesInfo(index){
				uni.navigateTo({
					url: `/subpkg/exam/exercisesinfo?index=${index}`
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/pages/style/tab_pages.scss';

	.bg1 {
		background-color: $color-pink;
	}

	.tag-fill {
		background-color: $color-pink;
		margin-left: 20rpx;
	}

	.circle_line1 {
		background-image: linear-gradient(to right, #ff8caf, #ff8caf), linear-gradient(90deg, #FFF -50%, rgba(255, 255, 255, 0.0));
	}

	.circle_line2 {
		background-image: linear-gradient(to right, #ff8caf, #ff8caf), linear-gradient(180deg, #FFF -50%, rgba(255, 255, 255, 0.0));
	}

	.circle_line3 {
		background-image: linear-gradient(to right, #ff8caf, #ff8caf), linear-gradient(0deg, #FFF -50%, rgba(255, 255, 255, 0.0));
	}
</style>
