<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 :foot-border-top="false" padding="0" margin="10px" borderRadius="40" v-for="(item, index) in tableList" :key="index"
			 class="card-container" @click="goToDetail(item)">
				<view class="card-content" slot="head" style="display: flex;">
					<view class="card-img">
						<u-avatar :src="item.url" size="100"></u-avatar>
					</view>
					<view>
						<view class="card-title">{{item.name}}</view>
						<view class="card-info-text">手机号：{{item.phone}}</view>
						<view class="card-info-text">地址：{{item.address}}</view>
					</view>
				</view>
				<view class="card-content" slot="body">
					<view class="card-info-text">{{item.remark}}</view>
				</view>
				<view class="card-content" slot="foot" style="padding-top: 0;">
					<view class="card-info-text" style="text-align: right;">{{item.time}}</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.getExtraLessonsList, {
					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;

			.card-container {
				.card-content {
					padding: 10px 15px;
				}

				.card-img {
					width: 50px;
					height: 50px;
					margin-right: 10px;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.card-title {
					font-size: 14px;
					line-height: 20px;
				}

				.card-info-text {
					color: #999999;
				}
			}
		}
	}
</style>
