| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- <template>
- <view class="activities-page">
- <!-- 自定义导航栏 -->
- <view class="custom-navbar">
- <view class="navbar-left" @click="goBack">
- <text class="back-icon">←</text>
- </view>
- <view class="navbar-title">活动中心</view>
- <view class="navbar-right">
- <view class="points-display">
- <text class="points-label">积分</text>
- <text class="points-value">{{ currentPoints }}</text>
- </view>
- </view>
- </view>
- <!-- 顶部公告 -->
- <view class="announcement-bar">
- <text class="announcement-icon">📢</text>
- <text class="announcement-content">红娘活动报名开始啦!用积分兑换活动名额,积分兑好礼!</text>
- </view>
- <!-- 活动分类标签 - 横向滚动 -->
- <scroll-view scroll-x class="category-scroll" show-scrollbar="false">
- <view class="category-list">
- <view
- v-for="(tab, index) in tabs"
- :key="index"
- class="category-item"
- :class="{ active: activeTab === tab.type }"
- @click="switchTab(tab.type)"
- >
- {{ tab.name }}
- </view>
- </view>
- </scroll-view>
- <!-- 活动列表 -->
- <view class="activity-grid">
- <view class="activity-card" v-for="(item, index) in activityList" :key="index" @click="goToDetail(item)">
- <image :src="item.coverImage || item.cover_image" class="activity-image" mode="aspectFill"></image>
- <view class="activity-info">
- <view class="activity-name">{{ item.name }}</view>
- <view class="activity-meta">
- <text class="activity-location">📍 {{ item.location }}</text>
- </view>
- <view class="activity-footer">
- <view class="activity-points">
- <text class="points-symbol">💎</text>
- <text class="points-value">{{ item.points }}</text>
- </view>
- <text class="activity-participants">{{ item.participants || 0 }}人参加</text>
- </view>
- <view class="activity-btn"
- :class="{ 'btn-disabled': hasExchanged(item.id) }"
- @click.stop="handleActivityAction(item)">
- {{ hasExchanged(item.id) ? '已报名' : '积分兑换' }}
- </view>
- </view>
- </view>
- </view>
- <!-- 空状态 -->
- <view class="empty-state" v-if="activityList.length === 0 && !loading">
- <image src="https://img.icons8.com/color/96/000000/calendar--v1.png" class="empty-icon"></image>
- <text class="empty-text">暂无活动</text>
- <text class="empty-subtext">敬请期待更多精彩活动</text>
- </view>
- <!-- 加载更多 -->
- <view class="load-more" v-if="hasMore && activityList.length > 0">
- <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
- </view>
- <view class="no-more" v-else-if="activityList.length > 0">
- <text class="no-more-text">没有更多了</text>
- </view>
- </view>
- </template>
- <script>
- import api from '../../utils/api.js'
- export default {
- data() {
- return {
- activityList: [],
- pageNum: 1,
- pageSize: 10,
- hasMore: true,
- loading: false,
- currentPoints: 0,
- makerId: null,
- exchangedActivities: [],
- tabs: [
- { name: '全部活动', type: 'all' },
- { name: '推荐活动', type: 'premium' }
- ],
- activeTab: 'all'
- }
- },
- onLoad() {
- this.initData()
- },
- onReachBottom() {
- if (this.hasMore && !this.loading) {
- this.pageNum++
- this.loadActivityList()
- }
- },
- methods: {
- // 初始化数据
- async initData() {
- const userInfo = uni.getStorageSync('userInfo')
- // 兼容多种字段名
- this.makerId = userInfo && (userInfo.matchmakerId || userInfo.makerId || userInfo.matchmaker_id)
-
- // 如果没有makerId,尝试通过userId获取
- if (!this.makerId && userInfo && userInfo.userId) {
- try {
- const res = await api.matchmaker.getByUserId(userInfo.userId)
- let matchmaker = res
- if (res && res.data) {
- matchmaker = res.data
- }
- if (matchmaker) {
- this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
- }
- } catch (e) {
- console.error('获取红娘信息失败:', e)
- }
- }
-
- if (!this.makerId) {
- uni.showToast({
- title: '请先登录红娘账号',
- icon: 'none'
- })
- return
- }
-
- await this.loadMakerInfo()
- await this.loadExchangedActivities()
- await this.loadActivityList()
- },
- // 加载红娘信息(包括积分)
- async loadMakerInfo() {
- try {
- const res = await api.matchmaker.getDetail(this.makerId)
- // 兼容不同的返回格式
- const makerInfo = res && res.data ? res.data : res
- if (makerInfo) {
- this.currentPoints = makerInfo.points || makerInfo.point || 0
- console.log('红娘积分:', this.currentPoints)
- }
- } catch (error) {
- console.error('加载红娘信息失败:', error)
- this.currentPoints = 0
- }
- },
- // 加载已兑换的活动列表
- async loadExchangedActivities() {
- try {
- const list = await api.matchmakerActivity.getPurchasedList(this.makerId)
- if (list && list.length > 0) {
- this.exchangedActivities = list.map(item => item.activity_id || item.activityId)
- }
- } catch (error) {
- console.error('加载已兑换活动失败:', error)
- this.exchangedActivities = []
- }
- },
- // 加载活动列表
- async loadActivityList() {
- if (this.loading) return
- this.loading = true
- try {
- const params = {
- categoryType: this.activeTab
- }
- const data = await api.matchmakerActivity.getList(params)
- if (data && data.length > 0) {
- this.activityList = [...this.activityList, ...data]
- this.hasMore = data.length >= this.pageSize
- } else {
- this.hasMore = false
- }
- } catch (error) {
- console.error('加载活动列表失败:', error)
- this.hasMore = false
- } finally {
- this.loading = false
- }
- },
- // 切换分类标签
- switchTab(type) {
- if (this.activeTab === type) return
- this.activeTab = type
- this.pageNum = 1
- this.activityList = []
- this.loadActivityList()
- },
- // 检查是否已兑换
- hasExchanged(activityId) {
- return this.exchangedActivities.includes(activityId)
- },
- // 处理活动操作(兑换或查看详情)
- async handleActivityAction(item) {
- if (this.hasExchanged(item.id)) {
- // 已兑换,跳转到详情页
- uni.navigateTo({
- url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
- })
- } else {
- // 未兑换,显示兑换确认
- uni.showModal({
- title: '确认兑换',
- content: `是否用 ${item.points} 积分兑换"${item.name}"活动?`,
- confirmText: '确认',
- cancelText: '取消',
- success: (res) => {
- if (res.confirm) {
- this.exchangeActivity(item)
- }
- }
- })
- }
- },
- // 兑换活动
- async exchangeActivity(item) {
- const pointsNeeded = item.points || 0
-
- if (this.currentPoints < pointsNeeded) {
- uni.showToast({
- title: '积分不足',
- icon: 'none'
- })
- return
- }
- try {
- console.log('兑换参数:', {
- makerId: this.makerId,
- activityId: item.id,
- points: pointsNeeded
- })
-
- const result = await api.matchmakerActivity.exchange({
- makerId: this.makerId,
- activityId: item.id,
- points: pointsNeeded
- })
-
- console.log('兑换结果:', result)
- // API请求成功(request函数已处理code=200的情况,能走到这里说明已成功)
- uni.showToast({
- title: '兑换成功',
- icon: 'success'
- })
- this.currentPoints -= pointsNeeded
- this.exchangedActivities.push(item.id)
-
- // 跳转到详情页
- setTimeout(() => {
- uni.navigateTo({
- url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
- })
- }, 500)
- } catch (error) {
- console.error('兑换失败:', error)
- uni.showToast({
- title: error.message || '兑换失败',
- icon: 'none'
- })
- }
- },
- // 跳转到活动详情
- goToDetail(item) {
- uni.navigateTo({
- url: `/pages/matchmaker-workbench/activity-detail?id=${item.id}`
- })
- },
- // 返回
- goBack() {
- uni.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .activities-page {
- min-height: 100vh;
- background-color: #FFF9F9;
- padding-top: 90rpx;
- }
- /* 自定义导航栏 */
- .custom-navbar {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- height: 90rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 20rpx;
- background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
- z-index: 999;
- .navbar-left,
- .navbar-right {
- width: 80rpx;
- }
- .back-icon {
- font-size: 40rpx;
- color: #333333;
- font-weight: bold;
- }
- .navbar-title {
- flex: 1;
- text-align: center;
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- }
- .points-display {
- display: flex;
- align-items: center;
- gap: 8rpx;
- background-color: rgba(255, 255, 255, 0.8);
- padding: 8rpx 16rpx;
- border-radius: 20rpx;
- .points-label {
- font-size: 24rpx;
- color: #666666;
- }
- .points-value {
- font-size: 28rpx;
- color: #FF6B8A;
- font-weight: bold;
- }
- }
- }
- /* 公告栏 */
- .announcement-bar {
- display: flex;
- align-items: center;
- gap: 12rpx;
- padding: 16rpx 20rpx;
- background-color: #FFF3E0;
- margin: 10rpx 0;
- .announcement-icon {
- font-size: 28rpx;
- flex-shrink: 0;
- }
- .announcement-content {
- font-size: 24rpx;
- color: #E65100;
- flex: 1;
- }
- }
- /* 分类标签 - 横向滚动 */
- .category-scroll {
- white-space: nowrap;
- padding: 0 20rpx;
- margin: 10rpx 0;
- }
- .category-list {
- display: flex;
- gap: 12rpx;
- }
- .category-item {
- display: inline-block;
- padding: 12rpx 24rpx;
- background-color: #FFFFFF;
- border-radius: 30rpx;
- font-size: 26rpx;
- color: #666666;
- border: 2rpx solid #EEEEEE;
- transition: all 0.3s ease;
- &.active {
- background-color: #9C27B0;
- color: #FFFFFF;
- border-color: #9C27B0;
- }
- }
- /* 活动列表 - 两列布局 */
- .activity-grid {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: 20rpx;
- padding: 20rpx;
- .activity-card {
- position: relative;
- background-color: #FFFFFF;
- border-radius: 20rpx;
- overflow: hidden;
- box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
- .activity-image {
- width: 100%;
- height: 240rpx;
- background-color: #F5F5F5;
- }
- .activity-info {
- padding: 20rpx;
- .activity-name {
- font-size: 28rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 10rpx;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
- .activity-meta {
- margin-bottom: 15rpx;
- .activity-location {
- font-size: 24rpx;
- color: #666666;
- }
- }
- .activity-footer {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 15rpx;
- .activity-points {
- display: flex;
- align-items: center;
- .points-symbol {
- font-size: 24rpx;
- margin-right: 5rpx;
- }
- .points-value {
- font-size: 26rpx;
- color: #FF6B8A;
- font-weight: bold;
- }
- }
- .activity-participants {
- font-size: 22rpx;
- color: #999999;
- }
- }
- .activity-btn {
- width: 100%;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: #9C27B0;
- color: #FFFFFF;
- border-radius: 30rpx;
- font-size: 26rpx;
- transition: all 0.3s ease;
- &:active {
- background-color: #7B1FA2;
- }
- &.btn-disabled {
- background-color: #CCCCCC;
- color: #999999;
- }
- }
- }
- }
- }
- /* 空状态 */
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 100rpx 0;
- .empty-icon {
- width: 120rpx;
- height: 120rpx;
- opacity: 0.5;
- margin-bottom: 20rpx;
- }
- .empty-text {
- font-size: 32rpx;
- color: #666666;
- margin-bottom: 10rpx;
- }
- .empty-subtext {
- font-size: 26rpx;
- color: #999999;
- }
- }
- /* 加载更多 */
- .load-more,
- .no-more {
- padding: 30rpx 0;
- text-align: center;
- .load-text,
- .no-more-text {
- font-size: 24rpx;
- color: #999999;
- }
- }
- </style>
|