<template>
	<view class="content">
		<u-card title="签到记录" sub-title="查看更多" :show-foot="false" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle"
		 @head-click="getSignInList">
			<view class="signIn-box" slot="body">
				<view class="signIn-col" v-for="(item, index) in classInfo.signInList" :key="index">
					<u-icon name="bookmark" color="#666666" size="64" v-if="!item.status"></u-icon>
					<u-icon name="bookmark-fill" :color="mainColor" size="64" v-else></u-icon>
					<view class="signIn-date">{{item.date}}</view>
				</view>
			</view>
		</u-card>
		<u-card title="成长经历" :show-foot="false" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle">
			<u-cell-group slot="body" :border="false" style="padding: 0px;">
				<u-cell-item :title="(item.type? '家长' : '教练') + '-' + item.name" :value="item.time" :label="item.content" v-for="(item, index) in classInfo.growList"
				 :key="index" :arrow="false" :title-style="cellTitleStyle"></u-cell-item>
			</u-cell-group>
		</u-card>
		<view class="handle-fix-box">
			<u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="goToCourseForm()">填写历程</u-button>
		</view>
		<u-calendar v-model="signInShow" mode="date" :active-bg-color="mainColor" btn-type="error" availableText="未签到"
		 activeText="已签到" :available="availableList" :activeList="activeList" :handleStatus="false"></u-calendar>
		<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: {
					growList: [],
					signInList: [],
				},
				signInShow: false,
				availableList: [],
				activeList: [],
				cardStyle: {
					fontWeight: 'bold'
				},
				cellTitleStyle: {
					fontSize: '14px',
					fontWeight: 'bold',
				},
			}
		},
		onLoad(options) {
			this.classId = options.id
		},
		onShow() {
			this.initialize()
		},
		onPullDownRefresh() {
			this.initialize()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 500)
		},
		methods: {
			//  获取初始化数据
			initialize() {
				NET.request(API.getMemberClassDetail, {
					id: this.classId
				}, 'POST').then(res => {
					this.classInfo = res.data
				}).catch(error => {
					this.$refs.uTips.show({
						title: error.message,
						type: 'warning',
					})
				})
				NET.request(API.getAllLeaveList, {
					id: this.classId
				}, 'POST').then(res => {
					this.availableList = res.data.filter(site => site.status == 0).map(site => {
						return site.lastDate
					})
					this.activeList = res.data.filter(site => site.status == 1).map(site => {
						return site.lastDate
					})
				}).catch(error => {
					this.$refs.uTips.show({
						title: error.message,
						type: 'warning',
					})
				})
			},
			getSignInList(index) {
				this.signInShow = true
			},
			//  跳转历程表单
			goToCourseForm() {
				uni.navigateTo({
					url: '/pagesMember/courseForm?id=' + this.classId
				});
			},
		},
	}
</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;

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

			.signIn-col {
				width: 40px;
				text-align: center;

				.signIn-date {
					margin-top: 5px;
					font-size: 10px;
					text-align: center;
				}
			}
		}

		/deep/.u-cell {
			padding: 26rpx 0;
		}
	}
</style>
