<template>
	<view class="matchmaker-ranking">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-btn" @click="goBack"></view>
			<text class="header-title">红娘排行榜</text>
			<view class="placeholder"></view>
		</view>

		<!-- 更新提示 -->
		<view class="update-info">
			<text class="update-text">每天17点自动更新数据</text>
		</view>

		<!-- 本周最佳榜标题 -->
		<view class="section-title-wrapper">
			<text class="section-title">
				<text class="title-icon">👩‍❤️‍💋‍👨</text>
				本周最佳榜
				<text class="title-icon">👩‍❤️‍💋‍👨</text>
			</text>
		</view>

		<!-- 榜说明 -->
		<view class="ranking-description">
			<text class="description-text">榜单综合万粉以下红娘的日牵线数,用户好评数 等综合因素,上榜为前20的红娘</text>
		</view>

		<!-- 前三名展示 -->
		<view class="top-three-container">
			<view class="top-three-item second">
				<text class="rank-number">2</text>
				<view class="avatar-large"></view>
				<text class="matchmaker-name">小颖颖</text>
				<text class="success-count">成功人数: 11</text>
				<view class="like-btn" @click="handleLike(2)">点赞</view>
			</view>

			<view class="top-three-item first">
				<text class="rank-number">1</text>
				<view class="avatar-large"></view>
				<text class="matchmaker-name">小超超</text>
				<text class="success-count">成功人数: 12</text>
				<view class="like-btn active" @click="handleLike(1)">点赞</view>
			</view>

			<view class="top-three-item third">
				<text class="rank-number">3</text>
				<view class="avatar-large"></view>
				<text class="matchmaker-name">小魏魏</text>
				<text class="success-count">成功人数: 10</text>
				<view class="like-btn" @click="handleLike(3)">点赞</view>
			</view>
		</view>

		<!-- 排行榜列表 -->
		<scroll-view scroll-y class="ranking-list">
			<view class="ranking-item" v-for="(item, index) in rankingList" :key="index">
				<text class="rank-number-normal">{{ index + 4 }}</text>
				<view class="avatar-small"></view>
				<view class="matchmaker-info">
					<text class="matchmaker-name-normal">{{ item.name }}</text>
					<text class="success-count-normal">成功人数: {{ item.successCount }} 人</text>
					<text class="user-rating">用户好评数:{{ item.userRating }}</text>
				</view>
				<view class="like-btn-small" @click="handleLike(index + 4)">点赞</view>
			</view>
		</scroll-view>

		<!-- 底部导航 -->
		<view class="tabbar">
			<view class="tabbar-item" @click="navigateToWorkbench">
				<text class="tab-icon">🏠</text>
				<text class="tab-text">工作台</text>
			</view>
			<view class="tabbar-item" @click="navigateToMyResources">
				<text class="tab-icon">📋</text>
				<text class="tab-text">我的资源</text>
			</view>
			<view class="tabbar-item active" @click="navigateToRanking">
				<text class="tab-icon">🏆</text>
				<text class="tab-text">排行榜</text>
			</view>
			<view class="tabbar-item" @click="navigateToMessage">
				<view class="tab-icon-wrapper">
					<text class="tab-icon">💬</text>
					<view class="badge">3</view>
				</view>
				<text class="tab-text">消息</text>
			</view>
			<view class="tabbar-item" @click="navigateToMine">
				<text class="tab-icon">👤</text>
				<text class="tab-text">我的</text>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/utils/api.js'
	
