<template>
	<view class="content">
		<scroll-view scroll-y class="scroll-box" @scrolltolower="handleLoadMore" :refresher-enabled="true"
		 :refresher-triggered="triggered" :refresher-threshold="100" refresher-background="white" @refresherrefresh="onRefresh"
		 @refresherrestore="onRestore">
			<u-card :head-border-bottom="false" :foot-border-top="false" padding="0px" margin="10px" borderRadius="40" v-for="(item, index) in tableList"
			 :key="index" class="class-card" @click="goToDetail(item)">
				<view class="class-content" slot="head" style="padding-top: 10px;">
					<view class="class-name">{{item.name}}</view>
				</view>
				<view class="class-content" slot="body">
					<view class="class-info-text">
						<u-icon name="clock"></u-icon>
						{{item.classStartHours}}-{{item.classEndHours}}&nbsp;&nbsp;{{item.classStartDate}}-{{item.classEndDate}}
					</view>
					<view class="class-info-text">
						<u-icon name="map"></u-icon>
						{{item.address}}
					</view>
					<view class="class-info-text">
						<u-icon name="account"></u-icon>
						学员人数:<text>{{item.studentCount}}</text>人
					</view>
					<view class="class-info-text">
						<u-icon name="tags"></u-icon>
						教练回复:<text>{{item.coachTotalCount}}</text>条
					</view>
					<view class="class-info-text">
						<u-icon name="tags"></u-icon>
						学生评价:<text>{{item.stuTotalCount}}</text>条
					</view>
				</view>
			</u-card>
			<u-divider v-if="isOver" bg-color="transparent">没有更多了</u-divider>
		</scroll-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'
			])
		},
		data() {
			return {
				triggered: false,
				isOver: false,
				pageIndex: 1,
				tableList: [],
			}
		},
		onLoad() {
			this.getTableList()
		},
		onReady() {},
		methods: {
			//  下拉刷新
			onRefresh() {
				this.triggered = true
				this.isOver = false
				this.pageIndex = 1
				this.tableList = []
				this.getTableList()
			},
			//  重置下拉刷新状态
			onRestore() {
				this.triggered = 'restore'
				this.triggered = false
			},
			//  懒加载
			handleLoadMore() {
				if (!this.isOver) {
					this.pageIndex++
					this.getTableList()
				}
			},
			//  获取列表数据
			getTableList() {
				NET.request(API.getEvaluateList, {
					page: this.pageIndex,
					size: 10,
				}, 'POST').then(res => {
					this.triggered = false
					this.tableList = this.tableList.concat(res.data.row)
					this.isOver = res.data.row.length != 10
				}).catch(error => {
					this.triggered = false
					this.$refs.uTips.show({
						title: error.message,
						type: 'warning',
					})
				})
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pagesMain/evaluateDetail?id=' + item.id
				});
			}
		},
	}
</script>

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

	.content {
		width: 100%;
		float: left;

		.scroll-box {
			width: 100%;
			height: 100vh;
			box-sizing: border-box;
			padding-bottom: 10px;

			.class-card {

				.class-content {
					padding: 5px 15px;
				}

				.class-name {
					height: 20px;
					display: inline-block;
					font-weight: bold;
					font-size: 14px;
					line-height: 20px;
				}

				.class-info-text {
					color: #999999;
					margin-bottom: 5px;

					/deep/.u-icon {
						margin-right: 5px;
						font-size: 14px;
						color: #000000;
					}

					text {
						color: $mainColor;
					}
				}
			}
		}
	}
</style>