<template>
	<view class="box u-skeleton">
		<u-skeleton :loading="loading" :animation="true"></u-skeleton>
		<view class="top">
			<u-search shape="round" :action-style="styobj" height="80" :clearabled="false" placeholder="请输入实验室名称"
				@custom="custom" @search="search"></u-search>
		</view>
		<view style="padding-top: 68px;display: flex;flex-direction: column;width: 100%;">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="list-top">
					<text class="txt1">{{item.name}}</text>
					<view>
						<image src="/static/image/record/user.png" mode="" style="width: 16px;height: 16px;"></image>
						<text style="padding-left: 2px;">{{item.max_student_nums}}人</text>
					</view>
				</view>
				<view class="list-bottom">
					<view @click="whRecord(item.id)">
						<text>维护记录</text>
					</view>
					<view class="heng">
					</view>
					<view @click="lookTable(item)">
						<text>查看课表</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="statuss " :load-text="loadText" icon="true" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				styobj: {
					'width': '66px',
					'height': '32px',
					'background': '#3665FF',
					'border-radius': '20px',
					'opacity': '1',
					'display': 'flex',
					'align-items': 'center',
					'justify-content': 'center',
					'color': 'white',
					'margin-left': '-70px',
					'font-size': '14px',
					'z-index': '2'
				},
				list: '',
				name: '',
				statuss: 'loadmore',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				meta: '',
				page: 1,
				loading: true
			}
		},
		methods: {
			whRecord(id) {
				uni.navigateTo({
					url: '/pages/laboratory/whRecord?id=' + id
				})
			},
			//查看课表
			lookTable(item) {
				uni.navigateTo({
					url: '/pages/laboratory/table?id=' + item.id + '&room_name=' + item.name
				})
			},
			custom(e) {
				this.name = e;
				this.lists()
			},
			search(e) {
				this.name = e;
				this.lists()
			},
			lists() {
				this.$u.get('school/room?page=1&name=' + this.name).then(res => {
					console.log(res)
					this.list = res.data.list;
					this.loading = false;
					this.meta = res.data.meta.pagination;
					if (res.data.list.length < 10) {
						this.statuss = 'nomore'
					}
				})
			}
		},
		onLoad() {
			this.lists()
		},
		onPullDownRefresh() {
			this.lists()
			this.page = 1;
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			this.statuss = 'loading';
			var page = this.page;
			if (page >= this.meta.total_pages) {
				this.statuss = 'nomore';
			} else {
				this.$u.get('school/room?page=' + Number(page + 1) + '&name=' + this.name).then(res => {
					console.log(res)
					this.list = this.list.concat(res.data.list);
					this.page = ++page;
				})
				this.statuss = 'loadmore';
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100vw;
		min-height: 100vh;
		background: #F5F5F5;
		padding-bottom: 30px;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		padding-left:15px ;
		padding-right: 15px;

		u-loadmore {
			margin-top: 10px;
		}

		.top {
			width: 100%;
			height: 64px;
			background: #FFFFFF;
			opacity: 1;
			background: white;
			display: flex;
			align-items: center;
			justify-content: center;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1;

			u-search {
				width: 343px !important;
				display: flex;
				align-items: center;
			}
		}

		.list {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			background: #FFFFFF;
			border-radius: 8px 8px 8px 8px;
			opacity: 1;
			display: flex;
			margin: 0 auto;
			margin-top: 12px !important;

			.list-top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				padding: 16px 12px 16px 12px;
				box-sizing: border-box;

				.txt1 {
					font-size: 16px;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #333333;
					width: 80%;
				}

				view {
					display: flex;
					align-items: center;
					font-size: 13px;
					font-weight: 400;
					color: #999999;
				}
			}

			.list-bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				border-top: 1px solid #F2F2F2;
				padding-top: 12px;
				padding-bottom: 12px;

				view {
					width: 49.5%;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 14px;
					font-weight: 400;
					color: #3665FF;
				}

				.heng {
					width: 0px !important;
					height: 20px !important;
					opacity: 0.2;
					border: 1px solid #3665FF;
				}
			}
		}
	}
</style>
