<template>
	<view class="container">
		<image class="cbg" src="../../static/common_bg.png"></image>
		<view class="list" v-if="hasData">

			<scroll-view :scroll-y="true" @scrolltolower="scrollGet" style="height:100%">
				<view class="list-item" @click="toDetail(item.id)" v-for="item in book_list">
					<view>预约时间：{{item.date}} {{formatTime(item.start_time)}}-{{formatTime(item.end_time)}}</view>
					<view>预约地点：{{item.appointment_config.name}}</view>
					<view>预约事项：{{item.content}}</view>
					<view>预约状态：{{item.status_text}}</view>
				</view>
			</scroll-view>
		</view>
		<view class="nodata" v-else>
			<u-empty mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				hasMobile: false,
				hasData: true,
				current_page: 1,
				total_page: 0,
				load_status: '',
				book_list: [],
				course_status: [{
					type: 'primary',
					value: '未开始'
				}, {
					type: 'warning',
					value: '进行中'
				}, {
					type: 'info',
					value: '已结束'
				}]
			}
		},
		onLoad() {
			this.getBookList()

		},
		onReachBottom() {
			console.log("this.onReachBottom", this.current_page, this.total_page)
			
		},
		methods: {
			scrollGet(){
				if (!this.hasData) {
					return
				}
				this.current_page = this.current_page + 1
				if (this.current_page > this.total_page) {
					this.base.toast('没有更多了')
					return
				}
				this.getBookList()
			},
			async getBookList() {
				const res = await this.$u.api.scheduleIndex({
					page: this.current_page,
					page_size: 10
				})
				this.total_page = res.last_page
				if (res.data.length === 0 && this.current_page === 1) {
					this.hasData = false
				}
				this.book_list.push(...res.data)

			},
			formatTime(val) {
				if (val) {
					return this.$moment(val).format("HH:mm")
				} else {
					return ''
				}
			},
			toDetail(id) {
				uni.navigateTo({
					url: '/packages/mybook/detail?id=' + id
				})
			}
		}

	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100vh;
		overflow: hidden;
	
		.cbg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100vh;
		}
	
		.nodata {
			position: relative;
			top: 0;
			left: 0;
			height: 100vh;
		}
	
		.list {
			// height:100vh;
			// background: url("../../static/common_bg.png") no-repeat;
			// background-size: 100% 100%;
			height: 100vh;
			// overflow: scroll;
			// padding-bottom: 200rpx;
			position: relative;
			top: 0;
			left: 0;
	
			&-item {
				margin: 30rpx;
				padding: 30rpx;
				background-color: #fff;
			}
		}
	}
</style>