<template>
	<view class="homework-container">
		<!-- 头部区域 -->
		<top-box :timeStamp="timeStamp"></top-box>
		<view class="module-container">
			<view style="margin: 0 20rpx;">
				<u-tabs :list="list" :current="current" @change="changeModule"
					:activeStyle="{color: '#5b7cff',fontWeight: 'bold',transform: 'scale(1.04)',}"
					:inactiveStyle="{fontWeight: 'bold',transform: 'scale(1)'}" lineColor="#5b7cff" lineWidth="60">
				</u-tabs>
			</view>

			<!-- 详情头部卡片 -->
			<view class="module-box" v-for="(item,index) in card" :key="index" v-if="current == index">
				<view class="card" :style="{backgroundColor: `${item.color}`}">
					<view style="display: flex; flex-direction: column;">
						<text class="card-title">{{item.title}}{{item.num}}</text>
						<text class="card-subtitle">{{item.subtitle}}{{item.finish}}</text>
						<text class="card-subtitle">完成情况: {{item.level}}</text>
					</view>
					<view class="image" :style="{backgroundImage:`url(${item.image})`}"></view>
				</view>

				<view style="display: flex; align-items: center;">
					<view class="cut-off">{{item.detail.nav}}</view>
					<!-- <u-button text="获得报表" :plain="true" :hairline="true" shape="circle" size="small"></u-button> -->
				</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-column" :chartData="homeworkData.testData" :loadingType="4"
								:canvas2d='true' tooltipFormat='tooltipPercent' canvasId='canvans0980111' />
						</view>
						<view class="charts-box" v-if="current == 1">
							<qiun-data-charts type="fin-column" :chartData="homeworkData.homeworkData" :loadingType="4"
								:canvas2d='true' tooltipFormat='tooltipPercent' canvasId='canvans0933511' />
						</view>
						<view class="charts-box" v-if="current == 2">
							<qiun-data-charts type="fin-column" :chartData="homeworkData.activityData" :loadingType="4"
								:canvas2d='true' tooltipFormat='tooltipPercent' 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>
						<u-list>
							<u-list-item>
								<u-cell :title="`列表长度-${index + 1}`"></u-cell>
								<u-cell :title="`列表长度-${index + 1}`"></u-cell>
								<u-cell :title="`列表长度-${index + 1}`"></u-cell>
							</u-list-item>
						</u-list>
					</view>

					<view class="detail-box-item" style="height: 100%;">
						<view class="item-info">
							<view class="t-icon t-icon-daiban"></view>
							<view class="item-text">{{item.detail.title}}</view>
						</view>
						<u-swipe-action v-for="(msg,i) in item.detail.data" :key="i">
							<u-swipe-action-item :options="options1">
								<view class="swipe-action u-border-top u-border-bottom">
									<view class="swipe-action__content">
										<text class="swipe-action__content__text">{{msg.name}}</text>
									</view>
								</view>
							</u-swipe-action-item>
						</u-swipe-action>
					</view>
				</view>

			</view>


		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_chart', ['homeworkData', 'todayData']),
		},
		data() {
			return {
				//模块名
				list: [{
					name: '评测详情'
				}, {
					name: '作业详情'
				}, {
					name: '活动详情'
				}],
				//当前模块
				current: 0,
				//时间戳
				timeStamp: '',
				//卡片内容
				card: [{
					title: '今日评测数:' + '\xa0\xa0\xa0',
					num: 5,
					subtitle: '评测已完成:' + '\xa0\xa0\xa0',
					finish: 3,
					level: '良好',
					color: '#0080ff;',
					image: 'https://ouch-cdn2.icons8.com/gpV8ZT40juL5H5uR0cv7ptJaV0vbUu64ANLmkch6cr4/rs:fit:1289:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvNTE3/L2M0Zjg4MDUzLTMx/ZDUtNDlhZS05M2Nj/LWU4YWM3YTNjODAx/My5zdmc.png',
					detail: {
						nav: '评测信息',
						title: '评测列表',
						data: [{
								name: '评测数据1'
							}, {
								name: '评测数据2'
							}, {
								name: '评测数据3'
							}, {
								name: '评测数据4'
							}, {
								name: '评测数据5'
							}
						]
					}
				}, {
					title: '今日作业数:' + '\xa0\xa0\xa0',
					num: 3,
					subtitle: '作业已完成:' + '\xa0\xa0\xa0',
					finish: 3,
					level: '完美',
					color: '#ff8caf;',
					image: 'https://ouch-cdn2.icons8.com/XuAMXajgkDqsOY7cp6uY1LQivtTxahNZjWM1Qk2bfoY/rs:fit:1216:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvMzE4/LzdjYTU2NDM4LTc4/MTktNDVhNi1hMjZh/LTMyZWE5NDE4YzI5/My5zdmc.png',
					detail: {
						nav: '作业信息',
						title: '作业列表',
						data: [{
								name: '作业数据1'
							}, {
								name: '作业数据2'
							}, {
								name: '作业数据3'
							}
						]
					}
				}, {
					title: '今日活动数:' + '\xa0\xa0\xa0',
					num: 6,
					subtitle: '活动已完成:' + '\xa0\xa0\xa0',
					finish: 5,
					level: '优秀',
					color: '#f9c752;',
					image: 'https://ouch-cdn2.icons8.com/xrmiKHmKAqKegMFWYXXUHk6mqTXXTqoU0wsTFULoboQ/rs:fit:1002:912/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvNzcy/LzczYWVmZjhkLTk4/N2ItNDI2Ny04NmNk/LTA1NTI4YjhiMTIw/Ni5zdmc.png',
					detail: {
						nav: '活动信息',
						title: '活动列表',
						data: [{
								name: '活动数据1'
							}, {
								name: '活动数据2'
							}, {
								name: '活动数据3'
							}, {
								name: '活动数据4'
							}, {
								name: '活动数据5'
							}, {
								name: '活动数据6'
							}
						]
					}
				}],
				//历史数据
				historyData: {
					test: [90, 89, 98, 100, 50],
					homework: [10, 29, 38, 60, 50],
					activity: [70, 19, 28, 40, 60]
				},
				options1: [{
					text: '待办',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
			};
		},
		onLoad() {
			this.$getTimeStamp()
			this.saveToStudyChart()
		},
		//刷新页面
		onPullDownRefresh() {
			this.$getTimeStamp()
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			...mapMutations('m_chart', ['updateTestColumn', 'updateHomeworkColumn', 'updateActivityColumn']),
			//更改模块
			changeModule(index) {
				this.current = index.index
			},
			//记录到图表
			saveToStudyChart() {
				let temp = {
					categories: [],
					series: [{
						"name": "",
						"data": []
					}]
				}
				//时间
				temp.categories = this.$getRecentDateArray(5)
				//数据
				//解除对象指向同一块内存(拷贝)
				temp.series[0].data = this.historyData.test
				let testDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateTestColumn(testDataTemp)

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

				temp.series[0].data = this.historyData.activity
				let activityDataTemp = JSON.parse(JSON.stringify(temp))
				this.updateActivityColumn(activityDataTemp)

			}

		}
	}
</script>

<style lang="scss">
	.homework-container {

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

	.module-container {
		margin-top: -70rpx;

		.card {
			display: flex;
			justify-content: space-around;
			margin: 20rpx auto 20rpx auto;
			height: 250rpx;
			width: 96%;
			// background: linear-gradient(to right, #ff95007a,#ff8419);
			border-radius: $card-border-radius;

			.card-title {
				margin: 30rpx 0 20rpx 20rpx;
				font-size: 45rpx;
				font-weight: bold;
				color: #FFF;
			}

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

			.image {
				position: relative;
				top: -40rpx;
				right: -30rpx;
				height: 300rpx;
				width: 300rpx;
				background-size: contain;
				background-repeat: no-repeat;
				z-index: 2;
			}
		}

		.cut-off {
			font-size: 35rpx;
			font-weight: bold;
			color: #606266;
			margin-left: 40rpx;
		}

		.detail-box {
			display: flex;
			flex-flow: column wrap;
			justify-content: space-between;
			margin: 20rpx 0 20rpx 0;
			height: 700rpx;
			width: 100%;

			.detail-box-item {
				margin: 0 2%;
				height: 48%;
				width: 46%;
				background-color: #FFF;
				border-radius: $card-border-radius;

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

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

					.item-text {
						font-size: 30rpx;
						font-weight: bold;
						color: #3B4144;
						margin-left: 10rpx;
					}
				}
			}
		}

	}

	.charts-box {
		width: 100%;
		height: 250rpx;
		margin-bottom: 20rpx;
	}

	.t-icon {
		margin: 20rpx;
		width: 110rpx;
		height: 110rpx;
	}

	.u-page {
		padding: 0;
	}

	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}
</style>
