<template>
	<view class="activities-page">
		<!-- 自定义导航栏 -->
		<view class="custom-navbar">
			<view class="navbar-left" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<view class="navbar-title">活动列表</view>
			<view class="navbar-right"></view>
		</view>

		<!-- 活动列表 -->
		<view class="activity-list">
			<view class="activity-card" v-for="(item, index) in activityList" :key="index"
				@click="goToDetail(item.id)">
				<image :src="item.cover_image" class="activity-image" mode="aspectFill"></image>
				<view class="activity-info">
					<view class="activity-name">{{ item.name }}</view>
					<view class="activity-meta">
                        <text class="activity-time">⏰ {{ formatTime(item.start_time) }}</text>
						<text class="activity-location">📍 {{ item.location }}</text>
					</view>
					<view class="activity-footer">
						<view class="activity-price">
							<text class="price-symbol">¥</text>
							<text class="price-value">{{ item.price }}</text>
						</view>
						<view class="activity-btn">立即报名</view>
					</view>
				</view>
				<view class="hot-tag" v-if="item.is_hot">HOT</view>
			</view>
		</view>

		<!-- 加载更多 -->
		<view class="load-more" v-if="hasMore">
			<text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
		</view>
		<view class="no-more" v-else>
			<text class="no-more-text">没有更多了</text>
		</view>
	</view>
</template>

<script>
	import api from '@/utils/api.js'
	import { formatTime } from '@/utils/util.js'
	import { DEFAULT_IMAGES } from '@/config/index.js'

	export default {
		data() {
			return {
				activityList: [],
				pageNum: 1,
				pageSize: 10,
				hasMore: true,
				loading: false
			}
		},

		onLoad() {
			this.loadActivityList()
		},

		onReachBottom() {
			if (this.hasMore && !this.loading) {
				this.pageNum++
				this.loadActivityList()
			}
		},

		methods: {
			// 加载活动列表
			async loadActivityList() {
				if (this.loading) return
				this.loading = true

				try {
					const data = await api.activity.getList({
						pageNum: this.pageNum,
						pageSize: this.pageSize,
						status: 1
					})

					if (data && data.length > 0) {
						this.activityList = [...this.activityList, ...data]
						this.hasMore = data.length >= this.pageSize
					} else {
						this.hasMore = false
					}
				} catch (error) {
					console.error('加载活动列表失败:', error)
					uni.showToast({
						title: '加载失败',
						icon: 'none'
					})
				} finally {
					this.loading = false
				}
			},

			// 格式化时间
			formatTime,

			// 跳转到详情
			goToDetail(id) {
				uni.navigateTo({
					url: `/pages/activities/detail?id=${id}`
				})
			},

			// 返回
			goBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.activities-page {
		min-height: 100vh;
		background-color: #FFF9F9;
		padding-top: 90rpx;
	}

	/* 自定义导航栏 */
	.custom-navbar {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 20rpx;
		background-color: #E91E63;
		z-index: 999;

		.navbar-left,
		.navbar-right {
			width: 80rpx;
		}

		.back-icon {
			font-size: 40rpx;
			color: #FFFFFF;
			font-weight: bold;
		}

		.navbar-title {
			flex: 1;
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	/* 活动列表 */
	.activity-list {
		padding: 20rpx 30rpx;

		.activity-card {
			position: relative;
			display: flex;
			margin-bottom: 20rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			overflow: hidden;
			box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);

			.activity-image {
				width: 260rpx;
				height: 260rpx;
				background-color: #F5F5F5;
			}

			.activity-info {
				flex: 1;
				padding: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.activity-name {
					font-size: 30rpx;
					font-weight: bold;
					color: #333333;
					margin-bottom: 10rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}

				.activity-meta {
					display: flex;
					flex-direction: column;
					gap: 8rpx;
					font-size: 24rpx;
					color: #666666;

					.activity-location {
						color: #999999;
					}
				}

				.activity-footer {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 10rpx;

					.activity-price {
						color: #E91E63;
						font-weight: bold;

						.price-symbol {
							font-size: 24rpx;
						}

						.price-value {
							font-size: 36rpx;
						}
					}

					.activity-btn {
						padding: 10rpx 30rpx;
						background-color: #E91E63;
						color: #FFFFFF;
						text-align: center;
						border-radius: 30rpx;
						font-size: 24rpx;
					}
				}
			}

			.hot-tag {
				position: absolute;
				top: 10rpx;
				left: 10rpx;
				padding: 5rpx 15rpx;
				background: linear-gradient(135deg, #FF6B6B 0%, #FF9800 100%);
				color: #FFFFFF;
				font-size: 20rpx;
				font-weight: bold;
				border-radius: 10rpx;
			}
		}
	}

	/* 加载更多 */
	.load-more,
	.no-more {
		padding: 30rpx 0;
		text-align: center;

		.load-text,
		.no-more-text {
			font-size: 24rpx;
			color: #999999;
		}
	}
</style>


