<template>
	<view class="main">
		<view class="blueBg">
			<!-- <topNavbar title="预约记录"></topNavbar> -->
			<view class="pad">
				<view class="searchBox">
					<searchRow placeholder="搜索学员姓名、学员手机号" @searchFn="searchFn"></searchRow>
				</view>
				<view class="tabs">
					<view class="tab" @click="changeTab(0)" :class="{active: params.writtenoffStatus==0}">待核销</view>
					<view class="tab" @click="changeTab(1)" :class="{active: params.writtenoffStatus==1}">已核销</view>
				</view>
			</view>
		</view>
		<view class="navs">
			<view class="nav" v-for="(item,index) in tabsList" :key="index" :class="{active: params.subject==item.id}" @click="changeNav(item)">{{ item.text }}</view>
		</view>
		<view class="pad">
			<view class="total_row">
				<view class="total"> <text  v-if="total">{{total}}条记录</text></view>
				<view class="screen" @click="showDate=true">
					<view class="text"><text v-if="params.beginTime||params.trainType">已</text> 筛选</view>
					<view class="icon">
						<image src="@/static/images/coach/screen.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="card" @click="goPage" v-for="(item,index) in list" :key="index">
				<appointItem :item="item"/>
			</view>
		</view>
		<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-popup :show="showDate" mode="bottom" :round="20" :closeable="true" :closeOnClickOverlay="true">
			<view class="popupBox">
				<view class="pad">
					<view class="car">
						<view class="h1">车型</view>
						<view class="car_row">
							<view class="carItem" @click="screenCarFn('C1')" :class="{active: screen.trainType=='C1'}">C1</view>
							<view class="carItem" @click="screenCarFn('C2')" :class="{active: screen.trainType=='C2'}">C2</view>
						</view>
					</view>
					<view class="car">
						<view class="h1" >日期</view>
						<view class="car_row border" @click="showDatePicker=true">
							<mySelect placeholder="请选择日期" :value="screen.screenDate"></mySelect>
							<u-icon name="arrow-down" :size="12" :color="'#ADADAD'" style="margin-left: 12rpx;"></u-icon>
						</view>
					</view>
					<view class="btn_row">
						<view class="btnBorder btn" @click="resetScreen">重置</view>
						<view class="btnBg btn" @click="screenSearch">确定</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		<u-datetime-picker
				:show="showDatePicker"
				mode="date"
				:closeOnClickOverlay="true"
				:minDate="1587524800000"
				@confirm="confirmDatePicker"
				 @cancel="showDatePicker=false"
				 @close="showDatePicker=false"
		></u-datetime-picker>
	</view>
</template>

