<template>
	<view class="safeArea">
		<nav-bar title="我的考试"></nav-bar>
		<view class="examWrap">
			<view class="examItem" @click="goAppointment">
				<view class="item">模拟考试预约</view>
				<view class="item"><text class="note">去预约模拟考试</text><u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
			</view>
			<view class="examItem" @click="goList(0)">
				<view class="item">未考试</view>
				<view class="item"><text class="num">{{total1}}</text>个<u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
			</view>
			<view class="examItem" @click="goList(1)">
				<view class="item">已结束</view>
				<view class="item"><text class="num">{{total2}}</text>个<u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
			</view>
			<view class="examItem">
				<view class="item">
					<view style="flex:1;" @click="goResult">模拟考试讲解直播</view>
					<view class="desc" @click="goLive()" v-if="livingInfo"><text class="num">{{livingInfo.name}}讲解正在直播中，立即前往查看</text></view>
				</view>
				<view class="item"><u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
			</view>
			<view class="examItem" @click="mockRecord()">
				<view class="item">模考记录</view>
				<view class="item"><u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	components: {
	},
	data() {
		return {
			yyNum:0,
			total1:0,
			total2:0,
			livingInfo:null
		};
	},
	onLoad(){
		// this.getCount()
		// this.mockApplyMockLiving();
	},
	onShow() {
		// this.getInfo()
		this.getCount()
		this.mockApplyMockLiving();
	},
	methods: {
		goLive() {
			let uuid = new Date().valueOf() + ""
      		// buyCourse 是否购买课程：1是 0否
			let encode = encodeURIComponent(this.config.hostLive+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='
			+this.livingInfo.liveUrl+'&buyCourse=1'+'&ident='+uuid)
			uni.navigateTo({
				url:`../../pages/webview/index?url=`+encode
			})
		},
		mockApplyMockLiving() {
			this.$api.mockApplyMockLiving().then(res => {
				if(res.data.data) {
					this.livingInfo = res.data.data;
				}
			})
		},
		mockRecord() {
			uni.navigateTo({
				url:'../mockRecord/mock_record'
			})
		},
		getCount() {
			this.$api.mockSubscribeListSubscribe({
				pageNum:1,
				pageSize:10,
				mockStatus:0,
				endTime:'',
				startTime:''
			}).then(res => {
				this.total1 = res.data.total
			})
			
			this.$api.mockSubscribeListSubscribe({
				pageNum:1,
				pageSize:10,
				mockStatus:1,
				endTime:'',
				startTime:''
			}).then(res => {
				this.total2 = res.data.total
			})
		},
		getInfo(){
			this.$api.getinfoAttached().then(res => {
				if (res.data.code === 200) {
					this.yyNum = res.data.data.subscribeSum;
				}
			});
		},
		goAppointment(){
			this.$navTo.togo('/pages5/examAppointList/index');
		},
		goList(state) {
			this.$navTo.togo('/pages5/examList/index?state='+state);
		},
		goResult(){
			this.$navTo.togo('/pages5/liveList/index');
		}
	},
	onReachBottom() {},
	computed: { ...mapGetters(['userInfo','config']) }
};
</script>
<style >
	page {
			background: #EAEEF1;
		}
</style>
<style scoped lang="scss">
.examWrap{
	padding: 16rpx;
	.examItem{
		padding:24rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 16rpx 4rpx rgba(145, 156, 178, 0.1);
		border-radius: 16rpx;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		margin-bottom: 16rpx;
		.num{
			color:#007AFF;
			text-decoration: underline;
			margin-right: 5rpx;
		}
		
		.desc {
			margin-top:30rpx;
			font-size: 28rpx;
		}
		
		.note {
			font-size: 24rpx;
			color:#999;
		}
	}
}
</style>
