Files
hmc_gbhd/frontend/src/pages/activity/detail/index.vue
T
2025-09-28 13:52:01 +08:00

570 lines
13 KiB
Vue

<template>
<view class="page-container">
<template v-if="detailData">
<view style="flex: 1;overflow-y: auto">
<!-- 活动图片 -->
<view class="event-header">
<t-image :src=config.fileDomain+detailData.cover shape="round"
class="event-cover" fit="fill"/>
</view>
<!-- 活动标题与标签 -->
<view class="event-title-section">
<view class="event-title">{{ detailData.title }}</view>
</view>
<!-- 活动基本信息 -->
<view class="event-info-section">
<!-- 报名时间 -->
<view class="info-item">
<t-icon name="calendar" size="20px"/>
<view class="info-text-container">
<text class="info-text-title">报名时间</text>
<text class="info-text">{{ formatDate(detailData.signStartTime) }} 至
{{ formatDate(detailData.signEndTime) }}
</text>
</view>
</view>
<!-- 活动时间 -->
<view class="info-item">
<t-icon name="alarm" size="20px"/>
<view class="info-text-container">
<text class="info-text-title">活动时间</text>
<text class="info-text">{{ formatDate(detailData.startTime) }} 至 {{
formatDate(detailData.endTime)
}}
</text>
</view>
</view>
<!-- 活动地点 -->
<view class="info-item">
<t-icon name="location" size="20px"/>
<view class="info-text-container">
<text class="info-text-title">活动地点</text>
<text class="info-text">{{ detailData.address }}</text>
</view>
</view>
</view>
<!-- 活动详情区域 -->
<view class="activity-detail-section">
<view class="section-title">活动详情</view>
<rich-text class="rich-content" :nodes="detailData.content"></rich-text>
</view>
<!-- 比赛项目 -->
<view class="activity-detail-section" v-if="detailData.items && detailData.items.length > 0">
<view class="section-title">比赛项目</view>
<scroll-view scroll-x class="event-items-scroll" show-scrollbar="false">
<view class="event-items-horizontal">
<view v-for="(item, index) in detailData.items" :key="index" class="event-item-card">
<view class="event-item-header">
<view class="event-item-index">{{ index + 1 }}</view>
<text class="event-item-name">{{ item.name }}</text>
</view>
<view class="event-item-content">
<!-- 项目图片区域 -->
<t-image :src=config.fileDomain+item.img shape="round"
class="event-item-image" fit="fill"/>
<!-- 项目信息区域 -->
<view class="event-item-info">
<view class="event-item-section">
<view class="event-item-section-title">
<t-icon name="flag" size="16px" color="var(--td-brand-color-5)"/>
<text>比赛方法</text>
</view>
<view class="event-item-section-content">{{ item.form }}</view>
</view>
<view class="event-item-section">
<view class="event-item-section-title">
<t-icon name="chart-bar" size="16px" color="var(--td-brand-color-5)"/>
<text>评分标准</text>
</view>
<view class="event-item-section-content">{{ item.rule }}</view>
</view>
<view class="event-item-section">
<view class="event-item-section-title">
<t-icon name="help-circle" size="16px" color="var(--td-brand-color-5)"/>
<text>比赛规则</text>
</view>
<view class="event-item-section-content">{{ item.ruleForm }}</view>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
</view>
<!-- 底部操作栏 -->
<view class="footer-bar">
<!-- <t-button theme="primary" block @click="navigateToSignUp">立即报名</t-button>-->
<t-button theme="primary" block :disabled="bottomButton.disabled" @click="bottomButton.onClick">
{{ bottomButton.text }}
</t-button>
</view>
</template>
<!-- 加载中状态 -->
<template v-else>
<view class="loading-container">
<t-loading theme="dots" size="40rpx"/>
<text>加载中...</text>
</view>
</template>
</view>
</template>
<script setup>
import {ref, onMounted, computed} from 'vue';
import {onLoad} from '@dcloudio/uni-app';
import {Toast} from 'tdesign-mobile-vue';
import {useRequest} from "@/utils/request";
import {config} from "@/utils/config";
import moment from "moment";
const request = useRequest();
const actId = ref(null);
const isSignUp = ref(null);
const detailData = ref(null);
// 格式化日期
const formatDate = (dateStr) => {
if (!dateStr) return '';
return moment(dateStr).format('YYYY.MM.DD HH:mm');
// try {
// // 手动解析日期部分
// const [datePart, timePart] = dateStr.split(' ');
// const [year, month, day] = datePart.split('-').map(Number);
// const [hours, minutes, seconds] = timePart.split(':').map(Number);
//
// // 创建日期对象(月份需要减1)
// const date = new Date(year, month - 1, day, hours, minutes, seconds);
//
// // 检查日期是否有效
// if (isNaN(date.getTime())) {
// return dateStr;
// }
//
// return `${date.getFullYear()}.${(date.getMonth() + 1).toString().padStart(2, '0')}.${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
// } catch (error) {
// return dateStr;
// }
};
// 底部按钮文字
const bottomButton = computed(() => {
const {signStartTime, signEndTime} = detailData.value
if (signStartTime && signEndTime) {
// const now = new Date();
// const startTime = new Date(signStartTime);
// const endTime = new Date(signEndTime);
const now = moment();
const startTime = moment(signStartTime);
const endTime = moment(signEndTime);
if (now.isBetween(startTime, endTime, null, '[]')) {
return {
text: isSignUp.value ? '修改报名信息' : '立即报名',
disabled: false,
onClick: navigateToSignUp
}
} else if (now.isBefore(startTime)) {
return {
text: `报名开始时间:${formatDate(signStartTime)}`,
disabled: true,
onClick: () => {
}
}
} else {
return {
text: `报名结束时间:${formatDate(signEndTime)}`,
disabled: true,
onClick: () => {
}
}
}
}
})
// 跳转到报名页面
const navigateToSignUp = () => {
if (!actId.value) return;
uni.navigateTo({
url: `/pages/activity/registration-form/index?id=${actId.value}`
});
};
// 获取活动详情
const getActivityDetail = async (id) => {
try {
const {code, data} = await request.get(`/client/activity/get/${id}`);
if (code === 0 && data) {
detailData.value = data;
} else {
// Toast({message: '获取活动详情失败', theme: 'error'});
}
} catch (error) {
console.error('获取活动详情错误', error);
// Toast({message: '获取活动详情失败', theme: 'error'});
}
};
// 判断是否报名
async function getIsSignUp() {
try {
const {code, data} = await request.get('/client/activity/is-sign-up/' + actId.value)
if (code === 0) {
isSignUp.value = data
} else {
Toast({message: '判断是否报名失败', theme: 'error'});
}
} catch (e) {
console.error(e)
}
}
// 页面加载
onLoad((option) => {
if (option.id) {
actId.value = option.id;
getActivityDetail(option.id);
getIsSignUp();
} else {
Toast({message: '未找到活动ID', theme: 'error'});
}
});
</script>
<style scoped lang="less">
/* 活动图片区域 */
.event-header {
position: relative;
width: 100%;
height: 420rpx;
}
.event-cover {
width: 100%;
height: 100%;
object-fit: cover;
}
.bottom-placeholder {
width: 100%;
height: 120rpx;
}
.event-title-section {
padding: 24rpx;
background-color: #ffffff;
}
.event-title {
font-size: 36rpx;
font-weight: bold;
line-height: 1.4;
color: #333333;
margin-bottom: 16rpx;
}
.event-tag {
display: inline-flex;
align-items: center;
background-color: rgba(var(--td-brand-color-5), 0.1);
color: var(--td-brand-color-5);
font-size: 24rpx;
padding: 6rpx 12rpx;
border-radius: 6rpx;
.t-icon {
margin-right: 4rpx;
}
}
/* 活动信息区域 */
.event-info-section {
margin-top: 16rpx;
background-color: #ffffff;
padding: 0 24rpx;
}
.info-item {
display: flex;
padding: 24rpx 0;
border-bottom: 1px solid #f0f0f0;
.t-icon {
color: var(--td-brand-color-5);
margin-right: 16rpx;
flex-shrink: 0;
margin-top: 4rpx;
}
}
.info-text-container {
display: flex;
flex-direction: column;
flex: 1;
}
.info-text-title {
font-size: 24rpx;
color: #999999;
margin-bottom: 6rpx;
}
.info-text {
font-size: 28rpx;
color: #333333;
line-height: 1.4;
}
/* 活动详情区域 */
.activity-detail-section {
margin-top: 16rpx;
background-color: #ffffff;
padding: 24rpx;
margin-bottom: 16rpx;
}
.section-title {
font-size: 32rpx;
font-weight: 500;
color: #333333;
margin-bottom: 24rpx;
position: relative;
padding-left: 24rpx;
&::before {
content: '';
position: absolute;
left: 0;
top: 8rpx;
width: 8rpx;
height: 32rpx;
background-color: var(--td-brand-color-5);
border-radius: 4rpx;
}
}
.rich-content {
font-size: 28rpx;
line-height: 1.6;
color: #333333;
}
/* 比赛项目 */
.event-items-scroll {
width: 100%;
white-space: nowrap;
}
.event-items-horizontal {
display: inline-flex;
padding: 0 12rpx;
}
.event-item-card {
display: inline-block;
width: 600rpx;
min-width: 600rpx;
max-width: 80vw;
background-color: #ffffff;
border-radius: 12rpx;
overflow: hidden;
border: 1px solid #f0f0f0;
margin-right: 24rpx;
flex-shrink: 0;
white-space: normal;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.event-item-card:last-child {
margin-right: 12rpx;
}
.event-item {
background-color: #ffffff;
border-radius: 12rpx;
overflow: hidden;
//box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
border: 1px solid #f0f0f0;
height: auto;
max-height: none;
margin-bottom: 24rpx;
}
.event-item:last-child {
margin-bottom: 0;
}
.event-item-header {
display: flex;
align-items: center;
padding: 20rpx 24rpx;
background-color: #f9f9f9;
border-left: 8rpx solid var(--td-brand-color-5);
position: relative;
}
.event-item-index {
background-color: var(--td-brand-color-5);
color: #ffffff;
width: 40rpx;
height: 40rpx;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24rpx;
font-weight: bold;
margin-right: 16rpx;
position: relative;
z-index: 1;
}
.event-item-name {
color: #333333;
font-size: 30rpx;
font-weight: 500;
flex: 1;
margin-right: 8rpx;
position: relative;
z-index: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.event-item-content {
padding: 0;
}
.event-item-image {
width: 100%;
height: 240rpx;
display: block;
}
.event-item-info {
padding: 24rpx;
max-height: 600rpx;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.event-item-section {
margin-bottom: 24rpx;
&:last-child {
margin-bottom: 0;
}
}
.event-item-section-title {
display: flex;
align-items: center;
margin-bottom: 12rpx;
.t-icon {
margin-right: 8rpx;
}
text {
font-size: 28rpx;
font-weight: 500;
color: #333333;
}
}
.event-item-section-content {
font-size: 28rpx;
color: #666666;
line-height: 1.5;
word-break: break-all;
padding-left: 32rpx;
}
/* 底部按钮区域 */
.footer-bar {
//position: fixed;
//bottom: 0;
//left: 0;
//right: 0;
flex-shrink: 0;
background-color: #ffffff;
padding: 24rpx;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
z-index: 100;
}
/* 加载状态 */
.loading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 80vh;
text {
margin-top: 24rpx;
color: #999999;
font-size: 28rpx;
}
}
/* 内容折叠样式 */
.content-collapsed {
max-height: 200rpx;
overflow: hidden;
position: relative;
&::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 60rpx;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
}
.expand-button {
margin-top: 12rpx;
text-align: center;
color: var(--td-brand-color-5);
font-size: 26rpx;
padding: 8rpx 0;
}
.scrollable-content {
max-height: 300rpx;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding-right: 10rpx;
}
::v-deep .t-swiper {
height: auto !important;
min-height: 500px;
}
::v-deep .t-swiper-item {
height: auto !important;
overflow-y: auto;
}
</style>