<template>
	<view>
		<nav-bar title="模考预约" class="nav"></nav-bar>
		<view class="tabs">
			<view class="tab" :class="{ active: index == 1 }" data-index="1" @click="tab(1)">
				<view>全部</view>
				<u-icon class="icon" :class="index ==1? 'animals':''" name="arrow-down"></u-icon>
			</view>
			<view class="tab" :class="{ active: index == 2 }" data-index="2">
				<view class="dateRange">
					<picker mode="date" :value="dateFrom" :start="startDate" :end="endDate" @change="bindDateFromChange">
						<view class="uni-input">{{dateFrom}}</view>
					</picker>
					- 
					<picker mode="date" :value="dateTo" :start="startDate" :end="endDate" @change="bindDateToChange">
						<view class="uni-input">{{dateTo}}</view>
					</picker></view>
				<u-icon class="icon" name="calendar"></u-icon>
			</view>
		</view>
		<view class="scroll">
			<scroll-view scroll-x="true" class="scroll-x" >
				<view class="content">
					<view class="scroll-tag active">AAAAAAAAAAAAAA</view>
					<view class="scroll-tag">bbbbbbbbbbbb</view>
					<view class="scroll-tag">ccccccccccc</view>
					<view class="scroll-tag">AAAAAAAAAAAAAA</view>
					<view class="scroll-tag">bbbbbbbbbbbb</view>
					<view class="scroll-tag">ccccccccccc</view>
					<view class="scroll-tag">AAAAAAAAAAAAAA</view>
					<view class="scroll-tag">bbbbbbbbbbbb</view>
					<view class="scroll-tag">ccccccccccc</view>
				</view>
				
			</scroll-view>
		</view>
		

		<view class="record">
			<view class="item" v-for="(item,index) in 5" :key="index">
				<view class="item__header">建设工程法规及相关知识建设工程</view>
				<view class="item__body">
					<view class="title">
						<image class="img" mode="widthFix" src="/pages5/static/time.png"></image>
						<text>考试时间</text>
					</view>
					<view class="desc">2022年4月15日（周五） 9:00-11:00 </view>
					<view class="btn" @click="appoint(item)" :class="{active: index % 2 == 0}">预约考试</view>
				</view>
			</view>
		</view>
		
		
		<view class="notice" @click="noticeModal=true">
			<u-icon class="icon" color="#fff" name="info-circle"></u-icon>
			<view class="text">模考说明</view>
		</view>

		<view class="modal" :style="{top:modalTop+'px'}" v-if="index == 1">
			<view class="content">
				<scroll-view scroll-y="true" style="height:100%">
					<view class="top" :class="activeIndex === 0 ? 'activesty' : ''" @click="testClick(3)">全部</view>
					<view class="list">
						<view class="item" :class="activeIndex == listItem.goodsId ? 'activesty' : ''" v-for="(listItem,listIndex) in list" :key="listIndex" @click="testClick(listItem)">
							{{ listItem.goodsName }}
						</view>
					</view>
				</scroll-view>
				
			</view>
			<view class="modal_wrap" @click="index = 0"></view>
		</view>
		
		<view class="notice_modal" :style="{top:modalTop+'px'}" v-if="index == 2">
			<view class="content">
				<scroll-view scroll-y="true" style="height:100%">
					<view class="top" :class="typeIndex === 0 ? 'activesty' : ''" @click="paperClick(3)">全部试卷类型</view>
					<view class="list">
						<view class="item" :class="typeIndex == listItem.paperId ? 'activesty' : ''" v-for="(listItem,listIndex) in list1" :key="listIndex" @click="paperClick(listItem)">{{ listItem.paperName }}</view>
					</view>
				</scroll-view>
			</view>
			<view class="modal_wrap" @click="index = 0"></view>
		</view>
		
		<u-popup class="notice__modal" v-model="noticeModal" mode="center" border-radius="24" :mask-close-able="false">
			<view class="notice__content">
				<view class="body">
					<scroll-view scroll-y="true" style="height:700rpx">
						<view class="content">
							<view class="bold text">模拟考试说明</view>
							
							<view>在您注册过程中,您需要完成我们的注册流程并通过点击“同意并继续”的形式在线签署以下协议及政策,请您务必仔细阅读、充分理解协议中的条款内容后再点击同意（尤其是以粗体标识的条款，因为这些条款可能会明确您应履行的义务或对您的权利有所限制）。
							</view>
							
						</view>
					</scroll-view>
				</view>
				<view class="footer">
					<view class="btn close" @click="noticeModal = false">我知道了</view>
				</view>
			</view>
		</u-popup>
		
		<view class="appoint__modal" v-if="appointModal" mode="center" border-radius="24" :mask-close-able="false">
			<view class="appoint__content">
				<view class="body">
						<image class="img" src="/pages5/static/img-header.png" mode="widthFix"></image>
						<view class="content">
							<view class="bold center">模拟考试说明</view>
							
							<view>
								您预约的模拟考试，安排如下： 
							</view>
							<view>
								<text class="bold text">模考场次： </text>
								<text class="text">2022年考前一建模拟考试</text>
							</view>
							<view>
								<text class="bold text">项目：   </text>
								<text class="text">一级建造师</text>
							</view>
							<view>
								<text class="bold text">专业：</text>
								<text class="text">市政专业</text>
							</view>
							<view>
								<text class="bold text">科目：</text>
								<text class="text">建设工程经济</text>
							</view>
							<view>
								<text class="bold text">考试时间：</text>
								<text class="text">2022年4月15日（周五）  9:00-10:00</text>
							</view>
							<view>请准时参加考试哦~</view>
							
						</view>
				</view>
				<view class="footer">
					<view class="btn close" @click="appointModal = false;openAppoint=true">我知道了</view>
				</view>
			</view>
		</view>
		
		<u-popup class="open__modal" v-model="openAppoint" mode="center" border-radius="24" :mask-close-able="false">
			<view class="open__content">
				<view class="body">
						<view class="content">
							<view class="bold center">开考提醒</view>
							
							<view class="center">
								开考前10分钟提醒入场，不错过实战机会
							</view>
							
						</view>
				</view>
				<view class="footer">
					<view class="btn close" @click="openAppoint = false">我知道了</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			openAppoint:false,
			appointModal:false,
			noticeModal:false,
			index: 0,
			list: [],
			list1: [],
			recordList: [],
			goodsData: {},
			param: {
				pageNum: 1,
				pageSize: 10
			},
			dateFrom:'',
			dateTo:'',
			isRepeat:false,
			total: 0,
			activeIndex: 0,
			typeIndex:0,
			itemIndex:'',
			modalTop:0,
			endDate:'',
		};
	},
	onLoad(option) {
		this.dateFrom = this.$method.timestampToTime(new Date().getTime() / 1000).replace(/-/g,'/');
		this.dateTo = this.$method.timestampToTime(new Date().getTime() / 1000).replace(/-/g,'/');
		this.endDate = this.$method.timestampToTime(new Date().getTime() / 1000).replace(/-/g,'/');
		
		uni.getSystemInfo({
			success:(e) => {
				let info = uni.createSelectorQuery().select(".nav");
				info.boundingClientRect((navData) => { //data - 各种参数
				
					let info = uni.createSelectorQuery().select(".tabs");
					info.boundingClientRect((tabData) => { //data - 各种参数
						this.modalTop = navData.height + tabData.height
						console.log(navData) // 获取元素宽度
						console.log(tabData) // 获取元素宽度
					}).exec()
				}).exec()
			}
		})
	},
	onPullDownRefresh() {
		let that = this;
		this.param = {
			pageNum: 1,
			pageSize: 10
		};
		this.getExamRecordList();
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 500);
	},
	onReachBottom() {
		if (this.recordList.length < this.total) {
			this.param.pageNum++;
			this.getExamRecordList();
		}
	},
	onShow() {
		if(this.isRepeat) {
			this.addRecord();
		} else {
			if(this.itemIndex !== '') {
				this.refreshByIndex();
			}
		}
		
	},
	methods: {
		refreshByIndex() {
			this.$api.examRecordGroupList({
				pageNum: this.itemIndex+1,
				pageSize: 1
			}).then(res => {
				this.$set(this.recordList,this.itemIndex,res.data.rows[0])
				this.itemIndex = ''
			});
		},
		
		appoint(item) {
			this.appointModal = true;
		},
		tab(index) {
			console.log(index,this.index)
			if(this.index == index) {
				this.index = 0;
				return;
			}
			this.index = index;
			console.log(this.index);
		},
		bindDateFromChange(e) {
			this.dateFrom = e.detail.value
		},
		
		bindDateToChange(e) {
			this.dateTo = e.detail.value
		}
	}
};
</script>
<style>
page {
	background: #eaeef1;
}
</style>
<style lang="scss" scope>
	.animals{
		transition: all 0.3s;
		transform: rotate(180deg);
	}
