<template>
	<view class="module-container">
		<!-- 评测 -->
		<view class="card" style="background-color:#4169e1" v-if="current == 0">
			<view class="box">
				<view class="flex">
					<text class="card-title">今日评测:</text>
					<view class="flex-line">
						<text class="card-title" style="margin-left: 20rpx;">{{testData.length}}</text>
						<text class="unit">例</text>
					</view>
				</view>
				<view class="box" style="margin: 10rpx 0 0 0;">
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">已完成:</text>
						<view class="flex-line">
							<text class="fin-number">{{testFinish}}</text>
							<text class="unit">例</text>
						</view>
					</view>
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">完成情况:</text>
						<text class="card-subtitle" style="font-weight: bold;opacity: 0.8;">{{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>
					<view class="flex-line">
						<text class="card-title" style="margin-left: 20rpx;">{{homeworkData.length}}</text>
						<text class="unit">例</text>
					</view>
				</view>
				<view class="box" style="margin: 10rpx 0 0 0;">
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">已完成:</text>
						<view class="flex-line">
							<text class="fin-number">{{homeworkFinish}}</text>
							<text class="unit">例</text>
						</view>
					</view>
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">完成情况:</text>
						<text class="card-subtitle" style="font-weight: bold;opacity: 0.8;">{{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>
					<view class="flex-line">
						<text class="card-title" style="margin-left: 20rpx;">{{activityData.length}}</text>
						<text class="unit">例</text>
					</view>
				</view>
				<view class="box" style="margin: 10rpx 0 0 0;">
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">已完成:</text>
						<view class="flex-line">
							<text class="fin-number">{{activityFinish}}</text>
							<text class="unit">例</text>
						</view>
					</view>
					<view class="flex">
						<view class="tag"></view>
						<text class="card-subtitle">完成情况:</text>
						<text class="card-subtitle" style="font-weight: bold;opacity: 0.8;">{{list[2].level}}</text>
					</view>
				</view>
			</view>
			<view class="image" :style="{backgroundImage:`url(${list[2].image})`}"></view>
		</view>
		<!-- 插槽传入内容 -->
		<slot name="center-slot"></slot>
		<!-- 列表 -->
		<view class="detail-box">
			<!-- 图表模块 -->
			<view class="detail-box-item" v-if="current == 1">
				<view class="item-info">
					<view class="t-icon t-icon-ceping"></view>
					<view class="item-text">完成率统计</view>
				</view>
				<view class="charts-box">
					<qiun-data-charts type="mount" :chartData="taskData" :loadingType="4"
						:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0933511'/>
				</view>
			</view>
			<!-- 详情列表 -->
			<!-- 评测 -->
			<view class="detail-box-item" v-if="current == 0" @click="navListData">
				<view class="item-info">
					<view class="t-icon t-icon-daiban"></view>
					<view class="item-text">评测列表</view>
				</view>
				<view style="margin-bottom: 20rpx;">
					<view class="block-box" v-for="(item,i) in testData" :key="i">
						<view class="tag-index" style="background-image: linear-gradient(#4169E1, #FFF);">
						</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">
									<view class="block-tag">
										{{item.examInfo.subjects[0].name}}
									</view>
								</view>
								<view class="block-tag-box">
									<view class="block-tag">
										{{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" @click="navListData">
				<view class="item-info">
					<view class="t-icon t-icon-daiban"></view>
					<view class="item-text">作业列表</view>
				</view>
				<view style="margin-bottom: 20rpx;">
					<view class="block-box" v-for="(item,i) in homeworkData" :key="i">
						<view class="tag-index" style="background-image: linear-gradient(#ff8caf, #FFF);">
						</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:'#ff8caf'}">
										<view class="block-tag"
											:style="{color:'#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" @click="navListData">
				<view class="item-info">
					<view class="t-icon t-icon-daiban"></view>
					<view class="item-text">活动列表</view>
				</view>
				<view style="margin-bottom: 20rpx;">
					<view class="block-box" v-for="(item,i) in activityData" :key="i">
						<view class="tag-index" style="background-image: linear-gradient(#f9c752, #FFF);">
						</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:'#f9c752'}">
										<view class="block-tag"
											:style="{color:'#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>
		<!-- 插槽传入内容 -->
		<slot name="end-slot"></slot>
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		name: "task-box",
		computed: {
			//单独作业图表数据
			...mapState('m_chart', ['taskData']),
		},
		props: {
			//当前模块
			current: {
				type: Number,
				default () {
					return 1
				}
			},
		},
		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',
				}],
				//页面数据内容
				testData: {},
				homeworkData: {},
				activityData: {},
				//完成内容
				testFinish: '',
				homeworkFinish: '',
				activityFinish: '',
				//作业完成率记录
				historyHomeworkChart: [80,60,66,79,55,20,40]
			};
		},
		created(options) {
			this.init()
		},
		methods: {
			...mapMutations('m_chart', ['updateHomeworkFinChart']),
			...mapMutations('m_children', ['updateDetailList', 'updateDetail']),
			//初始化页面
			init() {
				this.$initHomework()
				this.getLevel()
				this.saveToStudyChart()
			},
			//获得评判信息
			getLevel() {
				this.list[0].level = this.testFinish / this.testData.length >= 0.4 ?
					(this.testFinish / this.testData.length >= 0.7 ? '优秀' : '良好') : '较差'
				this.list[1].level = this.homeworkFinish / this.homeworkData.length >= 0.4 ?
					(this.homeworkFinish / this.homeworkData.length >= 0.7 ? '优秀' : '良好') : '较差'
				this.list[2].level = this.activityFinish / this.activityData.length >= 0.4 ?
					(this.activityFinish / this.activityData.length >= 0.7 ? '优秀' : '良好') : '较差'
			},
			//记录完成率到图表
			saveToStudyChart(){
				this.historyHomeworkChart.push(parseInt(this.homeworkFinish * 100 / this.homeworkData.length))
				if(this.historyHomeworkChart.length>7)
				this.historyHomeworkChart.shift()
				let temp = {
					series: [{
						data: []
					}]
				}
				let dateArray = this.$getRecentDateArray(this.historyHomeworkChart.length)
				for (let i = 0 ;i<this.historyHomeworkChart.length; i++) {
					let item = {
						name: dateArray[i],
						value: this.historyHomeworkChart[i]
					}
					temp.series[0].data.push(item)
				}
				this.updateHomeworkFinChart(temp)
			},
			//导航到详情页面
			navListData() {
				if (this.current === 0) {
					this.updateDetailList(this.testData)
					uni.navigateTo({
						url: `/subpkg/detaillist/examlist`
					})
				}
				if (this.current === 1) {
					this.updateDetailList(this.homeworkData)
					uni.navigateTo({
						url: `/subpkg/detaillist/homeworklist`
					})
				}
				if (this.current === 2) {
					this.updateDetailList(this.activityData)
					uni.navigateTo({
						url: `/subpkg/detaillist/activitylist`
					})
				}
			},
			//导航到单条数据页面
			navSingleData(item) {
				if (this.current === 0) {
					this.updateDetail(item)
					console.log(item);
					uni.navigateTo({
						url: `/subpkg/detail/exam`
					})
				}
				if (this.current === 1) {
					this.updateDetail(item)
					console.log(item);
					uni.navigateTo({
						url: `/subpkg/detail/homework`
					})
				}
				if (this.current === 2) {
					this.updateDetail(item)
					console.log(item);
					uni.navigateTo({
						url: `/subpkg/detail/activity`
					})
				}
			}

		}
	}
</script>

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

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

	//模块
	.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;
			}

			.unit {
				margin-left: 10rpx;
				font-size: 30rpx;
				opacity: 0.8;
				color: #FFF;
			}

			.fin-number {
				margin-left: 20rpx;
				font-size: 36rpx;
				font-weight: bold;
				color: #FFF;
			}

			.image {
				position: relative;
				top: -80rpx;
				right: -40rpx;
				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;
		}

		//列表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;
					}
				}
			}
		}
	}

	.tag {
		background-color: #FFF;
		height: 30rpx;
		width: 10rpx;
		border-radius: 100rpx;
		margin-left: 10rpx;
		opacity: 0.8;
	}

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

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

	.flex-line {
		display: flex;
		align-items: baseline;
	}
</style>
