<template>
	<view class="homework-container">
		<!-- 头部区域 -->
		<top-box :timeStamp="timeStamp" />
		<view class="module-container">
			<view style="margin: 0 20rpx">
				<u-tabs :list="list" :current="current" @change="changeModule"
					:activeStyle="{color: '#4169E1',fontWeight: 'bold',transform: 'scale(1.08)',}"
					:inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#4169E1" lineWidth="60">
				</u-tabs>
			</view>
			<!-- 模块卡片 -->
			<view class="module-box">
				<!-- 评测 -->
				<view class="card" style="background-color: #4169E1;" v-if="current == 0">
					<view class="box">
						<view class="flex">
							<text class="card-title">今日评测数:</text>
							<text class="card-title" style="margin-left: 20rpx;">{{testData.length}}</text>
						</view>
						<view class="box" style="margin: 10rpx 0 0 0;">
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成数量:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{testFinish}}</text>
							</view>
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成情况:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{list[0].level}}</text>
							</view>
						</view>
					</view>
					<view class="image" :style="{backgroundImage:`url(${list[0].image})`}"></view>
				</view>
				<!-- 作业 -->
				<view class="card" style="background-color: #ff8caf;" v-if="current == 1">
					<view class="box">
						<view class="flex">
							<text class="card-title">今日作业数:</text>
							<text class="card-title" style="margin-left: 20rpx;">{{homeworkData.length}}</text>
						</view>
						<view class="box" style="margin: 10rpx 0 0 0;">
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成数量:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{homeworkFinish}}</text>
							</view>
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成情况:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{list[1].level}}</text>
							</view>
						</view>
					</view>
					<view class="image" :style="{backgroundImage:`url(${list[1].image})`}"></view>
				</view>
				<!-- 活动 -->
				<view class="card" style="background-color: #f9c752;" v-if="current == 2">
					<view class="box">
						<view class="flex">
							<text class="card-title">今日活动数:</text>
							<text class="card-title" style="margin-left: 20rpx;">{{activityData.length}}</text>
						</view>
						<view class="box" style="margin: 10rpx 0 0 0;">
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成数量:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{activityFinish}}</text>
							</view>
							<view class="flex">
								<view class="index-box"></view>
								<text class="card-subtitle">完成情况:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{list[2].level}}</text>
							</view>
						</view>
					</view>
					<view class="image" :style="{backgroundImage:`url(${list[2].image})`}"></view>
				</view>
				<!-- 列表 -->
				<view class="detail-box">
					<!-- 图表模块 -->
					<view class="detail-box-item">
						<view class="item-info">
							<view class="t-icon t-icon-ceping"></view>
							<view class="item-text">完成情况统计</view>
						</view>
						<view class="charts-box" v-if="current == 0">
							<qiun-data-charts type="fin-area" :chartData="assignment.testData" :loadingType="4"
								:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0980111' />
						</view>
						<view class="charts-box" v-if="current == 1">
							<qiun-data-charts type="fin-area" :chartData="assignment.homeworkData" :loadingType="4"
								:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0933511' :opts="{color:['#ff8caf']}"/>
						</view>
						<view class="charts-box" v-if="current == 2">
							<qiun-data-charts type="fin-area" :chartData="assignment.activityData" :loadingType="4"
								:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0531032' :opts="{color:['#f9c752']}"/>
						</view>
					</view>
					<!-- 详情列表 -->
					<!-- 评测 -->
					<view class="detail-box-item" v-if="current == 0">
						<view class="item-info">
							<view class="t-icon t-icon-daiban"></view>
							<view class="item-text">评测列表</view>
							<view class="btn" @click="navData">
								<view class="t-icon t-icon-fenlei"></view>
								<view class="msg">详情列表</view>
							</view>
						</view>
						<view style="margin-bottom: 20rpx;">
							<view class="block-box" v-for="(item,i) in testData" :key="i">
								<view class="index"
									:style="{backgroundColor: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">
								</view>

								<view class="class-block" style="width: 85%;">
									<view style="width: 40%;">
										<view class="list-item-title">{{item.examInfo.name}}</view>
									</view>

									<view style=" display: flex; justify-content: space-between; width: 50%;">
										<view class="block-tag-box" :style="{borderColor: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">
											<view class="block-tag" :style="{color: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">{{item.examInfo.subjects[0].name}}</view>
										</view>
										<view class="block-tag-box" :style="{borderColor: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">
											<view class="block-tag" :style="{color: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">{{item.examInfo.examType.name}}</view>
										</view>
										<view class="block-tag-box" :style="{borderColor: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">
											<view class="block-tag" :style="{color: item.examInfo.progress === 'finish'? '#23b46c':'#4169E1'}">
												{{item.examInfo.progress === 'finish' ? '已完成' : '进行中'}}
											</view>
										</view>
									</view>

								</view>

							</view>
						</view>
					</view>
					<!-- 作业 -->
					<view class="detail-box-item" v-if="current == 1">
						<view class="item-info">
							<view class="t-icon t-icon-daiban"></view>
							<view class="item-text">作业列表</view>
							<view class="btn" @click="navData">
								<view class="t-icon t-icon-fenlei"></view>
								<view class="msg">详情列表</view>
							</view>
						</view>
						<view style="margin-bottom: 20rpx;">
							<view class="block-box" v-for="(item,i) in homeworkData" :key="i">
								<view class="index"
									:style="{backgroundColor: item.work.progress === 'finish'? '#23b46c':'#ff8caf'}">
								</view>
								<view class="class-block" style="width: 85%;justify-content: flex-start;">
									<view style="display: flex; flex-direction: column;">

										<view style="display: flex;margin-left: 30rpx;align-items: center;">
											<view class="list-item-title">{{item.work.name}}</view>
											<view class="block-tag-box" :style="{marginLeft: 40+'rpx',borderColor: item.work.progress === 'finish'? '#23b46c':'#ff8caf'}">
												<view class="block-tag" :style="{color: item.work.progress === 'finish'? '#23b46c':'#ff8caf'}">{{item.work.scope === 'private' ? '个人':'学校'}}作业
												</view>
											</view>
											<view class="block-tag-box" :style="{marginLeft: 20+'rpx',borderColor: item.work.progress === 'finish'? '#23b46c':'#ff8caf'}">
												<view class="block-tag" :style="{color: item.work.progress === 'finish'? '#23b46c':'#ff8caf'}">
													{{item.work.progress === 'finish' ? '已完成' : '进行中'}}
												</view>
											</view>
										</view>
										<rich-text class="block-subtitle" style="margin:10rpx 0 0 30rpx;"
											:nodes="item.work.description"></rich-text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 活动 -->
					<view class="detail-box-item" v-if="current == 2">
						<view class="item-info">
							<view class="t-icon t-icon-daiban"></view>
							<view class="item-text">活动列表</view>
							<view class="btn" @click="navData">
								<view class="t-icon t-icon-fenlei"></view>
								<view class="msg">详情列表</view>
							</view>
						</view>
						<view style="margin-bottom: 20rpx;">
							<view class="block-box" v-for="(item,i) in activityData" :key="i">
								<view class="index"
									:style="{ backgroundColor: item.survey.progress === 'finish' || item.vote.progress === 'finish'? '#23b46c':'#f9c752'}">
								</view>
								<view class="class-block" style="width: 85%;justify-content: flex-start;">
									<view style="display: flex; flex-direction: column;">
										<view style="display: flex;margin-left: 30rpx;align-items: center;">
											<view class="list-item-title">
												{{item.survey.name || item.vote.name}}
											</view>

											<view class="block-tag-box" :style="{ marginLeft: 40+'rpx',borderColor: item.survey.progress === 'finish' || item.vote.progress === 'finish'? '#23b46c':'#f9c752'}">
												<view class="block-tag" :style="{color: item.survey.progress === 'finish' || item.vote.progress === 'finish'? '#23b46c':'#f9c752'}">
													{{item.survey.scope === 'private' ? '个人':'学校' || item.vote.scope === 'private' ? '个人':'学校'}}活动
												</view>
											</view>
											<view class="block-tag-box" :style="{ marginLeft: 20+'rpx',borderColor: item.survey.progress === 'finish' || item.vote.progress === 'finish'? '#23b46c':'#f9c752'}">
												<view class="block-tag" :style="{color: item.survey.progress === 'finish' || item.vote.progress === 'finish'? '#23b46c':'#f9c752'}">
													{{item.survey.progress === 'finish' || item.vote.progress === 'finish' ? '已完成' : '进行中'}}
												</view>
											</view>
										</view>

										<rich-text class="block-subtitle" style="margin:10rpx 0 0 30rpx;"
											:nodes="item.vote.description || item.survey.description"></rich-text>
									</view>
								</view>
							</view>
						</view>
					</view>

				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_chart', ['assignment']),
		},
		data() {
			return {
				//模块名
				list: [{
					name: '评测详情',
					level: '',
					image: 'https://ouch-cdn2.icons8.com/yFl5NWU3aVehLBlQf9ctvnZPqtm5U0hqM3IzWvFDCaQ/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9wbmcvNzY5/LzY1ZTQxZmZjLTg1/YWQtNDYyMi1hYzU0/LWQ3NDEzZmY2NGI1/YS5wbmc.png',
				}, {
					name: '作业详情',
					level: '',
					image: 'https://ouch-cdn2.icons8.com/AVOwJ9emg_ZOeHvQaunQAZlgeLsG-b1cGhiYvgoJ06g/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9wbmcvNTAw/LzI5YjU1YWQ4LWMw/YTEtNDE1MS1iYmQw/LWIyMDdhYmRkOTE0/Mi5wbmc.png',
				}, {
					name: '活动详情',
					level: '',
					image: 'https://ouch-cdn2.icons8.com/LW70TMgW1cGfYeGNSTEp7__kiKVgIhwdZwUmykdLYMY/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9wbmcvOTI0/LzU3MWU4ZDZkLTg0/NzEtNGM5YS04MDJk/LTEzNTM5YmZmZTM2/YS5wbmc.png',
				}],
				//当前模块
				current: 0,
				//页面数据内容
				testData: {},
				homeworkData: {},
				activityData: {},
				//完成内容
				testFinish: '',
				homeworkFinish: '',
				activityFinish: '',
				//历史数据
				historyData: {
					test: [50, 55, 60],
					homework: [10, 60, 50, 88, 100],
					activity: [70, 19, 28, 40, 60, 100, 83]
				},
				//时间戳
				timeStamp: '',
			};
		},
		onLoad(options) {
			this.init()
			if (options.index)
				this.current = options.index
		},
		//刷新页面
		onPullDownRefresh() {
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			...mapMutations('m_chart', ['updateTestArea', 'updateHomeworkArea', 'updateActivityArea']),
			...mapMutations('m_children', ['updateDetail']),
			//初始化页面
			init() {
				this.timeStamp = (new Date()).format("hh:mm")
				this.$initHomework()
				this.saveToStudyChart()
				this.getLevel()

			},
			//更改模块
			changeModule(e) {
				this.current = e.index
			},
			//获得评判信息
			getLevel() {
				let testArr = this.historyData.test
				let homeworkArr = this.historyData.homework
				let activityArr = this.historyData.activity
				this.list[0].level = testArr[testArr.length - 1] >= 40 ?
					(testArr[testArr.length - 1] >= 70 ? '优秀' : '良好') : '较差'
				this.list[1].level = homeworkArr[homeworkArr.length - 1] >= 40 ?
					(homeworkArr[homeworkArr.length - 1] >= 70 ? '优秀' : '良好') : '较差'
				this.list[2].level = activityArr[activityArr.length - 1] >= 40 ?
					(activityArr[activityArr.length - 1] >= 70 ? '优秀' : '良好') : '较差'
			},
			//记录完成率到图表
			saveToStudyChart() {
				let temp = {
					categories: [],
					series: [{
						"name": "",
						"data": []
					}]
				}
				// 测试
				this.historyData.test.push(parseInt(this.testFinish * 100 / this.testData.length))
				if (this.historyData.test.length > 7)
					this.historyData.test.shift()
				temp.categories = this.$getRecentDateArray(this.historyData.test.length)
				//数据
				//解除对象指向同一块内存(拷贝)
				temp.series[0].data = this.historyData.test
				let testDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateTestArea(testDataTemp)
				//作业
				this.historyData.homework.push(parseInt(this.homeworkFinish * 100 / this.homeworkData
					.length))
				if (this.historyData.homework.length > 7)
					this.historyData.homework.shift()
				temp.categories = this.$getRecentDateArray(this.historyData.homework.length)
				temp.series[0].data = this.historyData.homework
				let homeworkDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateHomeworkArea(homeworkDataTemp)
				//活动
				this.historyData.activity.push(parseInt(this.activityFinish * 100 / this.activityData
					.length))
				if (this.historyData.activity.length > 7)
					this.historyData.activity.shift()
				temp.categories = this.$getRecentDateArray(this.historyData.activity.length)
				temp.series[0].data = this.historyData.activity
				let activityDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateActivityArea(activityDataTemp)
			},
			//导航到详情页面
			navData() {
				if (this.current === 0) {
					this.updateDetail(this.testData)
					uni.navigateTo({
						url: `/subpkg/detaillist/examlist`
					})
				}
				if (this.current === 1) {
					this.updateDetail(this.homeworkData)
					uni.navigateTo({
						url: `/subpkg/detaillist/homeworklist`
					})
				}
				if (this.current === 2) {
					this.updateDetail(this.activityData)
					uni.navigateTo({
						url: `/subpkg/detaillist/activitylist`
					})
				}

			}
		}
	}
