<template>
	<view class="my-registrations">
		<!-- 原生tabs组件 -->
		<view class="custom-tabs">
			<view 
				v-for="(tab, index) in tabList" 
				:key="index" 
				class="tab-item" 
				:class="{ active: currentTab === index }"
				@click="tabChange(index)"
			>
				<text class="tab-text" :class="{ active: currentTab === index }">{{ tab.name }}</text>
				<view v-if="currentTab === index" class="tab-line"></view>
			</view>
		</view>
		
		<!-- 活动列表 -->
		<view class="activity-list">
			<view class="activity-item" v-for="(item, index) in currentActivityList" :key="index" @click="viewActivityDetail(item)">
				<image class="activity-image" :src="item.image" mode="aspectFill"></image>
				<view class="activity-info">
					<view class="title-row">
						<view class="activity-badge">
							<text class="badge-text">30分</text>
						</view>
						<text class="activity-title">{{item.title}}</text>
					</view>
					<view class="activity-location">
						<uv-icon name="map-fill" size="14" color="#999"></uv-icon>
						<text class="location-text">{{item.location}}</text>
					</view>
					<view class="activity-time">
						<uv-icon name="calendar" size="14" color="#999"></uv-icon>
						<text class="time-text">{{item.time}}</text>
					</view>
					<view class="activity-participants">
						<uv-icon name="account-fill" size="14" color="#999"></uv-icon>
						<text class="participants-text">报名人数：{{item.participants}}/{{item.maxParticipants}}</text>
					</view>
				</view>
				<view class="activity-action">
					<uv-button 
						v-if="currentTab === 0" 
						type="primary" 
						size="mini" 
						shape="circle"
						text="扫码签到" 
						@click.stop="scanQRCode(item)"
					></uv-button>
					<uv-button 
						v-else-if="currentTab === 1" 
						type="success" 
						shape="circle"
						size="mini" 
						text="已签到" 
						disabled
					></uv-button>
					<uv-button 
						v-else 
						type="error" 
						size="mini" 
						text="已取消" 
						disabled
					></uv-button>
				</view>
			</view>
			
			<!-- 空状态 -->
			<view v-if="currentActivityList.length === 0" class="empty-state">
				<text class="empty-text">暂无相关报名记录</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'MyRegistrations',
		data() {
			return {
				currentTab: 0,
				tabList: [
					{ name: '未签到' },
					{ name: '已签到' },
					{ name: '系统取消' }
				],
				// 未签到活动列表
				unsignedList: [
					{
						id: 1,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					},
					{
						id: 2,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					},
					{
						id: 3,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					},
					{
						id: 4,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					}
				],
				// 已签到活动列表
				signedList: [
					{
						id: 5,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					}
				],
				// 系统取消活动列表
				cancelledList: [
					{
						id: 6,
						title: '关爱自闭症儿童活动',
						image: '/static/bannerImage.png',
						location: '长沙市雨花区时代阳光大道国际大厅2145',
						time: '2025-06-12 14:30',
						participants: 30,
						maxParticipants: 30
					}
				]
			}
		},
		computed: {
			currentActivityList() {
				switch(this.currentTab) {
					case 0:
						return this.unsignedList
					case 1:
						return this.signedList
					case 2:
						return this.cancelledList
					default:
						return []
				}
			}
		},
		methods: {
			tabChange(index) {
				this.currentTab = index
			},
			viewActivityDetail(activity) {
				// 查看活动详情，根据当前tab状态跳转到对应页面
				let status = 'unsigned' // 默认未签到
				switch(this.currentTab) {
					case 0:
						status = 'unsigned' // 未签到
						break
					case 1:
						status = 'signed' // 已签到
						break
					case 2:
						status = 'cancelled' // 系统取消
						break
				}
				uni.navigateTo({
					url: `/subPages/my/myActivityDetail?id=${activity.id}&status=${status}`
				})
			},
			// scanQRCode(activity) {
			// 	// 扫码签到
			// 	uni.scanCode({
			// 		success: (res) => {
			// 			console.log('扫码结果:', res)
			// 			// 这里可以处理签到逻辑
			// 			uni.showToast({
			// 				title: '签到成功',
			// 				icon: 'success'
			// 			})
			// 		},
			// 		fail: (err) => {
			// 			console.log('扫码失败:', err)
			// 			uni.showToast({
			// 				title: '扫码失败',
			// 				icon: 'error'
			// 			})
			// 		}
			// 	})
			// }
		}
	}
</script>

<style lang="scss" scoped>
.my-registrations {
	background-color: #f5f5f5;
	min-height: 100vh;
	
	.custom-tabs {
		display: flex;
		background-color: #fff;
		border-bottom: 1rpx solid #e5e5e5;
		
		.tab-item {
			flex: 1;
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 30rpx 0;
			cursor: pointer;
			
			.tab-text {
				font-size: 28rpx;
				color: #666;
				transition: color 0.3s;
				
				&.active {
					color: #218cdd;
					font-weight: bold;
				}
			}
			
			.tab-line {
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translateX(-50%);
				width: 60rpx;
				height: 4rpx;
				background-color: #218cdd;
				border-radius: 2rpx;
			}
		}
	}
	
	.activity-list {
		padding: 20rpx;
		
		.activity-item {
			display: flex;
			margin-bottom: 30rpx;
			background: #fff;
			border-radius: 12rpx;
			padding: 20rpx;
			
			.activity-image {
				width: 180rpx;
				height: 180rpx;
				border-radius: 8rpx;
				margin-right: 20rpx;
			}
			
			.activity-info {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				
				.title-row {
					display: flex;
					align-items: center;
					margin-bottom: 10rpx;
					
					.activity-badge {
						width: 31px;
						height: 20px;
						background: #218cdd;
						border-radius: 3.5px;
						margin-right: 7rpx;
						display: flex;
						align-items: center;
						justify-content: center;

						.badge-text {
							font-size: 18rpx;
							color: #fff;
						}
					}
				}
				
				.activity-title {
					font-size: 28rpx;
					font-weight: bold;
					color: $uni-text-color;
				}
				
				.activity-location, .activity-time, .activity-participants {
					display: flex;
					align-items: center;
					margin-bottom: 6rpx;
					
					.location-text, .time-text, .participants-text {
						font-size: 24rpx;
						color: $uni-text-color-grey;
						margin-left: 6rpx;
					}
				}
			}
			
			.activity-action {
				display: flex;
				align-items: flex-end;
				padding-bottom: 10rpx;
			}
		}
		
		.empty-state {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 400rpx;
			
			.empty-text {
				font-size: 28rpx;
				color: $uni-text-color-grey;
			}
		}
	}
}
</style>