<template>
	<view class="content">
		<u-card :title="classInfo.name" :show-foot="false" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle">
			<view slot="body">
				<view class="class-info-text">
					<u-icon name="clock"></u-icon>
					{{classInfo.classStartDate}}&nbsp;&nbsp;{{classInfo.classStartHours}}&nbsp;&nbsp;{{classInfo.residue}}课时
				</view>
				<view class="class-info-text">
					<u-icon name="map"></u-icon>
					{{classInfo.address}}
				</view>
			</view>
		</u-card>
		<u-card :title="'学员信息(' + classInfo.studentSignList.length + ')'" title-size="32" margin="0px 0px 10px 0px"
		 :head-style="cardStyle">
			<u-grid :col="3" slot="body" :border="false">
				<u-grid-item v-for="(item, index) in classInfo.studentSignList" :key="index" :custom-style="gridCustomStyle" @click="goToStudentInfo(item)">
					<view class="class-student-col" :class="item.state ? 'student-active' : ''">
						{{item.name}}
						<u-icon name="bookmark" :color="mainColor" size="48"></u-icon>
					</view>
				</u-grid-item>
			</u-grid>
		</u-card>
		<u-card title="班级近况" :show-foot="false" title-size="32" margin="0px" :head-style="cardStyle">
			<view class="class-show-box" slot="body">
				<view v-for="(item, index) in classInfo.showList" :key="index" class="class-show-card">
					<u-image :src="item.url" mode="aspectFill" height="30vw" border-radius="10px"></u-image>
					<view class="class-show-name">{{item.name}}</view>
				</view>
			</view>
		</u-card>
		<view class="handle-fix-box">
			<u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="goToSignForm()">立即签到</u-button>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		computed: {
			...mapGetters([
				'mainColor',
				'customStyle',
			])
		},
		data() {
			return {
				classId: '',
				classInfo: {
					name: '',
					classStartDate: '',
					classStartHours: '',
					residue: '',
					address: '',
					studentSignList: [],
					showList: [],
				},
				cardStyle: {
					fontWeight: 'bold'
				},
				gridCustomStyle: {
					padding: '0 2px'
				}
			}
		},
		onLoad(options) {
			this.classId = options.id
			this.initialize()
		},
		onReady() {},
		onPullDownRefresh() {
			this.initialize()
		},
		methods: {
			//  获取初始化数据
			initialize() {
				NET.request(API.getClassDetail, {
					id: this.classId
				}, 'POST').then(res => {
					this.classInfo = res.data
					uni.stopPullDownRefresh();
				}).catch(error => {
					this.$refs.uTips.show({
						title: error.message,
						type: 'warning',
					})
				})
			},
			//  跳转学生详情
			goToStudentInfo(item) {
				uni.navigateTo({
					url: '/pagesMain/studentInfo?type=1&id=' + item.id + '&classId=' + this.classId
				});
			},
			//  跳转签到表单
			goToSignForm() {
				uni.removeStorageSync('signUserList')
				uni.navigateTo({
					url: '/pagesClass/signForm?id=' + this.classId + '&status=' + this.classInfo.signStatus
				});
			},
		},
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #f7f7f7;
		position: relative;
	}
</style>
<style lang="scss" scoped>
	@import "@/static/css/themes.scss";

	.content {
		width: 100%;
		float: left;
		padding-bottom: 60px;

		.class-info-text {
			color: #999999;
			line-height: 18px;

			u-icon {
				margin-right: 4px;
			}
		}

		.class-student-col {
			height: 28px;
			display: flex;
			padding: 0 10px;
			line-height: 28px;
			color: $mainColor;
			white-space: nowrap;
			border: 1px solid $mainColor;
			border-radius: 5px;

			/deep/u-icon {
				margin-left: 5px;
			}
		}

		.student-active {
			background-color: $mainColor;
			color: #FFFFFF;
		}

		.class-student-box {
			display: flex;
			justify-content: space-around;


		}

		.class-show-box {
			width: 100%;
			float: left;

			.class-show-card {
				width: calc(50% - 16px);
				margin: 0 8px 16px 8px;
				float: left;

				.class-show-name {
					width: 100%;
					text-align: center;
					line-height: 20px;
					font-size: 14px;
					margin-top: 5px;
				}
			}
		}
	}
</style>
