<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="navWorkStats">
						<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="stat-card" style="background-color:#f9c752">
				<view class="card-column">
					<view class="flex-baseline">
						<text class="_title">今日作业</text>
						<text class="_title" style="margin-left: 20rpx;">{{workData.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="card-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="navWorkList" v-if="workData.length != 0">
						<view class="t-icon t-icon-fenlei"></view>
						<view class="title" style="color: #4169E1;margin-left: 10rpx;">作业列表</view>
					</view>
				</view>
				<view class="data-list">
					<view class="data-item"
						:style="{borderImage: none}"
						v-for="(item,index) in workData" :key="index" @click="navWorkReport(index)"
						v-if="workData.length != 0">
						<view class="flex-row" style="margin: 0 20rpx;">
							<view class="t-icon t-icon-workicon" style="width: 60rpx; height: 60rpx;"></view>
							<view class="flex-column">
								<view class="flex-row">
									<view class="item-title">{{item.work.name}}</view>
									<view class="tag-fill" style="background-color: #f9c752;">
										<view class="tag-text">{{item.work.scope === 'private' ? '个人':'学校'}}</view>
									</view>
									<view class="tag-fill"
										:style="{backgroundColor: item.work.progress === 'finish'? '#23b46c':'#ff5959'}">
										<view class="tag-text">{{item.work.progress === 'finish' ? '已完成' : '进行中'}}
										</view>
									</view>
								</view>
								<view class="row-desc">
									<view class="item-subtitle" style="font-size: 26rpx;font-weight: 400;">
										{{item.work.description}}
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="image-box" v-if="workData.length === 0">
						<view class="detail-image-none" :style="{backgroundImage:`url(${image1})`}"></view>
						<view class="subtitle">今日孩子暂无作业活动</view>
					</view>
				</view>
			</view>

			<view class="flex-column" 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="scroll-item" v-for="(item,index) in mistakeData" :key="index" @click="navWrongBook(index)">
				<view class="flex-column-book" :style="{backgroundColor: item.color}">
					<view class="book-shadow"></view>
					<view class="bg-title">{{item.subject}}</view>
					<view class="book-info">
						<view class="book-title">{{item.subject}}</view>
						<view class="flex-baseline" style="margin-left: auto;">
							<view class="book-subtitle" style="margin-left: 0;">收录错题</view>
							<view class="book-subtitle" style="font-size: 40rpx;">{{item.amount}}</view>
							<view class="book-subtitle">道</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_children', ['workData', 'mistakeData']),
			...mapState('m_chart', ['workChartData'])
		},
		data() {
			return {
				cardList: [{
					icon: 't-icon t-icon-gongzuo',
					title: '近期作业完成率',
					type: 'mini-column',
					data: ''
				}, {
					icon: 't-icon t-icon-renzheng',
					title: '近期作业得分率',
					type: 'mini-area',
					data: ''
				}],
				image: 'https://ouch-cdn2.icons8.com/AVOwJ9emg_ZOeHvQaunQAZlgeLsG-b1cGhiYvgoJ06g/rs:fit:912:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9wbmcvNTAw/LzI5YjU1YWQ4LWMw/YTEtNDE1MS1iYmQw/LWIyMDdhYmRkOTE0/Mi5wbmc.png',
				//完成情况
				performance: '',
				//完成数据
				finishData: '',
				finishRate: '',
				timeStamp: '',
				image1: 'https://image.meiye.art/pic_16314118207650DBDbJB8Ao3fE8_1bY3Fj',
			};
		},
		onLoad() {
			this.init()
		},
		//刷新页面
		onPullDownRefresh() {
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			//初始化
			init() {
				this.timeStamp = (new Date()).format("hh:mm")
				this.$initWork()
				this.getWorkChartData()
				this.getPerformance()
			},
			//获得作业图表信息
			getWorkChartData() {
				this.cardList[0].data = this.workChartData[0]
				this.cardList[1].data = this.workChartData[1]
			},
			//获得评判信息
			getPerformance() {
				if (this.workData.length != 0) {
					this.finishData = this.workData.filter(x => x.work.progress === 'finish')
					this.finishRate = (this.finishData.length * 100 / this.workData.length).toFixed(0)
					this.performance = this.finishData.length / this.workData.length >= 0.4 ?
						(this.finishData.length / this.workData.length >= 0.7 ? '优秀' : '良好') : '较差'
				} else {
					this.finishData = []
					this.finishRate = 0
					this.performance = '无作业'
				}
			},
			navWorkStats() {
				uni.navigateTo({
					url: '/subpkg/work/workStats'
				})
			},
			navWorkList() {
				let value = this.finishRate
				uni.navigateTo({
					url: `/subpkg/datalist/workList?value=${value}`
				})
			},
			navWorkReport(index) {
				uni.navigateTo({
					url: `/subpkg/datalist/workReport?index=${index}`
				})
			},
			navWrongBook(index){
				uni.navigateTo({
					url: `/subpkg/work/wrongBook?index=${index}`
				})
			}
		}
	}
</script>

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

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

	.flex-row {
		margin: 5rpx 20rpx;
	}
	.row-desc{
		margin: 5rpx 20rpx;
		display: flex;
		align-items: center;
		width: 510rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis
	}

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

	.image {
		top: -50rpx;
	}

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

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

	.circle-line3 {
		background-image: linear-gradient(to right, #f9c752, #f9c752), linear-gradient(0deg, #FFF -50%, rgba(255, 255, 255, 0.0));
	}

	.scroll-view-bottom {
		margin-top: -10rpx;

		.scroll-item {
			margin: 10rpx 20rpx 0 20rpx;
			display: inline-block;
			vertical-align: top;
			background-color: #FFF;
			border-radius: $border-radius;
			height: 300rpx;
			width: 240rpx;
			z-index: 55;
			box-shadow: 1px 0px 2px #ffffff, 2px -1px 2px #d2d2d2, 3px -2px 2px #b4b4b4;
		}
	}

	.flex-column-book {
		display: flex;
		flex-direction: column;
		height: 100%;
		width: 100%;
		overflow: hidden;
	}

	.bg-title {
		position: absolute;
		margin-top: 60rpx;
		margin-left: 80rpx;
		font-size: 130rpx;
		font-weight: 600;
		color: #FFF;
		opacity: 0.2;
		writing-mode: vertical-lr;
	}

	.book-shadow {
		position: absolute;
		margin-left: 20rpx;
		height: 300rpx;
		width: 20rpx;
		background-image: linear-gradient(to right, rgba(105, 105, 105, 0.1), rgba(255, 255, 255, 0.1));
	}

	.book-info {
		display: flex;
		flex-direction: column;
		height: 100rpx;
		width: 200rpx;
		margin: 160rpx 20rpx 40rpx 20rpx;
		justify-content: space-between;
		z-index: 99;
		.book-title{
			line-height: 60rpx;
			font-family: YSfont;
			color: #FFF;
			font-size: 60rpx;
			margin-left: auto;
		}
		.book-subtitle{
			font-size: 28rpx;
			color: #FFF;
			margin-left: 4rpx;
		}
	}
</style>
