<template>
	<view class="pageBgImg pad">
		<view class="searchBox">
			<searchRow placeholder="搜索学员姓名、学员手机号"></searchRow>
		</view>
		<view class="card">
			<view class="myClass">
				<view class="leftTxt">我的排课</view>
				<view class="leftBtn" @click="$goPage('/pages/recordEntry/operate/mySchedule/mySchedule')">去管理</view>
			</view>
		</view>
		<view class="tabs">
			<view class="tab" v-for="(item,index) in tabArr" :key="index" :class="{active: params.status==item.id}"
				@click="changeTab(item)">{{ item.text }}</view>
		</view>
		<view class="screen_row">
			<view class="selectItem" @click="showSubject=true">
				<view class="text oneRowText">{{screen.subject}}</view>
				<view class="downIcon">
					<u-icon name="arrow-down"></u-icon>
				</view>
			</view>
			<view class="selectItem" @click="showCar=true">
				<view class="text oneRowText">{{screen.car}}</view>
				<view class="downIcon">
					<u-icon name="arrow-down"></u-icon>
				</view>
			</view>
			<view class="selectItem" @click="showDatePicker=true">
				<view class="text">{{screen.timer}}</view>
				<view class="downIcon">
					<u-icon name="arrow-down"></u-icon>
				</view>
			</view>
		</view>

		<view class="list" v-if="list.length">
			<view class="card" v-for="(item,index) in list" :key="index">
				<appointItem-operate @click.native="$goPage('/pages/recordEntry/operate/detail/detail?id='+item.id)" :item="item"/>
			</view>
		</view>
		<!-- <nodata v-if="!list.length"></nodata> -->
		<view style="padding-bottom: 100rpx;" v-if="list.length">
			<u-loadmore :status="status" />
		</view>
		<nodata v-if="!list.length&&status=='nomore'"></nodata>
		
		<UserTab name ='实操训练'></UserTab>
		
		<u-datetime-picker
				:show="showDatePicker"
				mode="date"
				:closeOnClickOverlay="true"
				:visibleItemCount="4"
				:minDate="1587524800000"
				@confirm="confirmDatePicker"
				 @cancel="cancelDate"
				 cancelText="不限日期"
				 @close="showDatePicker=false"
		></u-datetime-picker>
		
		<!-- <u-picker :show="showC" :columns="carArr" keyName="lab" @confirm="confirmCar" @cancel="showCar=false"></u-picker> -->
		<u-picker :show="showCar" :columns="carColumns" keyName="licnum" @confirm="confirmCar" @cancel="showCar=false" :closeOnClickOverlay="true" @close="showCar=false"></u-picker>
		<u-picker :show="showSubject" :columns="subjectTxt" keyName="lab" @confirm="confirmSubject" @cancel="showSubject=false" :closeOnClickOverlay="true" @close="showSubject=false"></u-picker>
	</view>
</template>