.tabs {
	position: fixed;
	left: 0;
	width: 100%;
	display: flex;
	z-index: 10;
	.tab {
		padding:0 18rpx;
		flex: 1;
		display: flex;
		justify-content: space-between;
		height: 80rpx;
		line-height: 80rpx;
		background: #ffffff;
		font-size: 24rpx;
		color: #999999;
		
		&:nth-of-type(1) {
			border-right:1px solid #EEEEEE;
		}
		
		.dateRange {
			display: flex;
			justify-content: space-between;
		}

		&.active {
			color: #333333;
			.icon{
				transform: rotate(180deg);
			}
		}
	}
}

.scroll {
	width:100%;
	margin-top:80rpx;
	.scroll-x {
		
		.content {
				display: flex;
				padding:16rpx;
				
				.scroll-tag {
					padding:11rpx 17rpx;
					background: #fff;
					color:#666666;
					margin-right:16rpx;
					border-radius:16rpx;;
					
					&.active {
						background: #007AFF;
						color:#fff;
					}
				}
		}
		
	}
}


.record {
	padding: 16rpx 16rpx;
	display: flex;
	flex-wrap: wrap;
	.item {
		margin-bottom: 16rpx;
		width:351rpx;
		background: #ffffff;
		border-radius: 16rpx;
		position: relative;
		
		&:nth-of-type(2n) {
			margin-left:16rpx;
			
		}

		&__header {
			padding:24rpx 16rpx;
			background: #F2F6FF;
			font-size: 30rpx;
			color:#007AFF;
			
			&::before {
				content:'';
				display: inline-block;
				width: 4rpx;
				height: 32rpx;
				background: #007AFF;
				margin-right:10rpx;
				vertical-align: middle;
			}
		}
		
		&__body {
			padding:16rpx;
			
			.title {
				font-size: 24rpx;
				color: #666666;
				line-height: 48rpx;
				
				.img {
					vertical-align: middle;
					width:32rpx;
				}
			}
			
			.desc {
				margin-top:10rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #666666;
				line-height: 36rpx;
			}
			
			.btn {
				margin-top:30rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				height: 64rpx;
				line-height: 62rpx;
				text-align: center;
				font-size: 28rpx;
					border: 1px solid #D9D9D9;
					color:#D9D9D9;
				
				&.active {
					
					border: 1px solid #007AFF;
					color:#007AFF;
				}
			}
		}
	}
}

