<template>
	<view class="content">
		<u-card title="剩余课时" :show-foot="false" title-size="32" margin="0px 0px 10px 0px" :head-style="cardStyle">
			<view slot="body">{{ residue }}</view>
		</u-card>
		<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 signInList" :key="index" @click="handleSignClick(item.id,index)">
					<u-icon name="bookmark" :color="signIndex === index ? '#41b0fe' : '#666666'" size="64" v-if="!item.status"></u-icon>
					<u-icon name="bookmark-fill" :color="signIndex === index ? '#41b0fe' : mainColor" size="64" v-else></u-icon>
					<view class="signIn-date">{{item.date}}</view>
				</view>
			</view>
		</u-card>
		<u-card v-if="Object.keys(rateRecordInfo).length && rateRecordInfo.userRemark" 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> -->
			<view slot="body">
				<u-rate :count="10" :current="rateRecordInfo.star" :size="40" :gutter="10" :active-color="mainColor" isClick></u-rate>
				<view class="rate-info">学生评价: {{ rateRecordInfo.userRemark }}</view>
				<view class="rate-info" v-if="rateRecordInfo.coachRemark">教练回复: {{ rateRecordInfo.coachRemark }}</view>
			</view>
		</u-card>
		<!-- <view class="handle-fix-box" v-if="Object.keys(rateRecordInfo).length"> -->
		<view class="handle-fix-box" v-if="Object.keys(rateRecordInfo).length && !rateRecordInfo.userRemark">
			<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: '',
				signIndex: 0,
				signInShow: false,
				// 签到记录
				signInList: [],
				availableList: [],
				activeList: [],
				rateRecordInfo: {},
				// 签到id
				recordId: 0,
				// 剩余课时数
				residue: 0,
				cardStyle: {
					fontWeight: 'bold'
				},
				cellTitleStyle: {
					fontSize: '14px',
					fontWeight: 'bold',
				},
			}
		},
		onLoad(options) {
			this.classId = options.id
		},
		onShow() {
			this.initialize()
			this.signIndex = 0
		},
		onPullDownRefresh() {
			this.initialize()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 500)
		},
		methods: {
			//  获取初始化数据
			initialize() {
				// 获取会员服务班级详情
				NET.request(API.getMemberClassDetail, {
					id: this.classId
				}, 'POST').then(res => {
					this.residue = res.data.residue
					this.signInList = res.data.signInList
					if(res.data.signInList.length) {
						const result = res.data.signInList
						if(result[0].status == 1) {
							this.recordId = id
							NET.request(API.getSignRemark, {id: id}, 'POST').then( res => {
									this.rateRecordInfo = { ...res.data }
								}
							)
						} else {
							this.rateRecordInfo = {}
						}
					}
				}).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',
					})
				})
			},
			// 根据签到时间显示不同评价
			handleSignClick(id,index) {
				this.signIndex = index
				if(id) {
					this.recordId = id
					NET.request(API.getSignRemark, {id: id}, 'POST').then( res => {
							this.rateRecordInfo = { ...res.data }
						}
					)
				} else {
					this.rateRecordInfo = {}
				}
			},
			getSignInList(index) {
				this.signInShow = true
			},
			//  跳转历程表单
			goToCourseForm() {
				uni.navigateTo({
					url: '/pagesMember/courseForm?id=' + this.recordId
				});
			},
		},
	}
</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;
		}
	}
	.rate-info {
		width: 100%;
		margin-top: 20rpx;
		margin-left: 5rpx;
		word-wrap: break-word;
	}
</style>
