<template>
	<view class="school_report">
		<custom-nav title="成绩单"></custom-nav>
		<view class="header">
			<view class="top">
				<text class="season">大卫博士学位争霸赛第{{ info.season }}季</text>
				<!-- <picker class="toggle" :range="seasonList" range-key="name" :value="season_index" @change="changeSeason">切换赛季</picker> -->
				<view class="toggle" @click="toShare">分享成绩单</view>
			</view>
			<view class="bottom">赛季时间：{{ info.season_time }}</view>
		</view>
		<view class="nav">
			<view class="nav_main">
				<view class="item" :class="navActive === 0 ? 'active' : ''" @click="navActive = 0">成长</view>
				<view class="item" :class="navActive === 1 ? 'active' : ''" @click="navActive = 1">荣誉</view>
			</view>
			<image :src="userWxInfo.avatarUrl" class="header_img"></image>
		</view>
		<view class="container" v-if="navActive === 0">
			<view class="all_link">
				<view class="left">
					<view>总学分：{{ infoBody.integral || '' }}</view>
					<view class="speed_item_name level" v-if="infoBody.integral >= 300">{{ infoBody.integral | userXueWei }}</view>
				</view>
				<view class="link" @click="toRankLink">查看排行榜</view>
			</view>
			<view class="achievement_list">
				<view class="achievement_item">
					<view class="title">
						<view class="left">
							<view class="index">01</view>
							<view clas>销售数量</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">本届总销售：{{ infoBody.sale_num.total || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.total_up_num > 0">同比上季多卖了{{ infoBody.sale_num.total_up_num || 0 }}套</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">简约版：{{ infoBody.sale_num.simple || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.simple_up_num > 0">同比上季多卖了{{ infoBody.sale_num.simple_up_num || 0 }}套</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">高腰版：{{ infoBody.sale_num.old || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.old_up_num > 0">同比上季多卖了{{ infoBody.sale_num.old_up_num || 0 }}套</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">青春版：{{ infoBody.sale_num.youth || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.youth_up_num > 0">同比上季多卖了{{ infoBody.sale_num.youth_up_num || 0 }}套</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">精装版：{{ infoBody.sale_num.hard || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.hard_up_num > 0">同比上季多卖了{{ infoBody.sale_num.hard_up_num || 0 }}套</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">棉老版：{{ infoBody.sale_num.cot_old || 0 }}套</view>
							<view class="text" v-if="infoBody.sale_num.cot_old_up_num > 0">同比上季多卖了{{ infoBody.sale_num.cot_old_up_num || 0 }}套</view>
						</view>
					</view>
				</view>
				<view class="achievement_item">
					<view class="title">
						<view class="left">
							<view class="index">02</view>
							<view clas>学分挑战</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">挑战成功：{{ infoBody.challenge.challenge_success || 0 }}次</view>
							<view class="text" v-if="infoBody.challenge.challenge_inte > 0">赢得{{ infoBody.challenge.challenge_inte || 0 }}奖学金</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">挑战失败：{{ infoBody.challenge.challenge_fail || 0 }}次</view>
						</view>
					</view>
					<view class="body" v-if="infoBody.challenge.guessing_total > 0">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">参与竞猜：{{ infoBody.challenge.guessing_total || 0 }}次</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">竞猜赢了：{{ infoBody.challenge.guessing_success || 0 }}次</view>
							<view class="text" v-if="infoBody.challenge.guessing_inte">赢得{{ infoBody.challenge.guessing_inte || 0 }}奖学金</view>
						</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info info_flex">
							<view class="speed_item_name name">竞猜输了：{{ infoBody.challenge.guessing_fail || 0 }}次</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="container" v-else>
			<view class="all_link">
				<view class="left">
					<view>奖励金：{{ infoBody.bonus || 0 }}</view>
				</view>
				<!-- <view class="link" @click="toDuiHuan">兑换礼品</view> -->
			</view>
			<view class="achievement_list">
				<view class="achievement_item">
					<view class="title">
						<view class="left">
							<view class="index">01</view>
							<view clas>赛季成就</view>
						</view>
					</view>
					<view v-if="infoBody.season_data && infoBody.season_data.length > 0">
						<view class="body" v-for="(item, index) in infoBody.season_data" :key="index">
							<view class="bot_box"><view class="bot"></view></view>
							<view class="info">
								<view class="speed_item_name name">{{ item.type | deg }}</view>
								<view class="text">
									<view>获得时间</view>
									<view>{{ item.time }}</view>
								</view>
							</view>
						</view>
					</view>
					<view v-else>
						<view class="body">
							<view class="bot_box"><view class="bot"></view></view>
							<view class="info"><view class="speed_item_name name">未获得任何成就</view></view>
						</view>
					</view>
				</view>
				<view class="achievement_item">
					<view class="title">
						<view class="left">
							<view class="index">02</view>
							<view clas>荣誉证书</view>
						</view>
						<view class="right" @click="toHonorList">全部证书</view>
					</view>
					<view v-if="infoBody.season_data && infoBody.season_data.length > 0">
						<view class="body" v-for="(item, index) in infoBody.season_data" :key="index">
							<view class="bot_box"><view class="bot"></view></view>
							<view class="info">
								<view class="speed_item_name name">{{ item.type | deg }}</view>
								<view class="text">
									<view>获得时间</view>
									<view>{{ item.time }}</view>
								</view>
							</view>
						</view>
					</view>
					<view v-else>
						<view class="body">
							<view class="bot_box"><view class="bot"></view></view>
							<view class="info"><view class="speed_item_name name">未获得任何证书</view></view>
						</view>
					</view>
				</view>
				<view class="achievement_item">
					<view class="title">
						<view class="left">
							<view class="index">03</view>
							<view clas>荣誉奖章</view>
						</view>
						<view class="right" @click="showJiangPai">查看奖章</view>
					</view>
					<view class="body">
						<view class="bot_box"><view class="bot"></view></view>
						<view class="info">
							<view class="speed_item_name name">{{ jiangpaiShow(infoBody.season_data).name }}</view>
							<view class="text" v-if="jiangpaiShow(infoBody.season_data).time">
								<view>获得时间</view>
								<view>{{ jiangpaiShow(infoBody.season_data).time }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<page-toast :is-show="seeJiangPai" :before-close="resetjpToast">
			<view class="medal_container">
				<view>{{ jiangpaiShow(infoBody.season_data).name }}</view>
				<image class="medal_img" :src="`https://api.jiuweiyun.cn/public/uploads/icon/jp${jiangpaiShow(infoBody.season_data).type}.png`"></image>
			</view>
		</page-toast>
	</view>
</template>

<script>
import { get_season_list, school_report } from '../../api.js';
import { numToZh } from '../../common/js/filters.js';
export default {
	data() {
		return {
			userWxInfo: this.$store.state.userWeixinInfo,
			seasonList: [],
			season_index: 0,
			season_id: '',
			info: {},
			navActive: 0,
			infoBody: [],
			seeJiangPai: false
		};
	},
	watch: {
		navActive(a, b) {
			this.infoBody = (a === 0 ? this.info.list1 : this.info.list2) || [];
		}
	},
	onLoad() {
		this.getInfo();
		// this.getSeasonList()
	},
	methods: {
		toShare() {
			uni.navigateTo({
				url: '../cjdshare/index'
			});
		},
		toHonorList() {
			uni.navigateTo({
				url: '../honorList/index'
			});
		},
		toDuiHuan() {
			uni.navigateTo({
				url: '../exchange/exchange'
			});
		},
		toRankLink() {
			uni.navigateTo({
				url: '../ranking/ranking'
			});
		},
		resetjpToast() {
			this.seeJiangPai = false;
		},
		showJiangPai() {
			if (!this.infoBody.season_data || this.infoBody.season_data.length < 0 || this.jiangpaiShow(this.infoBody.season_data).type === -1) {
				uni.showModal({
					content: '您还未获得奖牌',
					showCancel: false
				});
			} else {
				this.seeJiangPai = true;
			}
		},
		getInfo() {
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			this.$ajax.get(`${school_report}`).then(([, { data: res }]) => {
				uni.hideLoading();
				if (res.code === 200) {
					this.info = res.data;
					this.infoBody = (this.navActive === 0 ? res.data.list1 : res.data.list2) || [];
				}
			});
		},
		getSeasonList() {
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			this.$ajax.get(`${get_season_list}`).then(([, { data: res }]) => {
				uni.hideLoading();
				if (res.code === 200) {
					this.seasonList = res.data.list.map(item => ({
						season: item.season,
						name: `大卫博士学位争霸赛第${item.season}季`
					}));
				}
			});
		},
		changeSeason(e) {
			this.season_id = this.seasonList[e.target.value].season;
			console.log(this.season_id);
		},
		jiangpaiShow(arr) {
			let out = {
				name: '未获得奖牌',
				time: '',
				type: -1
			};
			if (!arr || arr.length < 1) return out;
			let typeArr = arr.map(i => i.type);
			let maxType = Math.max.apply(Math, typeArr);
			let maxIndex = arr.findIndex(i => i.type === maxType);
			out.time = arr[maxIndex].time;
			switch (arr[maxIndex].type) {
				case 4:
					out.name = '金牌奖章';
					out.type = 4;
					break;
				case 3:
					out.name = '银牌奖章';
					out.type = 3;
					break;
				case 2:
					out.name = '铜牌奖章';
					out.type = 2;
					break;
			}
			return out;
		}
	}
};
</script>
<style lang="scss" scoped>
.school_report {
	border-top: 128rpx solid #ffffff;

	.medal_container {
		margin: 0 auto;
		width: 450rpx;
		height: 500rpx;
		padding: 30rpx 0 50rpx 0;
		border-radius: 6rpx;
		display: flex;
		justify-content: space-between;
		flex-direction: column;
		color: #333333;
		font-size: 36rpx;
		background-color: #ffffff;
		align-items: center;
		.medal_img {
			width: 300rpx;
			height: 336rpx;
		}
	}

	.speed_item_name {
		padding: 10rpx 15rpx;
		color: #f7a351;
		font-size: 28rpx;
		border: 1px solid #fa6342;
		border-radius: 4rpx;
		background-color: rgba(250, 99, 66, 0.1);
		position: relative;
		margin-bottom: 10rpx;
		&::before {
			content: '';
			display: block;
			width: 0;
			height: 0;
			border-width: 8rpx;
			border-style: solid;
			border-color: transparent #ffc7bb transparent transparent;
			position: absolute;
			top: 20rpx;
			left: -16rpx;
			z-index: 3;
		}
		&::after {
			content: '';
			display: block;
			width: 0;
			height: 0;
			border-width: 12rpx;
			border-style: solid;
			border-color: transparent #fa6342 transparent transparent;
			position: absolute;
			top: 16rpx;
			left: -24rpx;
			z-index: 2;
		}
	}

	.header {
		background-color: #fa6342;
		padding: 56rpx 32rpx;
		padding-bottom: 36rpx;
		.top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 23rpx;
			.season {
				font-size: 36rpx;
				color: #ffffff;
			}
			.toggle {
				color: #fa6342;
				background-color: #f2f4f5;
				font-size: 24rpx;
				height: 48rpx;
				line-height: 48rpx;
				width: 148rpx;
				border-radius: 24rpx;
				text-align: center;
			}
		}
		.bottom {
			font-size: 26rpx;
			color: #ffffff;
		}
	}
	.nav {
		color: #333333;
		font-size: 32rpx;
		width: 100%;
		height: 128rpx;
		background-image: url(../../static/icon/cjd_bg.png);
		background-size: 100% 100%;
		position: relative;
		.header_img {
			display: block;
			width: 128rpx;
			height: 128rpx;
			border-radius: 50%;
			position: absolute;
			top: 0;
			bottom: 0;
			right: 30rpx;
		}
		.nav_main {
			padding: 0 60rpx;
			height: 128rpx;
			display: flex;
			align-items: flex-end;
			.item {
				line-height: 64rpx;
				border-bottom: 2px solid #ffffff;
				&:nth-of-type(1) {
					margin-right: 100rpx;
				}
			}
			.active {
				border-bottom-color: #fa6342 !important;
				color: #fa6342 !important;
			}
		}
	}
	.container {
		padding: 24rpx 30rpx;
		.all_link {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 70rpx;
			background-color: #f2f4f5;
			padding: 0 24rpx;
			color: #333333;
			font-size: 26rpx;
			.left {
				display: flex;
				align-items: center;
				.level {
					margin-left: 22rpx;
					font-size: 22rpx;
					padding-top: 4rpx;
					padding-bottom: 4rpx;
					margin-bottom: 0;
					&::before {
						top: 10rpx;
					}
					&::after {
						top: 6rpx;
					}
				}
			}
			.link {
				display: flex;
				align-items: center;
				color: #999999;
				font-size: 24rpx;
				&::after {
					content: '';
					display: block;
					width: 0;
					height: 0;
					margin-left: 17rpx;
					border-width: 6rpx;
					border-style: solid;
					border-color: transparent transparent transparent #000000;
				}
			}
		}
		.achievement_list {
			position: relative;
			&::after {
				content: '';
				display: block;
				width: 1px;
				height: 100%;
				background: #d2d2d2;
				position: absolute;
				top: 0;
				left: 41rpx;
				z-index: -1;
			}
		}
		.achievement_item {
			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 20rpx 0;
				.left {
					display: flex;
					align-items: center;
					.index {
						width: 82rpx;
						height: 82rpx;
						background-image: url(../../static/icon/cjd_bg2.png);
						background-size: 100% 100%;
						color: #ffffff;
						font-size: 28rpx;
						line-height: 82rpx;
						text-align: center;
						margin-right: 35rpx;
					}
				}
				.right {
					color: #999999;
					font-size: 24rpx;
					display: flex;
					align-items: center;
					&::after {
						content: '';
						display: block;
						width: 0;
						height: 0;
						margin-left: 17rpx;
						border-width: 6rpx;
						border-style: solid;
						border-color: transparent transparent transparent #000000;
					}
				}
			}
			.body {
				display: flex;
				align-items: flex-start;
				justify-content: flex-start;
				margin-bottom: 40rpx;
				.bot_box {
					height: 60rpx;
					display: flex;
					align-items: center;
				}
				.bot {
					width: 22rpx;
					height: 22rpx;
					border-radius: 50%;
					background-color: #ffc7bb;
					margin: 0 30rpx;
				}

				.info_flex {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					.name {
						margin-right: 36rpx;
					}
				}

				.info {
					.text {
						text-align: center;
						color: #333333;
						font-size: 24rpx;
						line-height: 40rpx;
					}
				}
			}
		}
	}
}
</style>