.notice {
	position:fixed;
	right:0;
	top:50%;
	width: 48rpx;
	height: 200rpx;
	background: #52C41A;
	box-shadow: 0px 3rpx 16rpx 0rpx rgba(44, 121, 7, 0.5);
	border-radius: 24rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding:10rpx 0;
	
	.text {
		flex:1;
		color:#fff;
		text-align: center;
	}
}


.modal {
	bottom:0;
	z-index: 199999999;
	position: fixed;
	left: 0;
	width: 100%;

	.content {
		height:80%;
		overflow: hidden;
		position: relative;
		z-index: 10;
		background: #fff;
		padding: 8rpx 12rpx 20rpx;
		display: flex;
		flex-wrap: wrap;

		.top {
			margin: 0 auto;
			width: 726rpx;
			height: 80rpx;
			background: #f5f5f5;
			color: #666666;
			border-radius: 16rpx;
			text-align: center;
			line-height: 80rpx;
			font-size: 32rpx;
		}

		.list {
			width:100%;
			margin-top: 16rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.item {
				padding: 25rpx 20rpx;
				width: 49%;
				background: #f5f5f5;
				border-radius: 16rpx;
				font-size: 32rpx;
				color: #666666;
				margin: 8rpx 0;
			}
		}
	}

	.modal_wrap {
		position: absolute;
		left: 0;
		width: 100%;
		top: 0;
		height: 100%;
		background: rgba(0, 0, 0, 0.3);
	}
}


