| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <template>
- <view class="activity-detail-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>
- </view>
- <!-- 活动封面 -->
- <view class="activity-cover">
- <image :src="activity.coverImage || activity.cover_image" class="cover-image" mode="aspectFill"></image>
- <view class="cover-mask">
- <view class="activity-tag" v-if="activity.isRecommended">⭐ 推荐活动</view>
- </view>
- </view>
- <!-- 活动信息 -->
- <view class="activity-content">
- <view class="activity-title">{{ activity.name }}</view>
- <view class="info-section">
- <view class="info-item">
- <text class="info-icon">⏰</text>
- <text class="info-label">活动时间:</text>
- <text class="info-value">{{ formatActivityTime(activity.startTime || activity.start_time, activity.endTime || activity.end_time) }}</text>
- </view>
- <view class="info-item">
- <text class="info-icon">📍</text>
- <text class="info-label">活动地点:</text>
- <text class="info-value">{{ activity.location || '待定' }}</text>
- </view>
- <view class="info-item">
- <text class="info-icon">👥</text>
- <text class="info-label">报名人数:</text>
- <text class="info-value">{{ activity.participants || 0 }} / {{ activity.capacity || '不限' }}</text>
- </view>
- <view class="info-item">
- <text class="info-icon">💎</text>
- <text class="info-label">所需积分:</text>
- <text class="info-value points">{{ activity.points || 0 }}</text>
- </view>
- </view>
- <view class="divider"></view>
- <view class="description-section">
- <view class="section-title">活动介绍</view>
- <view class="description-text">{{ activity.description || '暂无介绍' }}</view>
- </view>
- <view class="divider"></view>
- <view class="content-section" v-if="activity.content">
- <view class="section-title">活动详情</view>
- <view class="content-text">{{ activity.content }}</view>
- </view>
- </view>
- <!-- 底部兑换按钮 -->
- <view class="bottom-bar" v-if="!hasExchanged">
- <view class="points-info">
- <text class="points-label">所需积分</text>
- <view class="points-value">
- <text class="points-symbol">💎</text>
- <text class="points-num">{{ activity.points || 0 }}</text>
- </view>
- </view>
- <view class="exchange-btn"
- :class="{ 'btn-disabled': currentPoints < (activity.points || 0) }"
- @click="handleExchange">
- <text class="btn-text">{{ currentPoints < (activity.points || 0) ? '积分不足' : '积分兑换报名' }}</text>
- </view>
- </view>
- <!-- 已报名状态 -->
- <view class="bottom-bar" v-else>
- <view class="registered-status">
- <text class="status-icon">✓</text>
- <text class="status-text">已报名</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import api from '../../utils/api.js'
- export default {
- data() {
- return {
- activityId: null,
- activity: {
- name: '加载中...',
- coverImage: 'https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60',
- points: 0
- },
- currentPoints: 0,
- makerId: null,
- hasExchanged: false
- }
- },
- onLoad(options) {
- if (options.id) {
- this.activityId = options.id
- this.initData()
- }
- },
- 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) {
-
- }
- }
-
- await this.loadMakerInfo()
- await this.loadActivityDetail()
- await this.checkExchangeStatus()
- },
- // 加载红娘信息(包括积分)
- async loadMakerInfo() {
- try {
- const res = await api.matchmaker.getDetail(this.makerId)
-
- // 兼容不同的返回格式
- let makerInfo = res
- if (res && res.data) {
- makerInfo = res.data
- }
- if (makerInfo) {
- // 兼容 snake_case 和 camelCase
- this.currentPoints = makerInfo.points ?? makerInfo.total_points ?? 0
-
- }
- } catch (error) {
-
- this.currentPoints = 0
- }
- },
- // 加载活动详情
- async loadActivityDetail() {
- try {
- const data = await api.matchmakerActivity.getDetail(this.activityId)
- if (data) {
- this.activity = data
- }
- } catch (error) {
-
- uni.showToast({
- title: '加载失败',
- icon: 'none'
- })
- }
- },
- // 检查是否已兑换
- async checkExchangeStatus() {
- try {
-
- const res = await api.matchmakerActivity.getPurchasedList(this.makerId)
-
- let list = res
- if (res && res.data) {
- list = res.data
- }
- if (Array.isArray(list) && list.length > 0) {
- this.hasExchanged = list.some(item => {
- const itemActivityId = item.activity_id || item.activityId
-
- return itemActivityId == this.activityId
- })
- }
-
- } catch (error) {
-
- this.hasExchanged = false
- }
- },
- // 格式化活动时间
- formatActivityTime(startTime, endTime) {
- if (!startTime) return '待定'
-
- const start = new Date(startTime)
- const end = endTime ? new Date(endTime) : null
-
- const startStr = start.toLocaleDateString('zh-CN') + ' ' +
- start.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
-
- if (end) {
- // 判断是否同一天
- const isSameDay = start.toDateString() === end.toDateString()
- let endStr
- if (isSameDay) {
- // 同一天只显示时间
- endStr = end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
- } else {
- // 不同天显示完整日期时间
- endStr = end.toLocaleDateString('zh-CN') + ' ' +
- end.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
- }
- return `${startStr} - ${endStr}`
- }
-
- return startStr
- },
- // 处理兑换
- async handleExchange() {
- if (this.currentPoints < (this.activity.points || 0)) {
- uni.showToast({
- title: '积分不足',
- icon: 'none'
- })
- return
- }
- uni.showModal({
- title: '确认兑换',
- content: `是否用 ${this.activity.points} 积分兑换"${this.activity.name}"活动?`,
- confirmText: '确认',
- cancelText: '取消',
- success: (res) => {
- if (res.confirm) {
- this.exchangeActivity()
- }
- }
- })
- },
- // 兑换活动
- async exchangeActivity() {
- try {
- const result = await api.matchmakerActivity.exchange({
- makerId: this.makerId,
- activityId: this.activityId,
- points: this.activity.points
- })
- if (result) {
- uni.showToast({
- title: '兑换成功',
- icon: 'success'
- })
- this.currentPoints -= this.activity.points
- this.hasExchanged = true
-
- // 更新参与人数
- if (this.activity.participants) {
- this.activity.participants++
- } else {
- this.activity.participants = 1
- }
- }
- } catch (error) {
-
- uni.showToast({
- title: error.message || '兑换失败',
- icon: 'none'
- })
- }
- },
- // 返回
- goBack() {
- uni.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .activity-detail-page {
- min-height: 100vh;
- background-color: #FFF9F9;
- padding-top: 90rpx;
- padding-bottom: 120rpx;
- }
- /* 自定义导航栏 */
- .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;
- }
- }
- /* 活动封面 */
- .activity-cover {
- position: relative;
- width: 100%;
- height: 400rpx;
- overflow: hidden;
- .cover-image {
- width: 100%;
- height: 100%;
- background-color: #F5F5F5;
- }
- .cover-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- display: flex;
- align-items: flex-start;
- justify-content: flex-start;
- padding: 20rpx;
- background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, transparent 100%);
- .activity-tag {
- background-color: rgba(255, 215, 0, 0.9);
- color: #333333;
- padding: 8rpx 16rpx;
- border-radius: 20rpx;
- font-size: 24rpx;
- font-weight: bold;
- }
- }
- }
- /* 活动内容 */
- .activity-content {
- padding: 30rpx 20rpx;
- .activity-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 30rpx;
- }
- .info-section {
- background-color: #FFFFFF;
- border-radius: 12rpx;
- padding: 20rpx;
- margin-bottom: 20rpx;
- .info-item {
- display: flex;
- align-items: flex-start;
- margin-bottom: 16rpx;
- &:last-child {
- margin-bottom: 0;
- }
- .info-icon {
- font-size: 28rpx;
- margin-right: 12rpx;
- flex-shrink: 0;
- }
- .info-label {
- font-size: 26rpx;
- color: #666666;
- min-width: 120rpx;
- }
- .info-value {
- font-size: 26rpx;
- color: #333333;
- flex: 1;
- &.points {
- color: #FF6B8A;
- font-weight: bold;
- }
- }
- }
- }
- .divider {
- height: 1rpx;
- background-color: #EEEEEE;
- margin: 20rpx 0;
- }
- .description-section,
- .content-section {
- background-color: #FFFFFF;
- border-radius: 12rpx;
- padding: 20rpx;
- margin-bottom: 20rpx;
- .section-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 16rpx;
- }
- .description-text,
- .content-text {
- font-size: 26rpx;
- color: #666666;
- line-height: 1.6;
- white-space: pre-wrap;
- word-break: break-word;
- }
- }
- }
- /* 底部栏 */
- .bottom-bar {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- height: 120rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 20rpx;
- background-color: #FFFFFF;
- border-top: 1rpx solid #EEEEEE;
- z-index: 100;
- .points-info {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- .points-label {
- font-size: 24rpx;
- color: #999999;
- margin-bottom: 8rpx;
- }
- .points-value {
- display: flex;
- align-items: center;
- gap: 8rpx;
- .points-symbol {
- font-size: 28rpx;
- }
- .points-num {
- font-size: 32rpx;
- color: #FF6B8A;
- font-weight: bold;
- }
- }
- }
- .exchange-btn {
- flex: 1;
- height: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
- color: #FFFFFF;
- border-radius: 40rpx;
- font-size: 28rpx;
- font-weight: bold;
- margin-left: 20rpx;
- transition: all 0.3s ease;
- &:active {
- transform: scale(0.95);
- }
- &.btn-disabled {
- background: #CCCCCC;
- color: #999999;
- }
- .btn-text {
- color: inherit;
- }
- }
- .registered-status {
- flex: 1;
- height: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: #E8F5E9;
- border-radius: 40rpx;
- margin-left: 20rpx;
- .status-icon {
- font-size: 40rpx;
- color: #4CAF50;
- margin-right: 12rpx;
- }
- .status-text {
- font-size: 28rpx;
- color: #4CAF50;
- font-weight: bold;
- }
- }
- }
- </style>
|