<template>
	<view class="page_view">
		<top-return color="#FFF" text="课程详情"></top-return>
		<!-- 背景 -->
		<view class="bg_card"></view>
		<!-- 页面标题内容 -->
		<view class="flex_cloumn">
			<view class="flex_baseline">
				<view class="content_title" style="font-size: 60rpx;">{{dayTime.split('月')[0]}}</view>
				<view class="content_title" style="margin-left: 10rpx;">月</view>
				<view class="content_title" style="font-size: 60rpx; margin-left: 10rpx;">{{dayTime.split('月')[1]}}
				</view>
				<view class="content_title" style="margin-left: 10rpx;">日</view>
				<view class="content_title" style="font-size: 60rpx;margin-left: 20rpx;">{{weekTime}}</view>
			</view>
			<view class="flex_baseline">
				<view class="content_subtitle" style="opacity: 0.8;">孩子今日共</view>
				<view class="content_subtitle" style="margin-left: 20rpx;font-size: 40rpx;transform: skew(-15deg);">
					{{classList.length}}
				</view>
				<view class="content_subtitle" style="margin-left: 20rpx;opacity: 0.8;">节课程</view>
			</view>
		</view>
		<!-- 天数选择 -->
		<scroll-view class="week_view" scroll-x="true" :scroll-with-animation="true" scroll-left="0">
			<view style="margin-top:20rpx;">
				<view v-for="(item,index) in weekList" :key="index"
					:class="isactive == index ? 'week_item_select' : 'week_item' " @click='chooseDay(index,item)'>
					<view class="item_box">
						<view class="_title">{{item.weekNum}}</view>
						<view class="_day">{{item.dayNum}}</view>
						<view class="tag_fill" v-if="isactive == index">
							<view class="tag_text" v-if="isactive == index && currentClassList.length != 0">{{currentClassList.length}} 节课</view>
							<view class="tag_text" v-if="isactive == index && currentClassList.length === 0">无课程</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>

		<!-- 课程表 -->
		<view class="card_view">
			<view class="card_item" style="width: 100%;">
				<view class="card_title">
					<view class="front_tag"></view>
					<view class="title">{{weekList[isactive].weekNum}}课程表</view>
				</view>
				<view class="class_list">
					<view class="class_item" v-for="(item,index) in currentClassList" :key="index">
						<view class="flex_row" style="justify-content: space-around;">
							<view class="class_item_title">{{item.name}}</view>
							<view class="tag" style="margin: 0;">
								<view class="tag_text">{{item.teacher}}</view>
							</view>
							<view class="class_item_subtitle" style="font-size: 24rpx;">{{item.timeFrame}}</view>
							<view class="class_item_title">{{item.time}}</view>
						</view>
					</view>
				</view>
				<view style="display: flex;flex-direction: column;height: 100%;align-items: center;margin-bottom: 50rpx;" v-if="!currentClassList">
					<view class="detail_image1" :style="{backgroundImage:`url(${image1})`}"></view>
					<view class="subtitle">当前选中日期暂无课程</view>
					<view class="subtitle" style="margin-top: 20rpx;">自由安排当前时间</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import MockData from '@/common/global_js/MockData.js'
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_children', ['classList'])
		},
		data() {
			return {
				dayTime: '',
				weekTime: '',
				isactive: 0,
				weekList: [{
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}, {
					weekNum: '',
					dayNum: '',
				}],
				currentClassList: '',
				weekClassData: MockData.classData,
				image1: 'https://ouch-cdn2.icons8.com/kO20yenejB3M-ElZUGZMtv3FCQ4fbFa7TbOKX5dGf0w/rs:fit:456:456/czM6Ly9pY29uczgu/b3VjaC1wcm9kLmFz/c2V0cy9zdmcvNDY4/LzU4OWMzZTZkLWQz/OTAtNGQ0My04NTgx/LTY4NDkzMGZiNWRk/ZC5zdmc.png',
			};
		},
		onLoad() {
			this.getPageData()
		},
		methods: {
			getPageData() {
				this.dayTime = (new Date()).format('M-d').replace('-', '月')
				this.weekTime = "星期" + "日一二三四五六".charAt(new Date().getDay());
				this.currentClassList = this.classList
				// 课程选择查看列表
				this.weekList.forEach(function(item, index) {
					var dateTime = new Date();
					dateTime = dateTime.setDate(dateTime.getDate() + index);
					let weekDateStr = "周" + "日一二三四五六".charAt(new Date(dateTime).getDay());
					item.weekNum = weekDateStr
					// if (index === 0) {
					// 	item.weekNum = '今日'
					// }
					item.dayNum = new Date(dateTime).format('d') + ' 号'
				});
			},
			chooseDay(index,item) {
				this.isactive = index
				for (const key in this.weekClassData) {
					if(key === item.weekNum){
						this.currentClassList = this.weekClassData[key]
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.week_view {
		white-space: nowrap;

		.week_item {
			display: inline-block;
			vertical-align: top;
			height: 150rpx;
			width: 130rpx;
			margin: 20rpx;
			padding: 20rpx;
			border-radius: $border-radius;
			background-color: #FFF;

			.item_box {
				width: 100%;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-around;

				._title {
					font-size: 30rpx;
					color: #898b91;
				}

				._day {
					font-size: 40rpx;
					font-weight: bold;
					color: #505155;
				}
			}
		}

		.week_item_select {
			display: inline-block;
			vertical-align: top;
			height: 180rpx;
			width: 160rpx;
			margin: 20rpx;
			padding: 20rpx;
			border-radius: $border-radius;
			background-color: #FFF;
			border: 3px solid $title;

			.item_box {
				width: 100%;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-around;

				.tag_fill {
					border-radius: 6rpx;
					background-color: $title;
					padding: 5rpx 20rpx;

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

				._title {
					font-size: 36rpx;
					color: $title;
				}

				._day {
					margin-top: -10rpx;
					font-size: 50rpx;
					font-weight: bold;
					color: $title;
				}
			}
		}
	}

	.class_list {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin: 0 20rpx 20rpx 20rpx;

		.class_item {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			margin: 10rpx 0;
			padding: 10rpx;
			height: 100rpx;
			background-color: $page-color;
			border-radius: $border-radius;
			background: linear-gradient(135deg, #f3f4f9 21px, #FFF 22px, #FFF 24px, transparent 24px, transparent 67px, #FFF 67px, #FFF 69px, transparent 69px), linear-gradient(225deg, #f3f4f9 21px, #FFF 22px, #FFF 24px, transparent 24px, transparent 67px, #FFF 67px, #FFF 69px, transparent 69px)0 64px;
			background-color: rgba(0, 0, 0, 0);
			background-size: auto, auto;
			background-color: #f3f4f9;
			background-size: 64px 128px;

			&_title {
				font-size: 32rpx;
				font-weight: bold;
				color: $title;
			}

			&_subtitle {
				font-size: 30rpx;
				font-weight: bold;
				color: $subtitle;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			&_detail {
				margin-left: 40rpx;
				line-height: 30rpx;
				font-size: 26rpx;
				font-weight: bold;
				color: $subtitle;
			}
		}
	}

	.flex_cloumn {
		margin: 140rpx 0 0 50rpx;
		height: 170rpx;
		justify-content: space-around;

		.content_title {
			font-size: 35rpx;
			font-weight: bold;
			transform: skew(-15deg);
			color: #FFF;
			z-index: 2;
		}

		.content_subtitle {
			font-size: 35rpx;
			color: #FFF;
			z-index: 2;
		}
	}
	.detail_image1 {
		width: 500rpx;
		height: 600rpx;
		background-size: 100%;
		background-repeat: no-repeat;
		z-index: 51;
	}
</style>