<script>
	import { bookingMasterPage, carPage} from '@/config/api.js'
	export default {
		data() {
			return {
				tabArr: [{
						text: '待上课',
						id: 0
					},
					{
						text: '已完成',
						id: 2
					},
					{
						text: '已取消',
						id: 9
					},
				],//状态：0：未签到，1：已签到，2：已签退，3：已过期，9：已取消,示例值(2)	
				currentTab: 1,
				screen: {
					subject: '训练科目',
					car: '预约车辆',
					timer: '预约时间'
				},
				status: 'loading',
				subjectTxt: [
					[
						{lab: '不限', id: 0},
						{lab: '科目二', id: 2},
						{lab: '科目三', id: 3},
					]
				],
				// :0：不限；2：科目二；3：科目三
				showDatePicker: false,
				showCar: false,
				showSubject: false,
				
				carColumns: [],
				params: {
					pageNo: 1,
					pageSize: 20,
					status: 0,
					carNumber: '',
					bookingTime: []
				},
				list: []
			}
		},
		onLoad() {
			console.log('我的页面')
			this.params.coachId = this.vuex_coachId
			this.carPageFn()
			// this.bookingMasterPageFn()
		},
		onShow() {
			uni.hideTabBar();
			this.initList()
		},
		onPullDownRefresh() {
			this.initList()
		},
		onReachBottom() {
			if(this.list<this.total) {
				this.initList()
			}
		},
		methods: {
			cancelDate() {
				this.showDatePicker=false
				this.params.beginTime = ''
				this.params.endTime = ''
				this.screen.timer = '预约时间'
				this.initList()
			},
			async initList() {
				this.status = 'loading'
				this.list = []
				this.params.pageNo = 1
				this.bookingMasterPageFn()
			},
			async bookingMasterPageFn() {
				console.log(this.params)
				let obj = Object.assign({},this.params)
				console.log(obj.carNumber)
				if(obj.carNumber=='不限') delete obj.carNumber
				const {data: res } = await bookingMasterPage(obj)
				// uni.$u.http.get('/api/admin-api/business/booking/master/page', this.params ).then(res => {
				//  console.log(res)
				// }).catch(err => {
				
				// })
				this.params.pageNo ++
				this.list.push(...res.list)
				this.total = res.total
				if(this.list.length>=this.total) this.status = 'nomore'
				console.log(res)
			},
			changeTab(item) {
				this.params.status = item.id
				this.initList()
			},
			confirmDatePicker(val) {
				this.showDatePicker = false
				this.screen.timer = uni.$u.date(val.value, 'yyyy-mm-dd')
				this.params.beginTime = this.screen.timer+ ' 00:00:00'
				this.params.endTime = this.screen.timer+ ' 23:59:59'
				// this.params.bookingTime = [startTimer, endTimer]
				this.initList()
			},
			confirmCar(val) {
				let item = val.value[0]
				this.screen.car = item.licnum
				this.params.carNumber = item.licnum
				this.showCar = false
				this.initList()
			},
			confirmSubject(val) {
				let item = val.value[0]
				this.screen.subject = item.lab
				this.params.subject = item.id
				this.initList()
				this.showSubject = false
			},
			async carPageFn() {
				let obj = {
					pageNo: 1,
					pageSize: 40,
					schoolId: this.vuex_schoolId,
					coachId: this.vuex_coachId
				}
				const {data: res} = await carPage(obj)
				res.list.unshift({licnum: '不限', id: 0})
				this.carColumns = [res.list]
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pageBgImg {
		.searchBox {
			padding: 140rpx 0 24rpx 0;
		}
		.card {
			padding: 0 28rpx;
			margin-bottom: 20rpx;
			.myClass {
				height: 108rpx;
				display: flex;
				justify-content: space-between;
				padding: 0 10rpx;
				align-items: center;
				.leftTxt {
					font-size: 32rpx;
					font-weight: 500;
				}
				.leftBtn {
					width: 192rpx;
					height: 60rpx;
					background: $themC; border-radius: 8rpx;
					line-height: 60rpx;
					text-align: center;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
		}
		.tabs {
			height: 72rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			display: flex;
			line-height: 72rpx;
			text-align: center;
			color: #ADADAD;
			margin: 24rpx 0;
			.tab {
				flex: 1;
				text-align: center;

				&.active {
					background: rgba(25, 137, 250, 0.1);
					border: 2rpx solid #1989FA;
					color: $themC;
					border-radius: 16rpx;
				}
			}
		}
		.screen_row {
			display: flex;
			margin-bottom: 24rpx;
			width: 100%;
			justify-content: space-between;
			.selectItem {
				display: flex;
				padding: 0 18rpx;
				border: 2rpx solid rgba(25,137,250,0.3);
				height: 60rpx;
				border-radius: 16rpx;
				background-color: #FFFFFF;
				line-height: 60rpx;
				align-items: center;
				width: 29%;
				.text {
					color: $themC;
					flex: 1;
					white-space: nowrap;
					text-align: center;
				}
				.downIcon {
					width: 24rpx;
				}
			}
		}

		.list {
			.card {
				appointitem-operate {}
			}
		}
	}
</style>