<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" v-for="(item,index) in pageData" :key="index" v-if="current == index">
				<!-- 详情头部卡片 -->
				<view class="card" :style="{backgroundColor: `${item.color}`}">
					<view class="box">
						<view class="flex">
							<text class="card-title">今日{{item.name}}数:</text>
							<text class="card-title" style="margin-left: 20rpx;">{{item.detail.data.length}}</text>
						</view>
						<view class="box" style="margin: 10rpx 0 0 0;">
							<view class="flex">
								<text class="card-subtitle">完成数量:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{finishData.length}}</text>
							</view>
							<view class="flex">
								<text class="card-subtitle">完成情况:</text>
								<text class="card-subtitle" style="margin-left: 20rpx;">{{item.level}}</text>
							</view>
						</view>
					</view>
					<view class="image" :style="{backgroundImage:`url(${item.image})`}"></view>
				</view>
				<!-- 中间标题 -->
				<view class="flex">
					<view class="cut-off">{{item.name}}信息</view>
				</view>
				<!-- 列表 -->
				<view class="detail-box" v-if="current == index">
					<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="homeworkData.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="homeworkData.homeworkData" :loadingType="4"
								:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0933511' />
						</view>
						<view class="charts-box" v-if="current == 2">
							<qiun-data-charts type="fin-area" :chartData="homeworkData.activityData" :loadingType="4"
								:canvas2d='true' tooltipFormat='HomeworkPercent' canvasId='canvans0531032' />
						</view>
					</view>
					<!-- 完成列表 -->
					<view class="detail-box-item">
						<view class="item-info">
							<view class="t-icon t-icon-shenhe"></view>
							<view class="item-text">今日已完成</view>
							<!-- 完成列表展示所有已完成的评测作业和活动信息 -->
						</view>
						<view style="margin-bottom: 20rpx;">
							<view class="block-box" v-for="(item,index) in finishData" :key="index">
								<view class="index" style="height: 100rpx;background-color: #00b894;"></view>
								<view class="class-block" style="height: 100rpx;width: 90%;">
									<view class="block-title">{{item.name}}</view>
									<view class="block-subtitle">科目:</view>
									<view class="block-tag-box">
										<view class="block-tag">{{item.subject}}</view>
									</view>
									<view class="block-subtitle">布置老师:</view>
									<view class="block-tag-box">
										<view class="block-tag">{{item.teacher}}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 列表 -->
					<view class="detail-box-item">
						<view class="item-info">
							<view class="t-icon t-icon-daiban"></view>
							<view class="item-text">{{item.detail.title}}</view>
							<!-- 详情列表展示(评测,活动或者作业)信息 -->
							<view style="display: flex; align-items: center;margin: 0 5rpx 0 auto;" @click="navData(index)">
								<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="(i,x) in item.detail.data" :key="x">
								<view class="index" :style="{height: 100+'rpx',backgroundColor: current === 0 ? '#4169E1':(current === 1 ? '#ff8caf': '#f9c752')}"></view>
								<view class="class-block" style="height: 100rpx; width: 90%;">
									<view class="block-title">{{i.name}}</view>
									<view class="block-tag-box">
										<view class="block-tag">{{i.subject}}</view>
									</view>
									<view class="block-tag-box">
										<view class="block-tag">{{i.teacher}}</view>
									</view>
									<view class="block-subtitle">{{i.description}}</view>
								</view>
							</view>
						</view>
					</view>

				</view>
			</view>

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

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_chart', ['homeworkData']),
		},
		data() {
			return {
				//模块名
				list: [{
					name: '评测详情'
				}, {
					name: '作业详情'
				}, {
					name: '活动详情'
				}],
				//当前模块
				current: 0,
				//页面数据内容
				pageData: '',
				//完成内容
				finishData: [],
				//历史数据
				historyData: {
					test: [90, 89, 98, 100, 50, 55, 60],
					homework: [10, 29, 38, 60, 50, 88, 100],
					activity: [70, 19, 28, 40, 60, 100, 83]
				},
				//时间戳
				timeStamp: '',
			};
		},
		watch: {
			current() {
				this.getFinishData()
			}
		},
		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', ['updateHomeworkDetail']),
			//初始化页面
			init() {
				this.$getTimeStamp()
				this.$initHomework()
				this.saveToStudyChart()
				this.getLevel()
				this.getFinishData()
			},
			//更改模块
			changeModule(index) {
				this.current = index.index
			},
			//获得评判信息
			getLevel() {
				this.pageData[0].level = this.historyData.test[6] >= 40 ? (this.historyData.test[6] >= 70 ? '优秀' : '良好') :
					'较差'
				this.pageData[1].level = this.historyData.homework[6] >= 40 ? (this.historyData.homework[6] >= 70 ? '优秀' :
					'良好') : '较差'
				this.pageData[2].level = this.historyData.activity[6] >= 40 ? (this.historyData.activity[6] >= 70 ? '优秀' :
					'良好') : '较差'
			},
			//获得完成数量
			getFinishData() {
				if (this.current === 0)
					this.finishData = this.pageData[0].detail.data.filter(x => x.finish === true)
				if (this.current === 1)
					this.finishData = this.pageData[1].detail.data.filter(x => x.finish === true)
				if (this.current === 2)
					this.finishData = this.pageData[2].detail.data.filter(x => x.finish === true)
			},
			//记录到图表
			saveToStudyChart() {
				let temp = {
					categories: [],
					series: [{
						"name": "",
						"data": []
					}]
				}
				//时间
				temp.categories = this.$getRecentDateArray(7)
				//数据
				//解除对象指向同一块内存(拷贝)
				temp.series[0].data = this.historyData.test
				let testDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateTestArea(testDataTemp)

				temp.series[0].data = this.historyData.homework
				let homeworkDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateHomeworkArea(homeworkDataTemp)

				temp.series[0].data = this.historyData.activity
				let activityDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateActivityArea(activityDataTemp)
			},
			//导航到详情页面
			navData(index) {
				this.updateHomeworkDetail(this.pageData[this.current].detail.data)
				uni.navigateTo({
					url: `/subpkg/detaillist/detaillist?index=${index}`
				})
			}

		}
	}
</script>

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

	.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: 95%;
			// background: linear-gradient(to right, #ff95007a,#ff8419);
			border-radius: $card-border-radius;

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

			.card-subtitle {
				font-size: 28rpx;
				color: #FFF;
			}

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

			.image {
				position: relative;
				right: -30rpx;
				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: 20rpx 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;
					}
				}
			}
		}
	}

	//图表
	.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;
	}
</style>
