<template>
	<view class="bg-white">
		<!-- 列表 -->
		<scroll-list ref="list" :option="option" @load="load" @refresh="refresh">
			<!-- 列表 -->
			<classroom-item v-for="(item, index) in list" :key="index" :data="item" />
		</scroll-list>
	</view>
</template>

<script>
import Api from '../../api/api.js';
import moment from 'moment';
import ClassroomItem from './classroom_item.vue'
export default {
	components: {
		ClassroomItem
	},
	data() {
		return {
			option: {
				size: 10,
				auto: true,
				loadDisabled: true
			},
			list: [],
			lastStartTime: '',
			page: 1
		};
	},
	computed: {
	},
	onReady() {},
	mounted() {
		
	},
	methods: {
		/// 初始化数据
		async requestData(isRefresh) {
			this.page = isRefresh ? 1 : this.page + 1
			var params = {
				"page": this.page,
				"rows": 10
			}
			var that = this
			Api.messageList(params).then( res => {
				if (res.code != 200) return;
				let data = res.data.content;
				var newList = []
				for (let i = 0; i < data.length; i++) {
					var item = data[i]
					var _startTime = moment(item.start_time).format('YYYY-MM-DD')
					item.isSection = that.lastStartTime != _startTime
					item.date = _startTime
					that.lastStartTime = _startTime
				}
				
				if (isRefresh) {
					that.list = data
					that.$refs.list.refreshSuccess({ list: that.list, total: res.data.totalSize });
				} else {
					that.list = [ ...that.list, ...data]
					this.$refs.list.loadSuccess({ list: this.list, total: res.data.totalSize });
				}
			})
		},
		// 刷新刷剧
		refresh(paging) {
			this.requestData(true)
		},
		load(paging) {
			this.requestData(false)
		},
	}
};
</script>

<style scoped>

</style>
