<template>
	<view class="container">
		<image class="cbg" src="../../static/common_bg.png"></image>
		<scroll-view :scroll-y="true" @scrolltolower="scrollGet" class="list">
			<image @click="goBook" class="list-img" src="../../static/mybook-top.png"></image>
			<view v-if="hasData" style="padding-bottom: 60rpx;">
				<view class="list-item" @click="toDetail(item.id)" v-for="item in book_list">
					<view class="list-item-top">
						<view style="display: flex;justify-content: space-between;align-items: center;">
							<image 
							:src="item.appointment_config.name==='车辆到闸'?'../../static/mybook-icon2.png':'../../static/mybook-icon2.png'">
							</image>
							{{item.appointment_config.name==='车辆到闸'?'车辆预约':'场地预约'}}
						</view>
						<view>
							<text :class="{'success':item.status===1,'warn':item.status>1}">{{item.status_text}}</text>
						</view>
					</view>
					<view class="list-item-middle">
						<view>
							<image src="../../static/mybook-icon3.png" style="width:24rpx;height: 24rpx;"></image>
							{{item.date}} {{formatTime(item.start_time)}}-{{formatTime(item.end_time)}}
						</view>
						<view>
							<image src="../../static/mybook-icon4.png" style="width:20rpx;height: 26rpx;"></image>
							{{item.appointment_config.name}}
						</view>
						<view>
							<image src="../../static/mybook-icon5.png"  style="width:21rpx;height: 23rpx;"></image>
							{{item.content?item.content:''}}
						</view>
					</view>
					<view class="list-item-bottom">
						<text @click.stop="cancelBook(item.id)" v-if="item.status<2">取消</text>
						<text v-if="item.status<2">|</text>
						<text>查看</text>
					</view>
					
				</view>
			</view>
			<view class="nodata" v-else>
				<u-empty mode="data"></u-empty>
			</view>

		</scroll-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 ''
				}
			},
			cancelBook(){
				
			},
			toDetail(id) {
				uni.navigateTo({
					url: '/packages/mybook/detail?id=' + id
				})
			},
			goBook(){
				uni.switchTab({
					url:'/pages/book/index'
				})
			}
		}

	}
</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;
			padding: 30rpx 0;
			// overflow: scroll;
			// padding-bottom: 200rpx;
			position: relative;
			top: 0;
			left: 0;

			overflow: scroll;

			&-img {
				width: calc(100% - 60rpx);
				height: 125rpx;
				display: block;
				margin: 0 auto;
			}

			&-item {
				margin: 30rpx;
				padding: 30rpx;
				background-color: #fff;
				border-radius: 10rpx;
				&-top{
					font-size: 32rpx;
					color:#b08c6c;
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom:1rpx solid #ddd;
					padding-bottom: 30rpx;
					image{
						width:37rpx;
						height:37rpx;
						margin-right:10rpx;
					}
					text{
						font-size: 24rpx;
						color:#fff;
						padding:5rpx 20rpx;
						display: inline-block;
						border-radius: 28rpx 0 28rpx 28rpx;
						background-color: #bf976e;
					}
					.success{
						background-color: #00b318;
					}
					.warn{
						background-color: #999;
					}
				}
				&-middle{
					padding:30rpx 0;
					padding-bottom:10rpx;
					border-bottom:1rpx solid #ddd;
					&>view{
						display: flex;
						align-items: center;
						margin-bottom:20rpx;
						image{
							margin-right:10rpx;
						}
					}
				}
				&-bottom{
					text-align: right;
					padding-top:30rpx;
					color:#b08c6c;
					text{
						margin-left:20rpx
					}
				}
			}
		}
	}
</style>