|
|
- <template>
- <view class="activity-page">
- <!-- 搜索栏和一级Tab合并容器 -->
- <view class="search-section">
- <view class="search-bar">
- <uv-icon name="search" size="18" color="#999"></uv-icon>
- <input type="text" placeholder="搜索活动名称" class="search-input" v-model="searchKeyword" />
- </view>
-
- <!-- 一级Tab:当前活动/往期活动 移到搜索容器内 -->
- <view class="primary-tabs">
- <view
- class="primary-tab-item"
- :class="{ active: primaryActiveTab === 'current' }"
- @click="switchPrimaryTab('current')"
- >
- 当前活动
- </view>
- <view
- class="primary-tab-item"
- :class="{ active: primaryActiveTab === 'past' }"
- @click="switchPrimaryTab('past')"
- >
- 往期活动
- </view>
- </view>
- </view>
-
- <!-- 二级Tab:使用uv-tabs组件 -->
- <view class="secondary-tabs">
- <uv-tabs
- :list="secondaryTabs"
- :current="secondaryActiveIndex"
- @change="switchSecondaryTab"
- lineColor="#007AFF"
- activeColor="#007AFF"
- inactiveColor="#666"
- :lineWidth="30"
- :lineHeight="3"
- itemStyle="padding: 10px 20px;"
- ></uv-tabs>
- </view>
-
- <!-- 活动列表 -->
- <view class="activity-list">
- <view
- class="activity-item"
- v-for="(item, index) in filteredActivities"
- :key="index"
- @click="goToActivityDetail(item)"
- >
- <!-- 活动图片 -->
- <view class="activity-image">
- <image :src="item.image" mode="aspectFill" class="image"></image>
- </view>
-
- <!-- 活动信息 -->
- <view class="activity-info">
- <view class="title-row">
- <!-- 活动标签 -->
- <view class="activity-tag" :style="{ backgroundColor: item.tagColor }">
- {{ item.tag }}
- </view>
- <view class="activity-title">{{ item.title }}</view>
- </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 type="primary" size="mini" shape="circle" :text="item.isFullOrExpired ? '已结束' : '报名中'" :disabled="item.isFullOrExpired" @click.stop="signUpActivity(item)"></uv-button>
- </view>
- </view>
- </view>
-
- <!-- 空状态 -->
- <view class="empty-state" v-if="filteredActivities.length === 0">
- <uv-empty mode="data" text="暂无活动数据"></uv-empty>
- </view>
- </view>
- </template>
-
- <script>
- export default {
- data() {
- return {
- searchKeyword: '',
- primaryActiveTab: 'current', // current: 当前活动, past: 往期活动
- secondaryActiveIndex: 0,
- secondaryTabs: [
- { name: '全部' },
- { name: '品牌项目' },
- { name: '公益活动' },
- { name: '培训活动' }
- ],
- // 模拟活动数据
- activities: [
- {
- id: 1,
- title: '关爱自闭症儿童活动',
- location: '长沙市雨花区时代阳光大道国际人才2145',
- time: '2025/08/1-2025/09/01',
- participants: 12,
- maxParticipants: 30,
- image: '/static/bannerImage.png',
- tag: '30分',
- tagColor: '#007AFF',
- category: 'charity', // all, brand, charity, training
- status: 'current', // current, past
- isFullOrExpired: false
- },
- {
- id: 2,
- title: '社区环保志愿服务',
- location: '长沙市岳麓区梅溪湖国际新城',
- time: '2025/07/15-2025/07/20',
- participants: 25,
- maxParticipants: 40,
- image: '/static/bannerImage.png',
- tag: '20分',
- tagColor: '#52C41A',
- category: 'charity',
- status: 'current',
- isFullOrExpired: false
- },
- {
- id: 3,
- title: '青少年编程培训',
- location: '长沙市开福区万达广场',
- time: '2025/06/01-2025/06/30',
- participants: 30,
- maxParticipants: 30,
- image: '/static/bannerImage.png',
- tag: '50分',
- tagColor: '#FF6B35',
- category: 'training',
- status: 'past',
- isFullOrExpired: true
- },
- {
- id: 4,
- title: '品牌推广活动',
- location: '长沙市天心区IFS国金中心',
- time: '2025/05/10-2025/05/15',
- participants: 18,
- maxParticipants: 25,
- image: '/static/bannerImage.png',
- tag: '40分',
- tagColor: '#722ED1',
- category: 'brand',
- status: 'past',
- isFullOrExpired: true
- }
- ]
- }
- },
- computed: {
- filteredActivities() {
- let filtered = this.activities;
-
- // 根据一级tab筛选
- filtered = filtered.filter(item => item.status === this.primaryActiveTab);
-
- // 根据二级tab筛选
- const categoryMap = {
- 0: 'all',
- 1: 'brand',
- 2: 'charity',
- 3: 'training'
- };
-
- const selectedCategory = categoryMap[this.secondaryActiveIndex];
- if (selectedCategory !== 'all') {
- filtered = filtered.filter(item => item.category === selectedCategory);
- }
-
- // 根据搜索关键词筛选
- if (this.searchKeyword.trim()) {
- filtered = filtered.filter(item =>
- item.title.toLowerCase().includes(this.searchKeyword.toLowerCase())
- );
- }
-
- return filtered;
- }
- },
- methods: {
- // 切换一级tab
- switchPrimaryTab(tab) {
- this.primaryActiveTab = tab;
- },
-
- // 切换二级tab
- switchSecondaryTab(index) {
- this.secondaryActiveIndex = index;
- },
-
- // 跳转到活动详情
- goToActivityDetail(activity) {
- uni.navigateTo({
- url: `/subPages/index/activityDetail?id=${activity.id}`
- });
- },
-
- // 报名活动
- signUpActivity(item) {
- if (item.isFullOrExpired) {
- uni.showToast({
- title: '活动已结束',
- icon: 'none'
- });
- return;
- }
- uni.navigateTo({
- url: `/subPages/index/activityDetail?id=${item.id}`
- });
- }
- },
-
- onLoad() {
- // 页面加载时的初始化逻辑
- console.log('活动页面加载完成');
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .activity-page {
- background-color: #f5f5f5;
- min-height: 100vh;
- }
-
- // 搜索栏样式 - 修改为包含一级Tab
- .search-section {
- height: 350rpx;
- background: linear-gradient(180deg,#1488db, #98b5f1);
- padding-top: 180rpx; /* 使用padding-top避免margin塌陷 */
- box-sizing: border-box; /* 确保padding包含在高度内 */
- }
-
- .search-bar {
- background-color: white;
- border-radius: 50rpx;
- padding: 20rpx 30rpx;
- display: flex;
- align-items: center;
- gap: 20rpx;
- width: 85%;
- margin: 0 auto ; /* 移除margin-top,只保留左右居中和下边距 */
- }
-
- .search-input {
- flex: 1;
- font-size: 28rpx;
- color: #333;
-
- &::placeholder {
- color: #999;
- }
- }
-
- // 一级Tab样式 - 调整为在蓝色背景内
- .primary-tabs {
- display: flex;
- padding: 0 20rpx;
- margin-bottom: 20rpx;
- }
-
- .primary-tab-item {
- flex: 1;
- text-align: center;
- padding: 20rpx 0;
- font-size: 32rpx;
- color: #000000; /* 白色半透明 */
- position: relative;
-
- &.active {
- color: white; /* 激活状态为纯白色 */
- font-weight: 600;
-
- &::after {
- content: '';
- position: absolute;
- bottom: 0;
- left: 50%;
- transform: translateX(-50%);
- width: 100rpx;
- height: 6rpx;
- background-color: white; /* 下划线改为白色 */
- border-radius: 3rpx;
- }
- }
- }
-
- // 二级Tab样式 - 保持不变
- .secondary-tabs {
- background-color: white;
- border-bottom: 1px solid #f0f0f0;
- }
-
- // 活动列表样式
- .activity-list {
- padding: 20rpx;
- }
-
- .activity-item {
- background-color: white;
- border-radius: 12rpx;
- margin-bottom: 30rpx;
- padding: 20rpx;
- display: flex;
- box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
- }
-
- .activity-image {
- width: 180rpx;
- height: 180rpx;
- border-radius: 8rpx;
- overflow: hidden;
- flex-shrink: 0;
- margin-right: 20rpx;
- }
-
- .image {
- width: 100%;
- height: 100%;
- }
-
- .activity-info {
- flex: 1;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
-
- .title-row {
- display: flex;
- align-items: center;
- margin-bottom: 10rpx;
- }
-
- .activity-tag {
- width: 31px;
- height: 20px;
- background: #218cdd;
- border-radius: 3.5px;
- margin-right: 7rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 18rpx;
- color: white;
- font-weight: 600;
- }
-
- .activity-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- line-height: 1.4;
- }
-
- .activity-location,
- .activity-time,
- .activity-participants {
- display: flex;
- align-items: center;
- margin-bottom: 6rpx;
-
- .location-text,
- .time-text,
- .participants-text {
- font-size: 24rpx;
- color: #666;
- margin-left: 6rpx;
- }
- }
-
- .activity-action {
- display: flex;
- align-items: flex-end;
- padding-bottom: 10rpx;
- }
-
- // 空状态样式
- .empty-state {
- padding: 100rpx 40rpx;
- }
- </style>
|