<template>
|
<view class="container">
|
<view style="height:50rpx"></view>
|
<view class="add-button-container">
|
<button class="add-button" @click="handleAdd">
|
<u-icon name="plus" color="#fff" size="20"></u-icon>
|
<text>新增活动</text>
|
</button>
|
</view>
|
<u-empty v-if="mockData.length === 0 && !loading" mode="data"
|
icon="http://cdn.uviewui.com/uview/empty/data.png">
|
</u-empty>
|
<scroll-view scroll-y :lower-threshold="100" class="scroll-view-container">
|
<view v-for="(item, idx) in mockData" :key="idx" class="activity-item card" @click="handleItemClick(item)">
|
<view class="cover-container">
|
<block v-if="item.coverType === 'image' || item.coverType === 'video'">
|
<image :src="item.url" mode="aspectFill" class="activity-cover" />
|
</block>
|
<block v-if="item.coverType === 'text'">
|
<view class="activity-cover text-cover">{{ item.cover }}</view>
|
</block>
|
</view>
|
|
<!-- 活动信息 -->
|
<view class="activity-info">
|
<view class="info-header">
|
<view class="activity-title">{{ item.activityName }}</view>
|
</view>
|
|
<view class="activity-meta">
|
<view class="meta-item">
|
<u-icon name="calendar" size="16" color="#999"></u-icon>
|
<text class="activity-time">{{ item.startTime }} - {{ item.endTime }}</text>
|
</view>
|
<view class="meta-item">
|
<u-icon name="map" size="16" color="#999"></u-icon>
|
<text class="activity-location">{{ item.activityLocation || '待定' }}</text>
|
</view>
|
</view>
|
</view>
|
</view>
|
<!-- 改进的加载更多提示 -->
|
<view class="load-more">
|
<u-loadmore :status="loading ? 'loading' : noMore ? 'nomore' : 'loadmore'" :load-text="{
|
loadmore: '上拉加载更多',
|
loading: '正在加载',
|
nomore: '没有更多了'
|
}" />
|
</view>
|
<view style="height:150rpx">
|
|
</view>
|
</scroll-view>
|
</view>
|
</template>
|
|
<script>
|
import TopBar from "@/components/TopBar.vue";
|
import '@/components/uview-components/uview-ui';
|
import {
|
addActivityByBuyer,
|
applyActivityPage
|
} from '@/api/activity.js'
|
export default {
|
|
data() {
|
return {
|
scrollViewTop: uni.upx2px(50 + 80 + 40), // 50rpx空白 + 80rpx按钮 + 40rpx边距
|
scrollViewBottom: uni.upx2px(120), // 底部预留
|
query: {
|
pageNumber: 1,
|
pageSize: 5,
|
|
},
|
loading: false,
|
total: 0,
|
mockData: [],
|
noMore: false,
|
}
|
},
|
//下拉刷新
|
onPullDownRefresh() {
|
//初始化页面参数
|
this.mockData = [];
|
this.query.pageNumber = 1;
|
//调用获取数据方法
|
this.getPage()
|
setTimeout(() => {
|
//结束下拉刷新
|
uni.stopPullDownRefresh();
|
}, 1000);
|
},
|
onReachBottom() {
|
this.loadMore()
|
},
|
mounted() {
|
|
},
|
onLoad() {
|
this.getPage();
|
uni.$on('refreshParentPage', this.getPage);
|
},
|
onUnload() {
|
uni.$off('refreshParentPage', this.getPage);
|
},
|
methods: {
|
loadMore() {
|
// 显示加载状态
|
this.loading = true;
|
|
// 延迟执行让UI有反应时间
|
setTimeout(() => {
|
this.query.pageNumber += 1;
|
this.getPage();
|
}, 300);
|
},
|
handleAdd() {
|
uni.navigateTo({
|
url: `/pages/mine/activity/addActivity` // 参数通过 URL 传递
|
});
|
},
|
handleItemClick(item) {
|
console.log(item)
|
},
|
async getPage() {
|
try {
|
const res = await applyActivityPage(this.query);
|
this.loading = false;
|
if (res.statusCode === 200) {
|
const newData = res.data.data;
|
// 更新总数据量
|
this.total = res.data.total || 0;
|
// 追加或替换数据
|
this.mockData = this.query.pageNumber === 1 ?
|
newData : [...this.mockData, ...newData];
|
// 判断是否还有更多数据
|
this.noMore = newData.length < this.query.pageSize ||
|
this.mockData.length >= this.total;
|
}
|
|
} catch (error) {
|
console.error('加载失败:', error);
|
// 失败时回退页码
|
if (this.query.pageNumber > 1) {
|
this.query.pageNumber -= 1;
|
}
|
} finally {
|
this.loading = false;
|
uni.hideLoading();
|
uni.stopPullDownRefresh();
|
}
|
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
/* 滑动框样式整体样式优化*/
|
.scroll-view-container {
|
flex: 1;
|
overflow: hidden;
|
padding: 0 20rpx;
|
box-sizing: border-box;
|
/* 确保可以滚动 */
|
-webkit-overflow-scrolling: touch;
|
}
|
|
.load-more {
|
padding: 20rpx 0;
|
text-align: center;
|
color: #999;
|
font-size: 26rpx;
|
background-color: #f8f9fa;
|
}
|
|
.container {
|
min-height: 100vh;
|
display: flex;
|
flex-direction: column;
|
}
|
|
|
|
|
|
|
/* 新增按钮样式 */
|
.add-button-container {
|
padding: 20rpx 30rpx;
|
background-color: #f7f8fa;
|
}
|
|
.add-button {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background-color: #2979ff;
|
color: #fff;
|
border-radius: 50rpx;
|
height: 80rpx;
|
line-height: 80rpx;
|
font-size: 30rpx;
|
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.3);
|
|
.u-icon {
|
margin-right: 10rpx;
|
}
|
|
&::after {
|
border: none;
|
}
|
|
&:active {
|
background-color: #1a6eff;
|
transform: scale(0.98);
|
}
|
}
|
|
.container {
|
padding: 0;
|
background-color: #f7f8fa;
|
height: auto;
|
}
|
|
|
/* 活动列表样式 */
|
.activity-list {
|
padding: 20rpx 24rpx;
|
}
|
|
.card {
|
background: #fff;
|
border-radius: 16rpx;
|
margin-bottom: 24rpx;
|
overflow: hidden;
|
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
|
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
|
&:active {
|
transform: scale(0.98);
|
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
|
}
|
}
|
|
.activity-item {
|
display: flex;
|
padding: 24rpx;
|
}
|
|
.cover-container {
|
position: relative;
|
width: 200rpx;
|
height: 200rpx;
|
border-radius: 12rpx;
|
overflow: hidden;
|
margin-right: 24rpx;
|
flex-shrink: 0;
|
}
|
|
.activity-cover {
|
width: 100%;
|
height: 100%;
|
border-radius: 12rpx;
|
}
|
|
.text-cover {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
|
color: #fff;
|
font-size: 28rpx;
|
padding: 16rpx;
|
line-height: 1.4;
|
}
|
|
.activity-info {
|
flex: 1;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.info-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: flex-start;
|
margin-bottom: 16rpx;
|
}
|
|
.activity-title {
|
flex: 1;
|
font-size: 32rpx;
|
color: #333;
|
font-weight: 500;
|
margin-right: 16rpx;
|
display: -webkit-box;
|
-webkit-box-orient: vertical;
|
-webkit-line-clamp: 2;
|
overflow: hidden;
|
line-height: 1.4;
|
}
|
|
.activity-meta {
|
font-size: 24rpx;
|
color: #999;
|
margin-bottom: 16rpx;
|
}
|
|
.meta-item {
|
display: flex;
|
align-items: center;
|
margin-bottom: 12rpx;
|
|
.u-icon {
|
margin-right: 8rpx;
|
}
|
}
|
|
.activity-status {
|
font-size: 24rpx;
|
padding: 6rpx 16rpx;
|
border-radius: 20rpx;
|
flex-shrink: 0;
|
|
&.signed {
|
color: #2979ff;
|
background-color: rgba(41, 121, 255, 0.1);
|
}
|
|
&.ended {
|
color: #909399;
|
background-color: rgba(144, 147, 153, 0.1);
|
}
|
|
&.canceled {
|
color: #fa3534;
|
background-color: rgba(250, 53, 52, 0.1);
|
}
|
}
|
|
/* 操作按钮 */
|
.action-container {
|
display: flex;
|
justify-content: flex-end;
|
margin-top: auto;
|
padding-top: 16rpx;
|
}
|
|
.cancel-btn {
|
background: #fef0f0;
|
color: #fa3534;
|
border: none;
|
border-radius: 40rpx;
|
padding: 0 32rpx;
|
height: 64rpx;
|
line-height: 64rpx;
|
font-size: 26rpx;
|
transition: all 0.3s ease;
|
|
&::after {
|
border: none;
|
}
|
|
&.cancel-btn-hover {
|
background: #fde2e2;
|
transform: scale(0.98);
|
}
|
}
|
</style>
|