<template>
	<view class="page-prebook-list">
		<view class="nav">
			<view :class="'item'+(userSelectIndex==0?' active':'')" @click="selectUser(0)">全部</view>
			<view :class="'item'+(userSelectIndex==(key+1)?' active':'')" v-for="(item,key) in vistors" @click="selectUser(key+1)">{{item.name}}</view>
		</view>
		<pre-book-list class="preg-books" :dataList="bookList"></pre-book-list>
	</view>
</template>

<script>
	import preBookList from '@/components/preBookList.vue'
	export default {
		data() {
			return {
				userSelectIndex:0,
				vistors:false,
				bookList:[]
			}
		},
		components:{
			preBookList
		},
		onShow(){
			this.getVisitors()
		},
		methods: {
			selectUser(key){
				this.userSelectIndex = key
				this.getBookData()
			},
			getBookData() {
				var param = new Object()
				param.page = 1
				param.limit = 10000
				if(this.userSelectIndex-1 >= 0){
					param.visitor_id = this.vistors[this.userSelectIndex-1].id
					console.log(this.vistors)
				}else{
					param.visitor_id = '0'
				}
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				var timerobj = setTimeout(function(){
					uni.hideLoading()
				}, 3000)
				this.$http.req('user/get_appoints', param, 'POST', true).then(data=>{
					clearTimeout(timerobj)
					uni.hideLoading()
					if(data == -1) return
					this.bookList = data;
					// if(this.userSelectIndex === 0){
						// this.vistors = JSON.parse(JSON.stringify(data))
					// }
				});
			},
			getVisitors() {
				var param = new Object()
				param.page = 1
				param.limit = 10000
				this.$http.req('user/get_visitors', {}, 'GET').then(data=>{
					if(data == -1) return
					this.vistors = data
					this.getBookData()
				});
			},
			pageInit() {

			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-prebook-list{
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		overflow-y: auto;
		background: #F8F8F8;
		.nav{
			width: 100%;
			display: flex;
			height: 132rpx;
			display: flex;
			box-sizing: border-box;
			overflow-x: auto;
			align-items: center;
			padding: 0 18rpx;
			column-gap: 20rpx;
			.item{
				width: auto;
				flex-shrink: 0;
				padding: 0 20rpx;
				height: 60rpx;
				line-height: 60rpx;
				background: rgba(201,203,209,0.25);
				border-radius: 30rpx;
				box-sizing: border-box;
				font-size: 24rpx;
				color: #616266;
				min-width: 136rpx;
				text-align: center;
				&.active{
					border: 1rpx solid #5BD07A;
					color: #58CA7F;
					background: #F8FFF7;
				}
			}
		}
		.preg-books{
			width: 714rpx;
			margin: 0 auto;
		}
	}
</style>