export default {
		data() {
			return {
				rankingList: [
					{ name: '小华华', successCount: 9, userRating: 25 },
					{ name: '小蒋蒋', successCount: 8, userRating: 24 },
					{ name: '小明明', successCount: 7, userRating: 23 },
					{ name: '小信信', successCount: 6, userRating: 23 },
					{ name: '小莉莉', successCount: 6, userRating: 22 },
					{ name: '小圆圆', successCount: 5, userRating: 21 },
					{ name: '小方方', successCount: 5, userRating: 20 },
					{ name: '小香香', successCount: 4, userRating: 19 },
					{ name: '小甜甜', successCount: 4, userRating: 18 },
					{ name: '小美美', successCount: 4, userRating: 18 },
					{ name: '小柔柔', successCount: 3, userRating: 17 },
					{ name: '小静静', successCount: 3, userRating: 16 },
					{ name: '小聪聪', successCount: 3, userRating: 15 },
					{ name: '小慧慧', successCount: 3, userRating: 15 },
					{ name: '小欢欢', successCount: 2, userRating: 14 },
					{ name: '小乐乐', successCount: 2, userRating: 13 },
					{ name: '小笑笑', successCount: 2, userRating: 12 },
					{ name: '小闹闹', successCount: 1, userRating: 11 },
					{ name: '小跳跳', successCount: 1, userRating: 10 },
					{ name: '小跑跑', successCount: 1, userRating: 9 }
				]
			}
		},
		onLoad() {
			// 加载排行榜数据
			this.loadRankingData()
		},
		methods: {
			// 返回上一页
			goBack() {
				uni.navigateBack()
			},
			// 加载排行榜数据
			async loadRankingData() {
				try {
					const res = await api.matchmaker.getRankingData()
					if (res.data) {
						this.rankingList = res.data
					}
				} catch (e) {
					console.error('加载排行榜数据失败:', e)
				}
			},
			// 点赞
			handleLike(rank) {
				// 实现点赞功能
				console.log('点赞第', rank, '名红娘')
				uni.showToast({
					title: '点赞成功',
					icon: 'success'
				})
			},
			// 导航到工作台
			navigateToWorkbench() {
				uni.redirectTo({
					url: '/pages/matchmaker-workbench/index'
				})
			},
			// 导航到我的资源
			navigateToMyResources() {
				uni.redirectTo({
					url: '/pages/matchmaker-workbench/my-resources'
				})
			},
			// 导航到排行榜
			navigateToRanking() {
				// 已在排行榜页面，无需跳转
			},
			// 导航到消息
			navigateToMessage() {
				uni.redirectTo({
					url: '/pages/matchmaker-workbench/message'
				})
			},
			// 导航到我的
			navigateToMine() {
				uni.redirectTo({
					url: '/pages/matchmaker-workbench/mine'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.matchmaker-ranking {
		min-height: 100vh;
		background: linear-gradient(135deg, #FFF3F6 0%, #FFE4E8 100%);
		display: flex;
		flex-direction: column;
	}

	/* 顶部导航栏 */
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25rpx 30rpx;
		padding-top: calc(25rpx + env(safe-area-inset-top));
		background: #FFF9F9;
		border-bottom: 1rpx solid #F0F0F0;

		.back-btn {
			width: 70rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: rgba(240, 240, 240, 0.5);
			border-radius: 50%;
			background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>');
			background-size: 40rpx 40rpx;
			background-repeat: no-repeat;
			background-position: center;
		}

		.header-title {
			font-size: 38rpx;
			font-weight: bold;
			color: #333;
		}

		.placeholder {
			width: 70rpx;
		}
	}

	/* 更新提示 */
	.update-info {
		background: #FFF3E0;
		padding: 15rpx;
		text-align: center;

		.update-text {
			font-size: 24rpx;
			color: #FF9800;
		}
	}

	/* 本周最佳榜标题 */
	.section-title-wrapper {
		text-align: center;
		margin: 30rpx 0 15rpx;

		.section-title {
			display: inline-block;
			font-size: 36rpx;
			font-weight: bold;
			color: #E91E63;
			line-height: 1.4;

			.title-icon {
				font-size: 40rpx;
				margin: 0 10rpx;
			}
		}
	}

	/* 榜说明 */
	.ranking-description {
		padding: 0 30rpx 25rpx;

		.description-text {
			display: block;
			font-size: 26rpx;
			color: #666;
			line-height: 1.5;
			text-align: center;
		}
	}

	/* 前三名展示 */
	.top-three-container {
		display: flex;
		justify-content: space-around;
		align-items: flex-end;
		padding: 0 20rpx 40rpx;
		background: #FFF9F9;
		border-radius: 20rpx;
		margin: 0 20rpx 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

		.top-three-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 20rpx;
			border-radius: 20rpx;
			position: relative;

			&.first {
				background: linear-gradient(135deg, #FFD700 0%, #FFA000 100%);
				width: 280rpx;
				height: 400rpx;
				order: 2;
				margin-bottom: 30rpx;
			}

			&.second {
				background: linear-gradient(135deg, #C0C0C0 0%, #A8A8A8 100%);
				width: 240rpx;
				height: 350rpx;
				order: 1;
			}

			&.third {
				background: linear-gradient(135deg, #CD7F32 0%, #B87333 100%);
				width: 240rpx;
				height: 350rpx;
				order: 3;
			}

			.rank-number {
				position: absolute;
				top: 20rpx;
				left: 20rpx;
				font-size: 48rpx;
				font-weight: bold;
				color: #FFFFFF;
			}

			.avatar-large {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				background: rgba(255, 255, 255, 0.3);
				margin: 40rpx 0 20rpx;
			}

			.matchmaker-name {
				font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;
				margin-bottom: 15rpx;
			}

			.success-count {
				font-size: 28rpx;
				color: #FFFFFF;
				margin-bottom: 30rpx;
			}

			.like-btn {
				padding: 12rpx 35rpx;
				background: rgba(255, 255, 255, 0.2);
				color: #FFFFFF;
				border-radius: 25rpx;
				font-size: 26rpx;
				font-weight: bold;
				border: 2rpx solid #FFFFFF;

				&.active {
					background: #E91E63;
					color: #FFFFFF;
					border-color: #E91E63;
				}
			}
		}
	}

	.ranking-list {
		flex: 1;
		padding: 0 20rpx 120rpx;

		.ranking-item {
			display: flex;
			align-items: center;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 25rpx;
			margin-bottom: 20rpx;
			box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

			.rank-number-normal {
				width: 50rpx;
				height: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				font-weight: bold;
				color: #999;
				border-radius: 50%;
				background: #F0F0F0;
				margin-right: 20rpx;
			}

			.avatar-small {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				background: #F0F0F0;
				margin-right: 20rpx;
			}

			.matchmaker-info {
				flex: 1;

				.matchmaker-name-normal {
					display: block;
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-bottom: 8rpx;
				}

				.success-count-normal,
				.user-rating {
					display: block;
					font-size: 24rpx;
					color: #666;
					margin-bottom: 4rpx;
				}
			}

			.like-btn-small {
				padding: 10rpx 30rpx;
				background: linear-gradient(135deg, #E91E63 0%, #C2185B 100%);
				color: #FFFFFF;
				border-radius: 25rpx;
				font-size: 26rpx;
				font-weight: bold;
			}
		}
	}

	/* 底部导航 */
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 110rpx;
		background: #FFFFFF;
		border-top: 1rpx solid #F0F0F0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding-bottom: env(safe-area-inset-bottom);

		.tabbar-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: 6rpx;
			padding: 10rpx 0;

			.tab-icon-wrapper {
				position: relative;

				.badge {
					position: absolute;
					top: -8rpx;
					right: -12rpx;
					background: #FF4444;
					color: #FFFFFF;
					font-size: 18rpx;
					font-weight: bold;
					min-width: 28rpx;
					height: 28rpx;
					padding: 0 6rpx;
					border-radius: 14rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.tab-icon {
				font-size: 36rpx;
			}

			.tab-text {
				font-size: 20rpx;
				color: #999;
			}

			&.active {
				.tab-text {
					color: #9C27B0;
					font-weight: bold;
				}
			}
		}
	}
</style>