.notice__modal {
	.notice__content {
		width: 640rpx;
		height: 818rpx;
		background: #FFFFFF;
		display: flex;
		flex-direction: column;
		
		.body {
			flex:1;
			
			.content {
				padding:30rpx 40rpx 28rpx;
				line-height: 40rpx;
				font-size: 28rpx;
				color:#666;
				
				.bold {
					color:#333;
					font-size: 32rpx;
					font-weight: bold;
				}
				
				.center {
					text-align: center;
				}
			}
		}
		
		.footer {
			height:140rpx;
			border-top:1px solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.btn {
				margin:0 12rpx;
				width: 200rpx;
				height: 80rpx;
				color:#007AFF;
				font-size: 30rpx;
				text-align: center;
				line-height: 80rpx;
				background: #F5F5F5;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				
				
				&.close {
					color:#fff;
					width: 560rpx;
					height: 80rpx;
					background: #007AFF;
					border-radius: 40rpx 40rpx 40rpx 40rpx;
				}
			}
		}
	}
}

.open__modal {
	.open__content {
		width: 640rpx;
		background: #FFFFFF;
		
		.body {
			
			.content {
				padding:30rpx 40rpx 28rpx;
				line-height: 40rpx;
				font-size: 28rpx;
				color:#666;
				
				.bold {
					color:#333;
					font-size: 32rpx;
					font-weight: bold;
				}
				
				.center {
					text-align: center;
				}
			}
		}
		
		.footer {
			height:140rpx;
			border-top:1px solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.btn {
				margin:0 12rpx;
				width: 200rpx;
				height: 80rpx;
				color:#007AFF;
				font-size: 30rpx;
				text-align: center;
				line-height: 80rpx;
				background: #F5F5F5;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				
				
				&.close {
					color:#fff;
					width: 560rpx;
					height: 80rpx;
					background: #007AFF;
					border-radius: 40rpx 40rpx 40rpx 40rpx;
				}
			}
		}
	}
}

.appoint__modal {
	position:fixed;
	left:0;
	top:0;
	width:100%;
	height:100%;
	background:rgba(0,0,0,0.3);
	.img {
		width:280rpx;
		position:absolute;
		left:50%;
		margin-left:-140rpx;
		top:-70rpx;
	}
	.appoint__content {
		border-radius:20rpx;
		position:absolute;
		left:50%;
		top:50%;
		transform: translate3D(-50%,-50%,0);
		width: 640rpx;
		height: 867rpx;
		background: #FFFFFF;
		
		.body {
			position: relative;
			
			
			.content {
				padding:160rpx 40rpx 28rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				color:#666;
				
				.bold {
					color:#333;
					font-size: 32rpx;
					font-weight: bold;
				}
				
				.center {
					text-align: center;
				}
				
				
				.text {
					color:#666;
					font-size: 28rpx;
				}
			}
		}
		
		.footer {
			height:140rpx;
			border-top:1px solid #EEEEEE;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.btn {
				margin:0 12rpx;
				width: 200rpx;
				height: 80rpx;
				color:#007AFF;
				font-size: 30rpx;
				text-align: center;
				line-height: 80rpx;
				background: #F5F5F5;
				border-radius: 40rpx 40rpx 40rpx 40rpx;
				
				
				&.close {
					color:#fff;
					width: 560rpx;
					height: 80rpx;
					background: #007AFF;
					border-radius: 40rpx 40rpx 40rpx 40rpx;
				}
			}
		}
	}
}
.activesty {
	background: #007aff !important;
	color: #fff !important;
}
</style>