</script>

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

	.list-item-title {
		font-size: 30rpx;
		font-weight: bold;
		color: $color-title;
	}

	.home-topinfo {
		background: linear-gradient($color-yellow, $page-background-color) !important;
	}

	//模块
	.module-container {
		margin-top: -70rpx;

		//头部卡片
		.card {
			display: flex;
			justify-content: space-around;
			margin: 20rpx auto 20rpx auto;
			height: 220rpx;
			width: 710rpx;
			// background: linear-gradient(to right, #ff95007a,#ff8419);
			border-radius: $card-border-radius;

			.card-title {
				font-size: 50rpx;
				font-weight: bold;
				color: #FFF;
			}

			.card-subtitle {
				margin-left: 20rpx;
				font-size: 30rpx;
				color: #FFF;
			}

			.border-bottom {
				height: 10rpx;
				width: 100%;
				border-radius: $card-border-radius;
				background-color: #FFF;
				margin: 5rpx 0 5rpx 0;
			}

			.image {
				position: relative;
				top: -90rpx;
				right: -35rpx;
				height: 300rpx;
				width: 300rpx;
				background-size: 100%;
				background-repeat: no-repeat;
				z-index: 2;
			}
		}

		//头部卡片
		.box {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			margin: 25rpx 0;
		}

		//中间标题
		.cut-off {
			font-size: 30rpx;
			font-weight: bold;
			color: #606266;
			margin-left: 40rpx;
		}

		//列表block
		.detail-box {
			display: flex;
			flex-flow: row wrap;
			margin: 30rpx 20rpx 0 20rpx;
			justify-content: space-between;

			.detail-box-item {
				margin: 0 0 4% 0;
				width: 100%;
				height: auto;
				background-color: #FFF;
				border-radius: $card-border-radius;

				.item-info {
					display: flex;
					align-items: center;
					padding: 20rpx;

					.t-icon {
						width: 40rpx;
						height: 40rpx;
					}

					.item-text {
						font-size: 30rpx;
						font-weight: bold;
						color: $color-title;
						margin-left: 15rpx;
					}
				}
			}
		}
	}

	.index-box {
		background-color: #FFF;
		height: 30rpx;
		width: 10rpx;
		border-radius: 100rpx;
	}

	//图表
	.charts-box {
		width: 100%;
		height: 300rpx;
	}

	.flex {
		display: flex;
		align-items: center;
		margin-left: 20rpx;
	}

	.msg {
		color: $color-mixblue;
		margin-left: 10rpx;
		font-size: 30rpx;
	}

	.btn {
		display: flex;
		align-items: center;
		margin: 0 5rpx 0 auto;
	}
</style>
