This commit is contained in:
那些花儿
2025-04-25 08:48:11 +08:00
parent 94656c9449
commit 89c2b07ca9
19 changed files with 1702 additions and 1604 deletions
+261 -214
View File
@@ -1,212 +1,248 @@
<template>
<view class="page-container">
<view class="search-block">
<t-search
v-model="pageForm.searchKeyword"
placeholder="搜索活动"
shape="round"
>
<template #action>
<t-button variant="text" @click="filterVisible = true">筛选</t-button>
</template>
</t-search>
</view>
<!-- 顶部搜索和筛选 -->
<view class="header">
<view class="search-container">
<t-search
v-model="pageForm.searchKeyword"
placeholder="搜索活动名称"
shape="round"
class="search-input"
@search="handleSearch"
/>
</view>
<!-- 筛选弹出层 -->
<t-popup
v-model:visible="filterVisible"
placement="top"
>
<view class="filter">
<view class="filter-header">
<t-button variant="text" @click="handleClearFilter">重置</t-button>
<text class="filter-title">筛选条件</text>
<t-button theme="primary" variant="text" @click="handleSearch">确定</t-button>
</view>
<t-cell-group title="状态">
<t-radio-group v-model="pageForm.status">
<t-radio
<!-- 状态筛选标签组 -->
<view class="filter-tabs">
<scroll-view scroll-x class="tabs-scroll-view" :show-scrollbar="false">
<view class="tabs-container">
<view
v-for="option in statusOptions"
:key="option.value"
:value="option.value"
:label="option.label"
borderless
/>
</t-radio-group>
</t-cell-group>
class="filter-tab"
:class="{ active: pageForm.status === option.value }"
@click="selectStatusFilter(option.value)"
>
{{ option.label }}
</view>
</view>
</scroll-view>
</view>
</t-popup>
</view>
<!-- 活动列表 -->
<scroll-view
style="overflow-y: auto;flex: 1"
:scroll-y="true"
:show-scrollbar="false"
@scrolltolower="onLoadMore"
:refresher-enabled="true"
@refresherrefresh="getListData(true)"
:refresher-triggered="refreshIng"
refresher-background="#f5f5f5"
<!-- 活动列表 - 使用scroll-view实现 -->
<scroll-view
scroll-y
class="list-scroll-view"
@scrolltolower="handleScrollToBottom"
refresher-enabled
:refresher-triggered="refresherTriggered"
@refresherrefresh="handleRefresh"
refresher-background="#f2f3f5"
>
<view class="card"
<view class="list-container">
<view
class="activity-card"
v-for="item in dataList"
:key="item.id"
@click="navigateToDetail(item.id)"
>
<view class="card-head">
<image :src="item.cover" mode="aspectFill" class="card-img"/>
<text class="card-tag" :class="getStatusClass(item.status)">
{{ getStatusText(item.status) }}
</text>
</view>
<view class="card-body">
<view class="card-title">{{ item.title }}</view>
<view class="card-info">
<view class="info-item">
报名时间
{{moment(item.signStartTime).format('YYYY-MM-DD HH:mm:ss')}}
{{moment(item.signEndTime).format('YYYY-MM-DD HH:mm:ss')}}
>
<view class="image-container">
<image :src="item.cover" mode="aspectFill" class="activity-image"/>
<view class="activity-time">
{{ formatTimeRange(item.startTime, item.endTime) }}
</view>
<view class="info-item">
活动时间
{{moment(item.startTime).format('YYYY-MM-DD HH:mm:ss')}}
{{moment(item.endTime).format('YYYY-MM-DD HH:mm:ss')}}
<view class="status-tag-container">
<t-tag
:theme="getTagTheme(getActivityStatus(item))"
size="medium"
shape="mark"
>{{ getStatusText(getActivityStatus(item)) }}
</t-tag>
</view>
</view>
<!-- <view class="card-footer">-->
<!-- <t-button-->
<!-- size="small"-->
<!-- shape="round"-->
<!-- :theme="item.status === 2 ? 'default' : 'primary'"-->
<!-- :disabled="item.status === 2"-->
<!-- >-->
<!-- {{ item.status === 1 ? '立即报名' : item.status === 3 ? '预约提醒' : '已结束' }}-->
<!-- </t-button>-->
<!-- </view>-->
<view class="activity-info">
<text class="activity-title">{{ item.title }}</text>
<view class="activity-address">
<t-icon name="location" size="small"/>
<text>{{ item.address || '暂无地址信息' }}</text>
</view>
</view>
</view>
</view>
<view class="loading-area">
<t-loading v-if="loading" text="加载中" layout="vertical"/>
<t-divider v-else-if="!hasMore && dataList.length > 0" content="没有更多了"/>
<!-- 加载状态 -->
<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 && !refreshIng && dataList.length === 0"
image="https://tdesign.gtimg.com/mobile/demos/empty1.png" description="暂无活动">
<template #action>
<t-button theme="primary" size="small" shape="round">刷新试试</t-button>
</template>
</t-empty>
<!-- 空状态 -->
<t-empty
v-if="!loading && dataList.length === 0"
description="暂无活动信息"
/>
</scroll-view>
</view>
</template>
<script setup>
import {ref, reactive, onMounted} from 'vue';
// 移除不再需要的onReachBottom和onPullDownRefresh
// import {onReachBottom, onPullDownRefresh} from "@dcloudio/uni-app";
import {Toast} from 'tdesign-mobile-vue';
import {useRequest} from "@/util/request";
import {useRequest} from "@/utils/request";
import moment from "moment";
// 筛选选项
// 活动状态筛选选项
const statusOptions = [
{value: '', label: '全部'},
{value: '1', label: '进行中'},
{value: '2', label: '已结束'},
{value: '3', 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: null,
status: null
})
searchKeyword: '',
status: '' // 全部
});
// 数据与状态
const dataList = ref([]);
const loading = ref(false);
const hasMore = ref(true);
const refreshIng = ref(false);
const filterVisible = ref(false);
// 添加下拉刷新状态
const refresherTriggered = ref(false);
// 获取状态样式类
const getStatusClass = (status) => {
return {
1: 'status-active',
2: 'status-ended',
3: 'status-upcoming'
}[status] || '';
// 获取活动状态
const getActivityStatus = (item) => {
const now = moment();
const signStartTime = moment(item.signStartTime);
const signEndTime = moment(item.signEndTime);
const activityStartTime = moment(item.startTime);
const activityEndTime = moment(item.endTime);
if (now.isBefore(signStartTime)) {
return 'notStartSign'; // 未开始报名
} else if (now.isBetween(signStartTime, signEndTime)) {
return 'signing'; // 报名中
} else if (now.isBetween(signEndTime, activityStartTime)) {
return 'notStartActivity'; // 活动未开始
} else if (now.isBetween(activityStartTime, activityEndTime)) {
return 'activitying'; // 活动进行中
} else {
return 'ended'; // 已结束
}
};
// 获取状态文本
const getStatusText = (status) => {
return {
1: '报名中',
2: '已结束',
3: '即将开始'
'notStartSign': '未开始报名',
'signing': '报名中',
'notStartActivity': '活动未开始',
'activitying': '活动进行中',
'ended': '已结束'
}[status] || '未知状态';
};
// 获取标签主题
const getTagTheme = (status) => {
return {
'notStartSign': 'primary',
'signing': 'success',
'notStartActivity': 'warning',
'activitying': 'info',
'ended': 'default'
}[status] || 'default';
};
// 格式化时间范围
const formatTimeRange = (startTime, endTime) => {
return `${moment(startTime).format('MM-DD')} ~ ${moment(endTime).format('MM-DD')}`;
};
// 选择状态筛选
const selectStatusFilter = (status) => {
pageForm.status = status;
handleSearch();
};
// 获取列表数据
const getListData = async (isRefresh = false) => {
if (loading.value) return;
loading.value = true;
if (isRefresh) {
refreshIng.value = true;
pageForm.pageNumber = 1;
} else {
loading.value = true
}
// 延时1秒,模拟网络请求
await new Promise(resolve => setTimeout(resolve, 1000));
try {
const {code, data, msg} = await useRequest().post('/client/activity/pageData', {
const response = await useRequest().post('/client/activity/pageData', {
...pageForm
})
});
if (response.code === 0) {
const {list, totalCount} = response.data;
if (code === 0) {
if (isRefresh) {
dataList.value = data.list;
dataList.value = list;
} else {
dataList.value = [...dataList.value, ...data.list];
dataList.value = [...dataList.value, ...list];
}
pageForm.totalCount = data.totalCount;
hasMore.value = dataList.value.length < data.totalCount;
pageForm.totalCount = totalCount;
hasMore.value = dataList.value.length < totalCount;
pageForm.pageNumber++;
console.log(hasMore.value)
} else {
console.error('获取列表失败', msg)
Toast({message: '获取列表失败', theme: 'error'});
Toast({message: '获取活动列表失败', theme: 'error'});
}
} catch (error) {
console.error('获取列表失败', error);
Toast({message: '获取列表失败', theme: 'error'});
console.error('获取活动列表失败', error);
Toast({message: '获取活动列表失败', theme: 'error'});
} finally {
loading.value = false;
refreshIng.value = false;
// 重置下拉刷新状态
if (refresherTriggered.value) {
refresherTriggered.value = false;
}
}
};
// scroll-view 下拉刷新
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();
getListData(true);
};
// 清空筛选
const handleClearFilter = () => {
pageForm.keyword = null
pageForm.status = null
filterVisible.value = false;
};
// 加载更多
const onLoadMore = () => {
// scroll-view 触底加载更多
const handleScrollToBottom = () => {
if (loading.value || !hasMore.value) return;
getListData();
};
@@ -224,130 +260,141 @@ onMounted(() => {
});
</script>
<style scoped>
.search-block {
<style lang="less" scoped>
.header {
background-color: #fff;
padding: 10px 16px;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);
padding: 16rpx 0;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
z-index: 10;
}
.filter {
background-color: #fff;
border-radius: 0 0 16px 16px;
padding: 0 16px 20px;
.search-container {
padding: 0 24rpx;
}
.filter-header {
.search-input {
width: 100%;
}
.filter-tabs {
margin-top: 20rpx;
padding: 0 12rpx;
}
.tabs-scroll-view {
white-space: nowrap;
width: 100%;
}
.tabs-container {
display: inline-flex;
padding: 0 12rpx;
}
.filter-tab {
display: inline-block;
padding: 10rpx 24rpx;
margin: 0 12rpx;
font-size: 26rpx;
color: #666;
background-color: #f5f5f5;
border-radius: 48rpx;
transition: all 0.3s;
&.active {
color: #fff;
background-color: var(--td-brand-color);
font-weight: 500;
}
}
.list-scroll-view {
flex: 1;
height: 0;
}
.list-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 0;
border-bottom: 1px solid #eee;
flex-direction: column;
padding: 20rpx 24rpx;
}
.filter-title {
font-weight: bold;
font-size: 16px;
}
.card {
.activity-card {
width: 100%;
margin-bottom: 24rpx;
background-color: #fff;
border-radius: 12px;
border-radius: 16rpx;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
margin: 10px;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
transition: transform 0.3s;
&:active {
transform: scale(0.98);
}
}
.card-head {
.image-container {
position: relative;
height: 160px;
height: 360rpx;
overflow: hidden;
}
.card-img {
.activity-image {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.4s;
.activity-card:hover & {
transform: scale(1.05);
}
}
.card-tag {
.activity-time {
position: absolute;
top: 12px;
right: 0;
padding: 4px 12px;
left: 16rpx;
bottom: 16rpx;
padding: 6rpx 16rpx;
background-color: rgba(0, 0, 0, 0.6);
color: #fff;
font-size: 12px;
font-weight: bold;
border-radius: 4px 0 0 4px;
font-size: 22rpx;
border-radius: 6rpx;
}
.status-active {
background-color: #28c445;
.activity-info {
padding: 20rpx 24rpx 10rpx;
}
.status-ended {
background-color: #999;
}
.status-upcoming {
background-color: #ff9800;
}
.card-body {
padding: 16px;
}
.card-title {
font-size: 16px;
font-weight: bold;
line-height: 1.4;
margin-bottom: 12px;
.activity-title {
width: 100%;
font-size: 32rpx;
font-weight: 500;
color: #333;
line-height: 1.4;
display: block;
}
.card-info {
margin-bottom: 12px;
}
.info-item {
.activity-address {
display: flex;
align-items: center;
font-size: 13px;
font-size: 26rpx;
color: #666;
margin-bottom: 6px;
margin-top: 12rpx;
}
.info-item :deep(i) {
margin-right: 6px;
.activity-address :deep(.t-icon) {
margin-right: 8rpx;
color: #999;
}
.card-footer {
display: flex;
justify-content: space-between;
align-items: center;
border-top: 1px solid #f0f0f0;
padding-top: 10px;
.status-tag-container {
position: absolute;
right: 0;
top: 16rpx;
}
.price {
display: flex;
align-items: baseline;
}
.price-symbol {
font-size: 14px;
color: #ff5050;
font-weight: bold;
}
.price-value {
font-size: 22px;
color: #ff5050;
font-weight: bold;
}
.loading-area {
padding: 16px 0;
.loading-container {
padding: 40rpx 0;
text-align: center;
}
</style>