Files
hmc_gbhd/frontend/src/pages/activity/list/index.vue
T
2026-09-29 13:41:27 +08:00

290 lines
7.9 KiB
Vue

<template>
<view class="page-container">
<view class="header">
<view class="search-container">
<t-search
v-model="pageForm.searchKeyword"
placeholder="搜索活动名称"
shape="round"
class="search-input"
@onSearch="handleSearch"
@onSubmit="handleSearch"
@submit="handleSearch"
@search="handleSearch"
/>
</view>
</view>
<scroll-view
scroll-y
class="list-scroll-view"
@scrolltolower="handleScrollToBottom"
refresher-enabled
:refresher-triggered="refresherTriggered"
@refresherrefresh="handleRefresh"
refresher-background="#f2f3f5"
>
<view class="list-container">
<view
class="card-item"
v-for="item in dataList"
:key="item.id"
@click="navigateToDetail(item.id)"
>
<view>
<view style="display: flex;align-items: center;margin-bottom: 10px">
<image
src="https://assets.cumen.fun/upload/017cdaf1-c5fa-788e-eea2-d0ee249f902b/0187376a-3cfa-07b3-3cd6-7479bf463865?x-oss-process=style/720-jpg"
style="width: 30px;height: 30px;flex-shrink: 0"
></image>
<view
style="margin-left: 10px;font-weight: 600;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
{{ item.title }}
</view>
</view>
<view style="display: flex;">
<t-image :src=config.fileDomain+item.cover shape="round"
style="flex-shrink:0;width: 120px;height: 90px;border-radius: 5px;" fit="fill"/>
<view
style="margin-left:10px;flex:1;overflow:hidden;display: flex;flex-direction: column;justify-content:space-around;color: #534d4d;">
<view class="activity-date-tag">
<t-icon name="time"></t-icon>
<text>{{ moment(item.startTime).format('YYYY年MM月DD日') }}</text>
</view>
<view style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<t-icon name="location"></t-icon>
{{ item.address }}
</view>
<view style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<t-icon name="castle-7"></t-icon>
{{ item.hostUnit }}
</view>
</view>
</view>
<view style="border-top: 1px solid #f0f0f0;margin-top: 10px;padding-top: 12px;display: flex;align-items: center;justify-content: space-between">
<view>
<!-- 100人已报名-->
</view>
<view style="display: flex;gap: 10px" @click.stop>
<t-button theme="default" variant="outline" shape="round" size="small"
@click="navigateToDetail(item.id)"><t-icon name="browse" size="16px" style="margin-right: 4px"/>查看详情</t-button>
<t-button theme="primary" shape="round" size="small"
@click="navigateToSignUp(item.id)"><t-icon name="edit" size="16px" style="margin-right: 4px"/>立即报名</t-button>
</view>
</view>
</view>
</view>
</view>
<!-- 加载状态 -->
<view class="loading-container">
<t-loading v-if="loading" text="加载中..." layout="vertical" theme="circular" size="40rpx"/>
<t-divider v-else-if="!hasMore && dataList.length > 0" content="没有更多活动了"/>
</view>
<!-- 空状态 -->
<t-empty
v-if="!loading && dataList.length === 0"
description="暂无活动信息"
/>
</scroll-view>
</view>
</template>
<script setup>
import {ref, reactive, onMounted} from 'vue';
import {Toast} from 'tdesign-mobile-vue';
import {useRequest} from "@/utils/request";
import moment from "moment";
import {config} from "@/utils/config";
// 活动状态筛选选项
const statusOptions = [
{value: '', label: '全部'},
{value: 'notStartSign', label: '未开始报名'},
{value: 'signing', label: '报名中'},
{value: 'notStartActivity', label: '活动未开始'},
{value: 'activitying', label: '活动进行中'},
{value: 'ended', label: '已结束'}
];
// 页面表单数据
const pageForm = reactive({
pageNumber: 1,
pageSize: 10,
totalCount: 0,
searchKeyword: '',
status: '' // 全部
});
// 数据与状态
const dataList = ref([]);
const loading = ref(false);
const hasMore = ref(true);
const refresherTriggered = ref(false);
// 选择状态筛选
const selectStatusFilter = (status) => {
pageForm.status = status;
handleSearch();
};
// 获取列表数据
const getListData = async (isRefresh = false) => {
if (loading.value) return;
loading.value = true;
if (isRefresh) {
pageForm.pageNumber = 1;
}
// 延时1秒,模拟网络请求
await new Promise(resolve => setTimeout(resolve, 1000));
try {
const response = await useRequest().post('/client/activity/pageData', {
...pageForm
});
if (response.code === 0) {
const {list, totalCount} = response.data;
if (isRefresh) {
dataList.value = list;
} else {
dataList.value = [...dataList.value, ...list];
}
pageForm.totalCount = totalCount;
hasMore.value = dataList.value.length < totalCount;
pageForm.pageNumber++;
} else {
Toast({message: response.msg, theme: 'error'});
}
} catch (error) {
console.error('获取活动列表失败', error);
} finally {
loading.value = false;
// 重置下拉刷新状态
if (refresherTriggered.value) {
refresherTriggered.value = false;
}
}
};
//下拉刷新
const handleRefresh = () => {
if (loading.value) {
refresherTriggered.value = false;
return;
}
refresherTriggered.value = true;
pageForm.pageNumber = 1;
getListData(true);
};
// 搜索处理
const handleSearch = () => {
pageForm.pageNumber = 1;
hasMore.value = true;
dataList.value = [];
getListData(true);
};
// 触底加载更多
const handleScrollToBottom = () => {
if (loading.value || !hasMore.value) return;
getListData();
};
// 跳转详情
const navigateToDetail = (id) => {
uni.navigateTo({
url: `/pages/activity/detail/index?id=${id}`
});
};
// 报名按钮直达表单,活动ID沿用详情页的报名入口参数。
const navigateToSignUp = (id) => {
uni.navigateTo({
url: `/pages/activity/registration-form/index?id=${id}`
});
};
// 初始化
onMounted(() => {
getListData();
});
</script>
<style lang="less" scoped>
.header {
background-color: #fff;
padding: 16rpx 0;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
z-index: 10;
}
.search-container {
padding: 0 24rpx;
}
.search-input {
width: 100%;
}
.list-scroll-view {
flex: 1;
height: 0;
}
.list-container {
display: flex;
flex-direction: column;
padding: 20rpx 24rpx;
}
.card-item {
width: 100%;
margin-bottom: 24rpx;
border-radius: 16rpx;
padding: 24rpx;
overflow: hidden;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
transition: transform 0.3s;
//background: url("https://assets.cumen.fun/upload/017cdaf1-c5fa-788e-eea2-d0ee249f902b/0189257e-fc75-5b89-b900-104c706f2d63") top / 100% auto no-repeat,
//linear-gradient(to right, white, #ecb5b5);
//background: no-repeat, linear-gradient(to right, white, #f6d4d4);
background: #ffffff;
&:active {
transform: scale(0.98);
}
}
.activity-date-tag {
align-self: flex-start;
display: inline-flex;
align-items: center;
column-gap: 4px;
max-width: 100%;
padding: 4px 8px;
border-radius: 12px;
box-sizing: border-box;
color: var(--td-brand-color);
background-color: rgba(25, 137, 250, 0.12);
font-size: 12px;
line-height: 1.2;
white-space: nowrap;
}
.loading-container {
padding: 40rpx 0;
text-align: center;
}
</style>