fix: 修复活动列表点击事件处理方法名称不一致的问题

This commit is contained in:
davy 2025-04-05 20:57:13 +08:00
parent 69ffc1fd00
commit b70b87cdb6
2 changed files with 177 additions and 84 deletions

View File

@ -1,28 +1,29 @@
<template>
<view class="activity-item flex" @click="handleClick">
<view class="left flex flex-col justify-between align-center">
<image :src="item.brandLogo" style="width: 140rpx;height: 140rpx;border-radius: 6rpx;"></image>
<text style="color: #606060;font-size: 24rpx;font-weight: bold;white-space: nowrap;">
<block v-if="activityState === 'recruiting'">活动招募还剩</block>
<block v-else-if="activityState === 'inProgress'">距离达成还剩</block>
</text>
<view class="status-box">
<block v-if="activityState === 'recruiting'">
<view class="days-left">
<text style="font-size: 72rpx; color: #DE3C4B;">{{item.remainingDays}}</text>
<text style="font-size: 24rpx;color: #606060;"></text>
</view>
</block>
<block v-else-if="activityState === 'inProgress'">
<view v-if="item.remainingBeerCount > 0">
<text style="font-size: 24rpx;color: #0B0E26;">{{item.remainingBeerCount}}</text>
<text style="font-size: 24rpx;color: #0B0E26;"></text>
</view>
</block>
<block v-else-if="activityState === 'completed'">
<view v-if="!item.barAwardStatus" style="font-size: 24rpx;color: #19367A;font-weight: bold;">待兑付</view>
<view v-else style="font-size: 24rpx;color: #19367A;font-weight: bold;">已完成</view>
</block>
<view class="activity-item flex" v-if="isActivityVisible" @click="handleClick">
<view class="left">
<image :src="item.brandLogo"></image>
<view class="status-content">
<text v-if="activityState === 'recruiting'">招募剩余天数</text>
<text v-else-if="activityState === 'inProgress'">距离达成还剩</text>
<view class="status-box">
<template v-if="activityState === 'recruiting'">
<view class="days-left">
<text class="days-num">{{item.remainingDays}}</text>
<text class="days-unit"></text>
</view>
</template>
<template v-else-if="activityState === 'inProgress'">
<view v-if="item.remainingBeerCount > 0" class="beer-count">
<text>{{item.remainingBeerCount}}</text>
<text></text>
</view>
</template>
<template v-else-if="activityState === 'completed'">
<view class="status-text">
{{!item.barAwardStatus ? '待兑付' : '已完成'}}
</view>
</template>
</view>
</view>
</view>
<view class="right">
@ -53,7 +54,24 @@ export default {
required: true
}
},
created() {
console.log('ActivityItem created', this.item)
},
mounted() {
console.log('ActivityItem mounted', this.item)
},
computed: {
//
isActivityVisible() {
//
const userCity = uni.getStorageSync('userCity');
//
if (!userCity) {
return this.item.city === '全国';
}
//
return this.item.city === '全国' || this.item.city === userCity;
},
activityState() {
if (this.item.activityStatus === 1) {
return 'recruiting';
@ -67,9 +85,11 @@ export default {
},
methods: {
handleClick() {
console.log('ActivityItem clicked', this.item)
this.$emit('click', this.item)
},
handleReview(beer) {
console.log('ActivityItem review clicked', beer)
this.$emit('review', beer)
}
}
@ -155,7 +175,7 @@ export default {
top: -12rpx;
height: calc(100% + 24rpx);
width: 180rpx;
padding: 24rpx 16rpx;
padding: 40rpx 24rpx;
background: #FFFFFF;
border-radius: 20rpx;
box-sizing: border-box;
@ -165,49 +185,66 @@ export default {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
.brand-logo {
width: 148rpx;
height: 148rpx;
border-radius: 12rpx;
margin-bottom: 16rpx;
image {
width: 132rpx;
height: 132rpx;
border-radius: 6rpx;
margin-bottom: 40rpx;
}
.brewery-name {
font-size: 24rpx;
font-weight: bold;
color: #0B0E26;
text-align: center;
margin-bottom: 8rpx;
}
.status-content {
display: flex;
flex-direction: column;
align-items: center;
text {
color: #606060;
font-size: 24rpx;
font-weight: bold;
white-space: nowrap;
margin-bottom: 46rpx;
}
.city {
font-size: 20rpx;
color: #9D9D9D;
text-align: center;
margin-bottom: 16rpx;
}
.status-text {
font-size: 20rpx;
color: #0B0E26;
text-align: center;
margin-bottom: 8rpx;
}
.remaining-days {
font-size: 40rpx;
font-weight: bold;
color: #D42E78;
text-align: center;
margin-bottom: 8rpx;
}
.days-unit {
font-size: 20rpx;
color: #D42E78;
text-align: center;
.status-box {
text-align: center;
.days-left {
display: flex;
align-items: baseline;
justify-content: center;
.days-num {
font-size: 72rpx;
color: #D42E78;
font-weight: bold;
line-height: 1;
}
.days-unit {
font-size: 24rpx;
color: #606060;
margin-left: 4rpx;
}
}
.beer-count {
text {
font-size: 24rpx;
color: #0B0E26;
&:last-child {
margin-left: 4rpx;
}
}
}
.status-text {
font-size: 24rpx;
color: #19367A;
font-weight: bold;
}
}
}
}
}

View File

@ -67,15 +67,13 @@
scroll-y="true"
@scrolltolower="changePage"
:scroll-anchoring="true"
:refresher-enabled="true"
@refresherrefresh="onRefresh"
>
<view class="activity-list" style="margin-top: 16rpx;">
<activity-item
v-for="(item, index) in featurePageList"
:key="index"
:item="item"
@click="toDetail"
@click="handleActivityClick"
@review="toReview"
/>
</view>
@ -147,6 +145,27 @@
finished: false,
};
},
created() {
console.log('Index page created')
},
mounted() {
console.log('Index page mounted')
},
onReady() {
console.log('Index page ready')
//
if (this.featurePageList.length === 0) {
this.getActivityList()
}
},
watch: {
featurePageList: {
handler(newVal) {
console.log('featurePageList changed', newVal)
},
deep: true
}
},
onLoad() {
// setTimeout(() => {
// uni.setNavigationBarColor({
@ -163,7 +182,8 @@
uni.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
//
uni.stopPullDownRefresh()
},
onShow() {
this.userInfo = uni.getStorageSync('userInfo')
@ -181,7 +201,10 @@
// onPullDownRefresh(){
// this.getFeaturePageListFun() //
// },
onPullDownRefresh() {
//
uni.stopPullDownRefresh()
},
methods: {
loginSuccess() {
this.userInfo = uni.getStorageSync('userInfo')
@ -313,14 +336,6 @@
//
console.log('搜索关键词:', this.keyword);
},
//
async onRefresh() {
this.pageNum = 1
this.finished = false
this.featurePageList = []
await this.getActivityList()
uni.stopPullDownRefresh()
},
//
async getActivityList() {
if (this.loading || this.finished) return
@ -332,14 +347,48 @@
})
if (res.code === 200) {
const { rows, total } = res
//
const processedRows = rows.map(it => {
//
const targetDate = new Date(it.endDate);
const currentDate = new Date();
const timeDiff = targetDate.getTime() - currentDate.getTime();
const remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
//
let activityState = 'recruiting';
if (it.activityStatus === 2) {
activityState = 'in_progress';
} else if (it.activityStatus === 3) {
activityState = 'completed';
}
return {
...it,
remainingDays,
activityState,
remainingBeerCount: it.remainingBeerCount || 0,
barAwardStatus: it.barAwardStatus || 0
};
});
//
const filteredRows = processedRows.filter(item => {
if (item.activityState === 'recruiting') {
return item.remainingDays >= 0
}
return true
});
if (this.pageNum === 1) {
this.featurePageList = rows
this.featurePageList = filteredRows;
} else {
this.featurePageList = [...this.featurePageList, ...rows]
this.featurePageList = [...this.featurePageList, ...filteredRows];
}
this.total = total
this.finished = this.featurePageList.length >= total
this.pageNum++
this.total = total;
this.finished = this.featurePageList.length >= total;
this.pageNum++;
}
} catch (error) {
console.error('获取活动列表失败:', error)
@ -347,13 +396,20 @@
this.loading = false
}
},
//
async changePage() {
if (!this.finished) {
await this.getActivityList()
}
},
//
handleActivityClick(item) {
console.log('handleActivityClick called', item)
uni.navigateTo({
url: "/pagesActivity/activityDetail?id=" + item.id
})
},
}
}
</script>
@ -585,6 +641,6 @@
}
.activity-item {
display: none;
display: block;
}
</style>