<template>
	<view class="role" :class="roleData.auth_role == 0 && Number(roleData.group) != 0 ? 'longBg' : 'shortBg'">
		<custom-nav v-if="showNav">
			<view class="current-date"><image src="../../static/imgs/arrow_left.png" @click="goBack"></image></view>
		</custom-nav>
		<view v-if="roleData.auth_role == 1 || roleData.auth_role == 2 || (roleData.auth_role == 0 && Number(roleData.group) == 0)">
			<view class="role_con">
				<image :src="userInfo.avatar"></image>
				<view class="flexCC">
					<text v-if="roleData.auth_role == 1" class="type">裁判</text>
					<text v-if="roleData.auth_role == 2" class="type">讲师</text>
					<text v-if="roleData.auth_role == 0" class="type">暂无分组</text>
					<text class="line" v-if="roleData.auth_role == 1 || roleData.auth_role == 2"></text>
				</view>
				<text v-if="roleData.auth_role == 1 || roleData.auth_role == 2">
					恭喜你获得创业{{ userInfo.season_type | activityType }}{{ roleData.auth_role == 1 ? '裁判' : '讲师' }}身份
				</text>
			</view>
			<view class="welcome">创业{{ userInfo.season_type | activityType }}欢迎您的加入</view>
		</view>
		<view v-if="roleData.auth_role == 0 && Number(roleData.group) != 0">
			<view class="group">
				<view class="group_con">
					<image :src="userInfo.avatar"></image>
					<view class="flexCC">
						<text class="type">小组成员</text>
						<text class="line"></text>
					</view>
					<view style="margin:37rpx 0 54rpx">创业{{ userInfo.season_type | activityType }}欢迎你的加入</view>
					<view class="score">
						<text>{{ roleData.score ? roleData.score : 0 }}分</text>
						<view>所在小组总得分</view>
					</view>
					<view class="photos">
						<view class="photos_con" v-for="(item, index) in roleData.team" :key="item.id"><image :src="item.get_user.avatar" v-if="index < 10"></image></view>
					</view>
				</view>
			</view>
			<view class="rank">
				<view class="rank_con">
					<image src="../../static/imgs/title.png" mode="" class="rank_title"></image>
					<image src="../../static/imgs/rank.png" class="rank_bg"></image>
					<view class="front flexCC">
						<view class="avatar"><image :src="topThree[0].team[0].get_user.avatar"></image></view>
						<view class="nickname" v-if="topThree">{{ topThree[0].group_name | getName }}</view>
						<view class="num">{{ topThree[0].score }}</view>
					</view>
					<view class="front flexCC two">
						<view class="avatar"><image :src="topThree[1].team[0].get_user.avatar"></image></view>
						<view class="nickname" v-if="topThree">{{ topThree[1].group_name | getName }}</view>
						<view class="num">{{ topThree[1].score }}</view>
					</view>
					<view class="front flexCC three">
						<view class="avatar"><image :src="topThree[2].team[0].get_user.avatar"></image></view>
						<view class="nickname" v-if="topThree">{{ topThree[2].group_name | getName }}</view>
						<view class="num">{{ topThree[2].score }}</view>
					</view>
				</view>
			</view>
			<view class="rank_list">
				<view class="list_con flexS" v-for="(item, index) in rankList" :key="item.id">
					<view style="font-size:32rpx;font-weight:bold;margin:0 20rpx 0 30rpx;width: 50rpx;flex-shrink: 0;">{{ index + 4 }}</view>
					<view class="fold">
						<view v-for="(temp, index) in item.team" :key="temp.id" class="avatars" :style="{ transform: `translateX(${-index * 10}rpx)` }">
							<image :src="temp.get_user.avatar" v-if="index < 3"></image>
						</view>
						<view class="more" style="transform: translateX(-40rpx);"><image src="../../static/imgs/more_photo.png"></image></view>
					</view>
					<view class="name">{{ item.group_name }}</view>
					<view style="font-size:32rpx;color:#FFCA65;font-weight:bold;">{{ item.score }}</view>
				</view>
				<view class="more_rank" @click="moreRank">{{ isMore ? '收起<<' : '查看TOP' + ' ' + total + '>>' }}</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getRank, lookAuth } from '../../api/identity.js';