<script>
	import { examSimulationPages } from '@/config/api.js'
	export default {
		data() {
			return {
				tabsList: [
					{id: 0, text: '全部'},
					{id: 2, text: '科目二'},
					{id: 3, text: '科目三'},
				],
				showDate: false,
				showDatePicker: false,
				params: {
					pageNo: 1,
					pageSize: 20,
					coachId: 0,
					writtenoffStatus:  0,
					subject: 0,
					studentName: '',
					studentPhone: ''
				},
				screen: {
					trainType: '',
					screenDate: ''
				},
				list: [],
				status: 'loading',
				total: 20
			}
		},
		created() {
			this.params.coachId = this.vuex_userInfo.user.coachId
			// this.params.deptId = this.vuex_userInfo.user.deptId
			// this.examSimulationPagesFn()
			this.initList()
		},
		methods: {
			async examSimulationPagesFn() {
				let obj = Object.assign({},this.params)
				if(obj.subject==0) delete obj.subject
				const {data: res} = await examSimulationPages(obj)
				this.params.pageNo ++
				this.total = res.total
				this.list.push(...res.list)
				if(this.list.length>=this.total) this.status = 'nomore'
				console.log(res)
			},
			initList() {
				this.status = 'loading'
				this.list = []
				this.params.pageNo = 1
				this.examSimulationPagesFn()
			},
			changeTab(num) {
				this.params.writtenoffStatus = num
				this.initList()
				
			},
			changeNav(item) {
				this.params.subject = item.id
				this.initList()
			},
			goPage() {
				this.$goPage('/pages/recordEntry/examine/examineRecord/detail/detail')
			},
			confirmDatePicker(val) {
				this.screen.screenDate = this.$u.timeFormat(val.value, 'yyyy-mm-dd')
				this.showDatePicker = false
			},
			// 选择筛选日期
			selectDateClick(val) {
				console.log(val)
				this.showDate = false
			},
			screenCarFn(trainType) {
				this.screen.trainType = trainType
			},
			resetScreen() {
				this.screen.trainType = ''
				this.screen.screenDate = ''
			},
			// 筛选搜索
			screenSearch() {
				this.params.trainType = this.screen.trainType
				if(!this.screen.screenDate) {
					this.params.beginTime = ''
					this.params.endTime = ''
				}else {
					this.params.beginTime = this.screen.screenDate + ' 00:00:00'
					this.params.endTime = this.screen.screenDate + ' 23:59:59'
				}
				this.showDate = false
				this.initList()
			},
			searchFn(val) {
				if(uni.$u.test.mobile(val)) {
					this.params.studentPhone = val
					this.params.studentName = ''
				}else {
					this.params.studentName = val
					this.params.studentPhone = ''
				}
				this.initList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.popupBox {
		padding-bottom: 30rpx;
		.btn_row {
			padding-top: 20rpx;
			display: flex;
			justify-content: space-between;
			.btn {
				width: 48%;
			}
		}
		.car {
			margin-bottom: 20rpx;
			.h1 {
				line-height: 100rpx;
			}
			.car_row {
				display: flex;
				
				&.border {
					width: 300rpx;
					line-height: 70rpx;
					border: 1rpx solid #d8d8d8;
					border-radius: 10rpx;
					padding: 0 16rpx;
					justify-content: space-between;
				}
				.carItem {
					width: 130rpx;
					background: #f3f3f3;
					border-radius: 8rpx;
					text-align: center;
					line-height: 60rpx;
					color: #333;
					margin-right: 58rpx;
					&.active {
						background: $themC;
						color: #fff;
					}
				}
			}
		}
	}
	.main {
		width: 100%;
		min-height: 100vh;
		background: #f3f3f3;
		.blueBg {
			background: #1989FA;
			padding: 140rpx 0 20rpx 0;
		}
		.total_row {
			display: flex;
			justify-content: space-between;
			height: 82rpx;
			align-items: center;
			.total {
				font-size: 24rpx;
				color: #686B73;
				text-align: right;
				line-height: 82rpx;
			}
			.screen {
				display: flex;align-items: center;
				color: $themC;
				margin-left: 8rpx;
				font-size: 28rpx;
				.icon {
					width: 24rpx;
					height: 24rpx;
				}
			}
		}
		
		.card {
			padding: 0 20rpx;
		}
	}
	.searchBox {
		padding: 24rpx 0 20rpx 0;
	}
	.tabs {
		display: flex;
		width: 100%;
		height: 72rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		.tab  {
			flex: 1;
			text-align: center;
			line-height: 72rpx;
			color: #ADADAD;
			font-size: 28rpx;
			&.active {
				background: rgba(25,137,250,0.1);
				border-radius: 16rpx;
				border: 2rpx solid #1989FA;
				color: $themC;
				font-weight: 600;
			}
		}
	}
	.navs {
		display: flex;
		justify-content: space-between;
		color: #fff;
		font-size: 28rpx;
		padding: 0rpx 108rpx 0rpx 130rpx;
		color: $themC;
		background: #fff;
		height: 100rpx;
		.nav {
			line-height: 100rpx;
			&.active {
				font-weight: 500;
				position: relative;
				&::before {
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					bottom: 20rpx;
					content: '';
					width: 56rpx;
					height: 6rpx;
					background: $themC;
					border-radius: 3rpx;
				}
			}
		}
	}
</style>