first commit
This commit is contained in:
@@ -0,0 +1,372 @@
|
||||
<template>
|
||||
<view class="page-container">
|
||||
<!-- 顶部搜索区域 -->
|
||||
<view class="header">
|
||||
<t-search
|
||||
v-model="pageForm.searchKeyword"
|
||||
placeholder="搜索活动"
|
||||
shape="round"
|
||||
class="search"
|
||||
>
|
||||
<template #action>
|
||||
<t-button variant="text" @click="filterVisible = true">筛选</t-button>
|
||||
</template>
|
||||
</t-search>
|
||||
</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
|
||||
v-for="option in statusOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
borderless
|
||||
/>
|
||||
</t-radio-group>
|
||||
</t-cell-group>
|
||||
</view>
|
||||
</t-popup>
|
||||
|
||||
<!-- 活动列表 -->
|
||||
<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"
|
||||
>
|
||||
<view class="card"
|
||||
v-for="item in dataList"
|
||||
:key="item.id"
|
||||
@click="navigateToDetail(item.id)"
|
||||
>
|
||||
<view class="card-head">
|
||||
<image :src="item.image" 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">
|
||||
<t-icon name="alarm" size="12px"/>
|
||||
<text>{{ item.date }}</text>
|
||||
</view>
|
||||
<view class="info-item">
|
||||
<t-icon name="location" size="12px"/>
|
||||
<text>{{ item.location }}</text>
|
||||
</view>
|
||||
<view class="info-item">
|
||||
<t-icon name="user" size="12px"/>
|
||||
<text>{{ item.participants }}人已报名</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card-footer">
|
||||
<view class="price">
|
||||
<text class="price-symbol">¥</text>
|
||||
<text class="price-value">{{ item.price }}</text>
|
||||
</view>
|
||||
<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>
|
||||
</view>
|
||||
|
||||
<view class="loading-area">
|
||||
<t-loading v-if="loading" text="加载中" layout="vertical"/>
|
||||
<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>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {ref, reactive, onMounted} from 'vue';
|
||||
import {Toast} from 'tdesign-mobile-vue';
|
||||
import {useRequest} from "@/util/request";
|
||||
|
||||
// 筛选选项
|
||||
const statusOptions = [
|
||||
{value: '', label: '全部'},
|
||||
{value: '1', label: '进行中'},
|
||||
{value: '2', label: '已结束'},
|
||||
{value: '3', label: '未开始'}
|
||||
];
|
||||
|
||||
const pageForm = reactive({
|
||||
pageNumber: 1,
|
||||
pageSize: 10,
|
||||
totalCount: 0,
|
||||
searchKeyword: null,
|
||||
status: null
|
||||
})
|
||||
|
||||
// 数据与状态
|
||||
const dataList = ref([]);
|
||||
const loading = ref(false);
|
||||
const hasMore = ref(true);
|
||||
const refreshIng = ref(false);
|
||||
const filterVisible = ref(false);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
keyword: '',
|
||||
status: ''
|
||||
});
|
||||
|
||||
// 获取状态样式类
|
||||
const getStatusClass = (status) => {
|
||||
return {
|
||||
1: 'status-active',
|
||||
2: 'status-ended',
|
||||
3: 'status-upcoming'
|
||||
}[status] || '';
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (status) => {
|
||||
return {
|
||||
1: '报名中',
|
||||
2: '已结束',
|
||||
3: '即将开始'
|
||||
}[status] || '未知状态';
|
||||
};
|
||||
|
||||
// 获取列表数据
|
||||
const getListData = async (isRefresh = false) => {
|
||||
if (isRefresh) {
|
||||
refreshIng.value = true;
|
||||
pageForm.pageNumber = 1;
|
||||
} else {
|
||||
loading.value = true
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
try {
|
||||
const {code, data, msg} = await useRequest().post('/client/activity/pageData', {
|
||||
...pageForm
|
||||
})
|
||||
|
||||
if (code === 0) {
|
||||
if (isRefresh) {
|
||||
dataList.value = data.list;
|
||||
} else {
|
||||
dataList.value = [...dataList.value, ...data.list];
|
||||
}
|
||||
hasMore.value = dataList.value.length < data.totalCount;
|
||||
pageForm.pageNumber++;
|
||||
console.log(hasMore.value)
|
||||
} else {
|
||||
console.error('获取列表失败', msg)
|
||||
Toast({message: '获取列表失败', theme: 'error'});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取列表失败', error);
|
||||
Toast({message: '获取列表失败', theme: 'error'});
|
||||
} finally {
|
||||
loading.value = false;
|
||||
refreshIng.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = () => {
|
||||
hasMore.value = true;
|
||||
dataList.value = [];
|
||||
getListData();
|
||||
};
|
||||
|
||||
// 清空筛选
|
||||
const handleClearFilter = () => {
|
||||
pageForm.keyword = null
|
||||
pageForm.status = null
|
||||
filterVisible.value = false;
|
||||
};
|
||||
|
||||
// 加载更多
|
||||
const onLoadMore = () => {
|
||||
if (loading.value || !hasMore.value) return;
|
||||
getListData();
|
||||
};
|
||||
|
||||
// 跳转详情
|
||||
const navigateToDetail = (id) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/detail/index?id=${id}`
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getListData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header {
|
||||
background-color: #fff;
|
||||
padding: 10px 16px;
|
||||
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.search {
|
||||
--td-search-bg-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.filter {
|
||||
background-color: #fff;
|
||||
border-radius: 0 0 16px 16px;
|
||||
padding: 0 16px 20px;
|
||||
}
|
||||
|
||||
.filter-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.filter-title {
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: #fff;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.card-head {
|
||||
position: relative;
|
||||
height: 160px;
|
||||
}
|
||||
|
||||
.card-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.card-tag {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 0;
|
||||
padding: 4px 12px;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px 0 0 4px;
|
||||
}
|
||||
|
||||
.status-active {
|
||||
background-color: #28c445;
|
||||
}
|
||||
|
||||
.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;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.card-info {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.info-item :deep(i) {
|
||||
margin-right: 6px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.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;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user