feat: optimize activity list page

This commit is contained in:
davy 2025-03-31 14:29:15 +08:00
parent d53c847ff7
commit a58ff14117

View File

@ -1,25 +1,40 @@
<template> <template>
<view class="page">
<view class="page-content flex-col"> <view class="page-content flex-col">
<view class="bg-zd" style="height: 526rpx;border-radius: 0 0 100rpx 100rpx;margin-bottom: 20rpx;" <!-- 筛选导航 -->
:style="{'padding-top': statusBaeHeight + 60 + 'px'}"> <view class="filter-tabs">
<view class="padding-lr flex justify-between"> <view class="tabs-content">
<template> <view
<view class="text-sm tag" :class="{'active-tag': curTag == 0}" @click="changeTag(0)">ALL</view> class="tab-item"
<view class="text-sm tag" :class="{'active-tag': curTag == 1}" @click="changeTag(1)">关注品牌</view> :class="{'active-tag': queryForm.orderBy == 'create_time'}"
</template> @click="changeOrder('create_time')"
<template> >最新发布</view>
<view class="text-sm tag" :class="{'active-tag': queryForm.orderBy == 'popularity'}" @click="changeOrder('popularity')">人气排名</view> <view
<view class="text-sm tag" :class="{'active-tag': queryForm.orderBy == 'create_time'}" @click="changeOrder('create_time')">最新发布</view> class="tab-item"
</template> :class="{'active-tag': queryForm.orderBy == 'popularity'}"
@click="changeOrder('popularity')"
>人气排名</view>
<view class="brand-filter" :class="{ active: isFilterActive }" @click="showBrandFilter">
<text>筛选品牌</text>
<image :src="'/static/icons/filter.svg'" mode="aspectFit" class="filter-icon"></image>
</view> </view>
</view> </view>
<view class="flex-1 padding list-container"> </view>
<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="changePage">
<!-- 列表内容区域 -->
<view class="list-container">
<scroll-view
style="height: 100%;"
scroll-y="true"
@scrolltolower="changePage"
refresher-enabled="true"
:refresher-triggered="isRefreshing"
@refresherrefresh="onRefresh"
>
<view class="activity-item flex" v-for="(it, index) in activeList" :key="index" @click="toDetail(it)"> <view class="activity-item flex" v-for="(it, index) in activeList" :key="index" @click="toDetail(it)">
<view class="left flex flex-col justify-between align-center"> <view class="left flex flex-col justify-between align-center">
<image :src="it.brandLogo" style="width: 140rpx;height: 140rpx;"> <image :src="it.brandLogo" style="width: 140rpx;height: 140rpx;"></image>
</image> <text>活动状态</text>
<text >活动状态</text>
<view v-if="it.stage == 0">未开始</view> <view v-if="it.stage == 0">未开始</view>
<view v-if="it.stage == 2">已结束</view> <view v-if="it.stage == 2">已结束</view>
<view v-if="it.stage == 3">已结束</view> <view v-if="it.stage == 3">已结束</view>
@ -31,7 +46,6 @@
</view> </view>
<view class="right"> <view class="right">
<view class="title">{{ it.breweryName }}</view> <view class="title">{{ it.breweryName }}</view>
<!-- <view class="title">{{ it.activityName }}</view> -->
<view class="sub">时间首次扫码开始累计 <text style="color:#DE3C4B">{{it.duration}}天内</text></view> <view class="sub">时间首次扫码开始累计 <text style="color:#DE3C4B">{{it.duration}}天内</text></view>
<view class="sub">目标全系列酒款累积扫码 {{ it.activityTarget}}</view> <view class="sub">目标全系列酒款累积扫码 {{ it.activityTarget}}</view>
<scroll-view v-if="it.beers" scroll-x="true" class="scroll-img"> <scroll-view v-if="it.beers" scroll-x="true" class="scroll-img">
@ -51,12 +65,12 @@
</view> </view>
<loginPopup ref="loginRef"></loginPopup> <loginPopup ref="loginRef"></loginPopup>
</view> </view>
</view>
</template> </template>
<script> <script>
import { import {
getActivities, getActivities
getFavoriteActivities
} from '@/api/bar.js' } from '@/api/bar.js'
import loginPopup from '@/components/loginPopup.vue'; import loginPopup from '@/components/loginPopup.vue';
export default { export default {
@ -65,63 +79,41 @@
}, },
data() { data() {
return { return {
statusBaeHeight: 40,
curTag: 0,
activeList: [], // activeList: [], //
loading: false, loading: false,
isRefreshing: false, //
queryForm: { queryForm: {
pageNum: 1, pageNum: 1,
pageSize: 5, pageSize: 5,
orderBy:'' orderBy: 'create_time' //
}, },
total: 0, total: 0,
isFilterActive: false //
}; };
}, },
onLoad() { onLoad() {
uni.setTabBarStyle({ //
backgroundColor: '#ffffff'
})
this.statusBaeHeight = uni.getWindowInfo.statusBarHeight
this.getActivitiesFun() this.getActivitiesFun()
}, },
methods: { methods: {
changeTag(key) {
this.curTag = key
if(key == 0) {
this.queryForm.pageNum = 1
this.activeList = []
this.getActivitiesFun()
}else if(key == 1) {
this.activeList = []
this.queryForm.pageNum = 1
this.getFavoriteActivitiesFun()
}
},
// //
changeOrder(key) { changeOrder(key) {
this.queryForm.orderBy = key if (this.queryForm.orderBy === key) return;
if(this.curTag == 0) { this.queryForm.orderBy = key;
this.queryForm.pageNum = 1 this.queryForm.pageNum = 1;
this.activeList = [] this.activeList = [];
this.getActivitiesFun() this.getActivitiesFun();
} else if(this.curTag == 1) {
this.activeList = []
this.queryForm.pageNum = 1
this.getFavoriteActivitiesFun()
}
}, },
//
changePage() { changePage() {
if (this.activeList.length < this.total) { if (this.activeList.length < this.total) {
if (this.curTag == 1) { this.queryForm.pageNum++;
this.queryForm.pageNum++ this.getActivitiesFun();
this.getFavoriteActivitiesFun()
}else {
this.queryForm.pageNum++
this.getActivitiesFun()
}
} }
}, },
//
toDetail(item) { toDetail(item) {
if (!uni.getStorageSync('token')) { if (!uni.getStorageSync('token')) {
this.$refs.loginRef.open() this.$refs.loginRef.open()
@ -131,44 +123,31 @@
url: "/pagesActivity/activityDetail?id=" + item.id url: "/pagesActivity/activityDetail?id=" + item.id
}) })
}, },
//
getFavoriteActivitiesFun() {
this.loading = true
getFavoriteActivities(this.queryForm).then(res=>{
this.total = res.total
if(res.rows && res.rows.length > 0) {
let arr = res.rows.map(it => {
it.remainingDays = this.getRemainingDays(it.endDate)
return it
})
arr.forEach(it => {
this.activeList.push(it)
})
}
this.loading = false
}).catch(err => {
this.loading = false
})
},
// //
getActivitiesFun() { getActivitiesFun() {
this.loading = true this.loading = true;
getActivities(this.queryForm).then(res => { getActivities(this.queryForm).then(res => {
this.total = res.total this.total = res.total;
if(res.rows && res.rows.length > 0) { if(res.rows && res.rows.length > 0) {
let arr = res.rows.map(it => { let arr = res.rows.map(it => {
it.remainingDays = this.getRemainingDays(it.endDate) it.remainingDays = this.getRemainingDays(it.endDate);
return it return it;
}) });
arr.forEach(it => { //
this.activeList.push(it) if (this.queryForm.pageNum === 1) {
}) this.activeList = arr;
} else {
//
this.activeList = [...this.activeList, ...arr];
} }
this.loading = false }
this.loading = false;
}).catch(err => { }).catch(err => {
this.loading = false this.loading = false;
}) });
}, },
// //
getRemainingDays(date) { getRemainingDays(date) {
const targetDate = new Date(date); const targetDate = new Date(date);
@ -177,50 +156,126 @@
const remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); const remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
return remainingDays; return remainingDays;
}, },
//
showBrandFilter() {
this.isFilterActive = !this.isFilterActive;
//
},
//
onRefresh() {
this.isRefreshing = true;
//
this.queryForm.pageNum = 1;
this.activeList = [];
//
getActivities(this.queryForm).then(res => {
this.total = res.total;
if(res.rows && res.rows.length > 0) {
let arr = res.rows.map(it => {
it.remainingDays = this.getRemainingDays(it.endDate);
return it;
});
this.activeList = arr;
}
this.isRefreshing = false;
}).catch(err => {
this.isRefreshing = false;
});
}
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.page-content { .page {
height: 100vh; min-height: 100vh;
background: #F9F9F9;
.activeTab {
font-size: 64rpx;
border-bottom: 2px solid #303048;
} }
.tag { .filter-tabs {
background-color: transparent; position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 99;
background: #FFFFFF;
// border-bottom: 1rpx solid #F5F5F5
.tabs-content {
display: flex;
align-items: center;
padding: 20rpx 32rpx;
height: 112rpx;
width: 100%;
.tab-item {
width: 144rpx;
height: 64rpx;
line-height: 64rpx;
border-radius: 12rpx; border-radius: 12rpx;
padding: 12rpx 30rpx; background: #F9F9F9;
border: 1px solid #fff; margin-right: 16rpx;
margin-right: 24rpx; font-size: 24rpx;
font-weight: 500;
text-align: center;
&.active-tag {
//
color: #FFF;
background: #D42E78;
}
} }
.active-tag { .brand-filter {
background-color: #FEE034; margin-left: auto;
font-weight: bold; display: flex;
border: 1px solid #FEE034; align-items: center;
justify-content: center;
height: 64rpx;
min-width: 144rpx; //
padding: 0 24rpx; //
border-radius: 12rpx;
background: #FFFFFF;
border: 1rpx solid #D42E78;
transition: all 0.3s; //
text {
color: #D42E78;
font-size: 24rpx;
font-weight: 500;
margin-right: 8rpx; //
}
.filter-icon {
width: 32rpx;
height: 32rpx;
}
//
&.active {
background: #D42E78;
border-color: #D42E78;
text {
color: #FFFFFF;
}
.filter-icon {
filter: brightness(0) invert(1); //
}
}
}
}
} }
.list-container { .list-container {
margin-top: -300rpx; margin-top: 104rpx; //
overflow-y: auto; padding: 24rpx 32rpx;
// padding-bottom: calc(110rpx + constant(safe-area-inset-bottom));
// padding-bottom: calc(110rpx + env(safe-area-inset-bottom));
.card {
border-radius: 40rpx;
} }
.avatar {
width: 160rpx;
height: 160rpx;
border-radius: 8rpx;
}
//
.activity-item { .activity-item {
border-radius: 20rpx; border-radius: 20rpx;
background: #FDFDFD; background: #FDFDFD;
@ -302,6 +357,4 @@
} }
} }
} }
}
}
</style> </style>