<template>
	<view class="app">
		<view class="app-body">
			<!--关键词搜索-->
			<view class="sreach fx-r fx-bc fx-ac">
				<image class="icon" src="/static/img/tb-seach.png"></image>
				<input type="text" v-model="keyword"  placeholder="请输入用户昵称/用户ID" placeholder-style="color: #B3B3B3;" />
				<view class="fx-g1"></view>
				<view class="search-btn"  @tap="tapSerach">搜索</view>
			</view>
		</view>
		
		<scroll-view scroll-y class="scroll" :style="'height: calc(100vh - ' + hFoot + 'px  - 60px);'"  @scrolltolower="loadMoreData">
			<view class="sc-body">
				<view class="item" v-for="item in listAr">
					<view class="info fx-r">
						<view class="nickname">{{ item.nickname }}</view>
						<view class="mobile">{{ item.mobile }}</view>
					</view>
					
					<view class="info fx-r">
						<view class="id">数量： <text style="color: red;font-weight: bold;margin-right: 2px;">{{ item.count }}</text> 单</view>
					</view>
					
					<view class="info fx-r">
						<view class="id">ID号：{{ item.uid }}</view>
						<view class="fx-g1"></view>
						<view class="changci">场次：{{ item.action_name }}</view>
					</view>
					
					<view class="infos fx-r">
						<view class="time">预约时间:<text>{{ item.create_time }}</text></view>
						
					</view>
					
				</view>
				
				<view v-if="listAr.length > 0">
					<view class="loading fx-r fx-ac fx-bc" v-if="page.isFrite && !page.isFoot">
						<image src="/static/img/xloading.png"></image>
						<text>正在载入更多...</text>
					</view>
					<view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
				</view>
				
				<view v-if="listAr.length == 0 && isFirst">
					<u-empty
								mode="data"
								icon="/static/img/no-empty.png"
							></u-empty>		
				</view>
				
			</view>
		</scroll-view>
		
		
		
	</view>
</template>

<script>
	import {mapState,mapMutations } from 'vuex';
	export default {
		computed: mapState(['user']),
		data() {
		    return {
				isFirst:false,
				listAr:[],
				keyword : "",
				id : 0,
				hFoot : 0,
				page:{
					isFirst:false,
					isLoad:false,
					isFoot:false,
					page:1
				},
		    }
		}, 
		onLoad(options) {
			this.id = options.id || 0;
			this.initView();
			// #ifdef H5
				this.hFoot = 60;
			// #endif
		},
			 
		methods: {
			...mapMutations(['checkUserLogin']),
			/**
			 * 加载基础配置
			 */
			initView:function(){
				this.getData(true);
				
			},	
			/**
			 * 获取数据
			 */
			getData:function(isPull = false){
				if(this.page.isLoad) return;
				this.page.isLoad = true;
				if(isPull) {
					this.page.page = 1;
					this.page.isLoad = false;
					this.page.isFoot = false;
				}
				uni.showLoading({ title: '获取数据中..' });
				var post = {};
				post.page = this.page.page;
			
				this
					.request
					.post("gzBooking",{
						keyword : this.keyword,
						page : this.page.page,
						id  : this.id
					})
					.then(res => {
						uni.hideLoading();
						this.page.isFirst = true;
						this.page.isLoad = false;
						this.isFirst = true;
						if(isPull) {
							this.listAr = res.data.list;
						} else {
							this.listAr = this.listAr.concat(res.data.list);
						}
						//是否到底
						if(res.data.list.length != res.data.pageSize) {
							this.page.isFoot = true;
						} 
					})
					.catch((res)=>{
						console.log(res);
						uni.hideLoading();
						uni.showModal({title: '系统提示',content: '加载失败，返回在尝试',showCancel: false});
					});
			},
			
			tapSerach:function(){
				this.getData(true);
			},
			
			loadMoreData:function() {
				if(this.page.isFoot || this.page.isLoad) {
					return;
				}
				this.page.page ++;
				this.getData();			
			},
			
	},
}
</script>	


<style lang="scss">
	.app-body{
		padding: 0px 20rpx;
	}
	.sreach{
		background: #fff;
		margin:20rpx 0;
		border-radius: 32rpx;
		padding: 16rpx 32rpx;
		.icon{
			width: 46rpx;
			height: 46rpx;
		}
		input{
			width: calc(100% - 46rpx - 16rpx - 50px);
			font-size: 16px;
		}
		.search-btn{
			font-size: 14px;
			color: #FF4C4C;
		}
	}
	
	.sc-body{
		padding: 20rpx;
		.item{
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 26rpx 44rpx;
			margin-bottom: 10px;
			.info{
				margin-bottom: 10rpx;
				.nickname{
					font-weight: bold;
					font-size: 32rpx;
					color: #303133;
				}
				.mobile{
					font-weight: 500;
					font-size: 30rpx;
					color: #999999;
					margin-left: 10px;
				}
				.id{
					font-weight: 500;
					font-size: 26rpx;
					color: #666666;
				}
				.changci{
					font-weight: 500;
					font-size: 26rpx;
					color: #666666;
					text{
						color: #333333;
					}
				}
				
			}
			.infos{
				margin-top: 10px;
				border-top: 1px solid #f1f1f1;
				padding-top: 6px;
				.time{
					font-size: 14px;
					color: #666;
				}
			}
		}
	}
	
</style>