import customNav from '../../components/custom-nav.vue';
export default {
	data() {
		return {
			userInfo: {},
			rankList: '', //排行刚进入页面显示
			topThree: '', //排行前三名
			moreList: '', //所有排行榜
			avatars: '', //排行榜重叠头像
			isMore: false, //点击显示更多
			auth_role: '', //1裁判  2讲师 0 小组
			total: '', //排行榜总条数
			showNav: true //向下滑动时隐藏nav
		};
	},
	//向下滚动时隐藏导航栏
	onPageScroll(res) {
		if (res.scrollTop > 10) {
			this.showNav = false;
		} else {
			this.showNav = true;
		}
	},
	onShow() {
		this.lookAuth();
		this.userInfo = uni.getStorageSync('userInfo');
	},
	filters: {
		getName(name) {
			if (name) {
				return name.length > 6 ? name.slice(0, 6) + '...' : name;
			}
			return '';
		}
	},
	components: {
		customNav
	},
	methods: {
		//返回上一页
		goBack() {
			uni.navigateBack({
				delta: 1
			});
		},
		//获取排行榜列表
		getRank() {
			let that = this;
			getRank().then(res => {
				if (res.code == 200) {
					let list = res.data.list;
					that.moreList = list.slice(3);
					that.topThree = list.slice(0, 3);
					that.rankList = list.slice(3, 11);
					that.total = res.data.list.length;
				} else {
					uni.showModal({
						content: res.msg || '请求失败',
						showCancel: false
					});
				}
			});
		},
		//查看身份信息
		/*
		 * desc auth_role及grop都为0的时候没有分组
		 */
		lookAuth() {
			lookAuth().then(res => {
				if (res.code == 200) {
					this.roleData = res.data;
					if (res.data.auth_role == 0 && Number(res.data.group) != 0) {
						//已经分组，是小组成员
						this.getRank();
					}
				} else {
					uni.showModal({
						content: res.msg || '请求失败',
						showCancel: false
					});
				}
			});
		},
		//点击查看更多
		moreRank() {
			let that = this;
			that.isMore = !that.isMore;
			if (that.isMore) {
				that.rankList = that.moreList;
			} else {
				that.rankList = that.moreList.slice(0, 8);
			}
		}
	}
};
</script>
<style>
page {
	min-height: 100%;
	width: 750rpx;
	background: #c11b0b;
	overflow-x: hidden;
}
</style>
<style lang="scss">
.current-date {
	image {
		width: 50rpx;
		height: 50rpx;
		vertical-align: -9rpx;
	}
}
.longBg {
	width: 100%;
	min-height: 100%;
	background: url('https://api.szy.jiuweiyun.cn/images/longBg.png') no-repeat;
	background-size: 100% 2766rpx;
	overflow-x: hidden;
	z-index: 1;
}
.shortBg {
	width: 100vw;
	height: 100vh;
	background: url('https://api.szy.jiuweiyun.cn/images/shortBg.png') no-repeat;
	background-size: 100% 100%;
	overflow-x: hidden;
}

.role_bg {
	.long {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 2766rpx;
	}
}
.group_con,
.role_con {
	image {
		height: 144rpx;
		width: 144rpx;
		border-radius: 50%;
	}
	.line {
		display: inline-block;
		background-color: #febe3f;
		z-index: 77;
	}
	.type {
		z-index: 88;
		font-size: 50rpx;
		color: #333;
		font-weight: 800;
	}
}
.role_con {
	width: 100%;
	text-align: center;
	position: absolute;
	top: 34vh;
	left: 0;
	text {
		font-size: 30rpx;
		font-weight: 500;
	}
	view {
		font-weight: bold;
		margin: 45rpx 0;
		.line {
			display: inline-block;
			background-color: #febe3f;
			margin-top: -16rpx;
			width: 113rpx;
			height: 14rpx;
		}
	}
}
.welcome {
	position: absolute;
	left: 0;
	bottom: 4.5vh;
	font-size: 46rpx;
	font-weight: bold;
	color: #c21c0b;
	width: 100%;
	text-align: center;
}
.group {
	width: 100%;
	text-align: center;
	padding-top: 401rpx;
	.group_con {
		width: 556rpx;
		margin: 0 auto;
		.line {
			width: 295rpx;
			height: 14rpx;
			margin-top: -13rpx;
		}
		.score {
			text {
				font-size: 53rpx;
				color: #c11b0b;
				font-weight: bold;
			}
			view {
				font-size: 24rpx;
				color: #333;
				margin: 17rpx 0 34rpx;
			}
		}
		.photos {
			width: 494rpx;
			height: 180rpx;
			margin: 0 auto;
			background-color: #f0f0f0;
			border-radius: 10rpx;
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
			align-items: center;
			.photos_con {
				width: 20%;
				image {
					width: 61rpx;
					height: 61rpx;
					border-radius: 50%;
				}
			}
		}
	}
}
.rank {
	width: 100%;
	padding-top: 166rpx;
	.rank_con {
		text-align: center;
		position: relative;
		.rank_title {
			width: 506rpx;
			height: 116rpx;
		}
		.rank_bg {
			width: 639rpx;
			height: 345rpx;
			margin-top: 20rpx;
		}
		.front {
			position: absolute;
			bottom: 80rpx;
			left: 328rpx;
			.avatar {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				border: 5rpx solid #fff;
				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}
			}
			.nickname {
				font-size: 22rpx;
				font-weight: bold;
				margin: 15rpx 0;
				color: #fff;
			}
			.num {
				font-size: 44rpx;
				font-weight: bold;
				color: #ffbf44;
			}
		}
		.two {
			position: absolute;
			left: 92rpx;
			bottom: 23rpx;
		}
		.three {
			position: absolute;
			right: -133rpx;
			bottom: 23rpx;
		}
	}
}
.rank_list {
	width: 690rpx;
	margin: 58rpx auto 80rpx;
	background: #991300;
	border-radius: 16rpx;
	color: #fff;
	.list_con {
		align-items: center;
		padding-top: 20rpx;
		.fold {
			flex-shrink: 0;
			width: 233rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			.avatars {
				image {
					width: 56rpx;
					height: 56rpx;
					border-radius: 50%;
				}
			}
		}
		.name {
			font-size: 24rpx;
			width: 230rpx;
			text-align: center;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			margin-right: 25rpx;
		}
		.more {
			image {
				width: 56rpx;
				height: 56rpx;
			}
		}
	}
	.more_rank {
		width: 100%;
		text-align: center;
		font-size: 32rpx;
		color: #f9e55a;
		font-style: italic;
		font-weight: bold;
		padding: 30rpx 0;
	}
}
</style>
