<template>
	<view class="web_box">
		<!-- <u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="我的考试" @leftClick="leftClick" :autoBack="true" bgColor="#fff">
		</u-navbar> -->
		<view class="tabs hflex acenter">
			<u-tabs :list="tabs" :activeStyle="{color: '#2988FE',}" @click="changeTab" :scrollable="false"></u-tabs>
		</view>
		<view class="list" v-if="active == 0&&record.length>0">
			<block v-for="(item,index) in record" :key="index">
				<view class="list_item" @click="toDetail(index)">
					<view class="title">
						{{item.name}}
					</view>
					<view class="date">
						{{item.start_at}}
					</view>
					<view class="bottom hflex acenter jbetween">
						<view class="hflex acenter">
							<span class="text_style1">{{item.score}}</span>/{{item.all_score}}分
						</view>
						<view class="hflex acenter">
							<span class="text_style1">{{item.correct_count}}</span>/{{item.all_count}}题
						</view>
						<view class="state yellow" v-if="item.is_pass == 0">未通过</view>
						<view class="state" v-else>通过</view>
					</view>
				</view>
			</block>
		</view>
		<view class="list vflex acenter jcenter" v-if="active == 0&&record.length==0">
			<image src="../../../static/images/common/exam_none.png" class="img_none"></image>
			<view class="text_none">
				暂无考试记录
			</view>
		</view>
		<view class="list" v-if="active == 1&&collect.length> 0">
			<block v-for="(item,index) in collect" :key="index">
				<view class="list_item hflex acenter jbetween" @click="wrong(item.id)">
					<view class="left">{{item.name}}</view>
					<view class="hflex acenter">
						<view class="right">{{item.collection_count}}道</view>
						<u-icon name="arrow-right" color="#333333" size="12"></u-icon>
					</view>
				</view>
			</block>
		</view>
		<view class="list vflex acenter jcenter" v-if="active == 1&&collect.length==0">
			<image src="../../../static/images/common/exam_none.png" class="img_none"></image>
			<view class="text_none">
				暂无收藏题目
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	
	export default {
		data() {
			return {
				tabs: [
					{
						name: '考试记录'
					},
					{
						name: '收藏题目'
					}
				],
				active: 0,
				record: [],
				collect: [],
				page: 1,
				limit: 10,
				type: 1
			}
		},
		onLoad() {
			this.getExam(this.type)
		},
		methods: {
			// leftClick() {
			// },
			// 获取考试数据
			getExam(type) {
				var that = this
				$api.req({
					url: '/api/User/myExaminationApplet',
					data: {
						page: that.page,
						limit: that.limit,
						type: type
					}
				}, function(res) {
					console.log("我的考试：",res);
					if (res.code == 1) {
						if (that.type == 1) {
							that.record = res.data.list
						} else {
							that.collect = res.data.list
						}
					}
				})
			},
			// 切换tabs
			changeTab(e) {
				this.active = e.index
				this.type = this.active + 1
				this.getExam(this.type)
			},
			// 考试详情
			toDetail(index) {
				if (this.record[index].can_test == 1) {
					if (this.record[index].pass_history) {
						$api.info('您已经考试及格了，无需再参加考试了')
					} else {
						$api.jump('/pages/index/exam/exam?id=' + this.record[index].course_id)
						this.exam.show = false
					}
					
				} else {
					$api.info('未到时间')
				}
			},
			wrong(id) {
				$api.jump('/pages/mine/exam/wrong?id=' + id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.web_box::v-deep {
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.tabs {
			width: 100%;
			box-sizing: border-box;
			padding: 12rpx 0;
			background: #FFFFFF;
		}
		.u-tabs {
			width: 100%;
		}
		.list {
			width: 100%;
			box-sizing: border-box;
			padding: 0 46rpx;
		}
		.list_item {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 22rpx;
			background: #FFFFFF;
			box-shadow: 0px 2px 6px 0px rgba(213,213,213,0.5);
			border-radius: 24rpx;
			margin-top: 20rpx;
		}
		.title {
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
		}
		.date {
			font-size: 26rpx;
			font-weight: 400;
			color: #333333;
			padding: 20rpx 0 34rpx;
		}
		.bottom {
			width: 100%;
			box-sizing: border-box;
			padding: 8rpx 48rpx;
			background: #F2F2F2;
			border-radius: 8px;
			font-size: 26rpx;
			color: #999999;
		}
		.text_style1 {
			font-size: 40rpx;
			font-weight: 400;
			color: #333333;
		}
		.state {
			font-size: 26rpx;
			font-weight: 500;
			color: #2988FE;
		}
		.yellow {
			color: #FA6400;
		}
		.left {
			font-size: 32rpx;
			font-weight: 600;
			color: #333333;
		}
		.right {
			font-size: 28rpx;
			font-weight: 400;
			color: #333333;
			padding-right: 6rpx;
		}
		.text_none {
			font-size: 32rpx;
			color: #333333;
			margin-top: 44rpx;
		}
		.img_none {
			margin-top: 300rpx;
			width: 490rpx;
			height: 404rpx;
		}
	}
</style>