| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334 |
- <template>
- <view class="activity-container" :style="{ '--font-scale': fontScale }">
- <!-- Nav bar with title "活动中心" and admin "+" button -->
- <!-- Tab bar(管理 tab 仅对有活动管理权限的账号可见:活动管理员 / 已通过审核的活动提供商) -->
- <view class="tab-bar">
- <view
- class="tab-item"
- :class="{ active: currentTab === tab.key }"
- v-for="tab in visibleTabs"
- :key="tab.key"
- @click="onTabChange(tab.key)"
- >
- <text class="tab-label">{{ tab.label }}</text>
- </view>
- </view>
- <!-- ScrollView content area -->
- <scroll-view
- class="content-scroll"
- scroll-y
- :refresher-enabled="true"
- :refresher-triggered="isRefreshing"
- @refresherrefresh="onRefresh"
- @scrolltolower="onLoadMore"
- >
- <!-- Tab 1: mine -->
- <view v-if="currentTab === 'mine'">
- <!-- Filter chips -->
- <scroll-view class="filter-scroll" scroll-x enable-flex>
- <view class="filter-chips">
- <view
- class="filter-chip"
- :class="{ active: currentMineFilter === filter.value }"
- v-for="filter in mineFilters"
- :key="filter.value"
- @click="onMineFilterChange(filter.value)"
- >
- <text class="filter-label">{{ filter.label }}</text>
- </view>
- </view>
- </scroll-view>
- <!-- Activity cards -->
- <view class="card-list" v-if="myActivities.length > 0">
- <view
- class="activity-card"
- v-for="act in myActivities"
- :key="act.id"
- @click="goDetail(act)"
- >
- <image
- class="card-cover"
- :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
- mode="aspectFill"
- lazy-load />
- <view class="card-info">
- <text class="card-title">{{ act.title }}</text>
- <view class="card-tags" v-if="tagList(act.tags).length">
- <text class="tag-chip" v-for="(t, ti) in tagList(act.tags)" :key="ti">{{ t }}</text>
- </view>
- <text class="card-meta" v-if="act.registrantName">报名人:{{ act.registrantName }}</text>
- <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
- <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
- <view class="card-bottom">
- <text class="card-status" :class="'status-' + (act._cls || 'upcoming')">
- {{ act._txt || '待开始' }}
- </text>
- <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
- <text class="card-price free" v-else>免费</text>
- </view>
- <!-- Action buttons for approved status -->
- <view
- v-if="act.status === 'approved'"
- class="card-actions"
- >
- <button class="btn-cancel" @click.stop="onCancel(act)">取消报名</button>
- <button class="btn-checkin" @click.stop="onCheckin(act)">签到</button>
- </view>
- </view>
- </view>
- </view>
- <!-- Empty state for mine -->
- <view class="empty-state" v-else-if="!mineLoading">
- <text class="empty-icon">📋</text>
- <text class="empty-title">暂无报名的活动</text>
- <text class="empty-desc">去发现页探索精彩活动吧</text>
- <button class="empty-btn" @click="switchToDiscover">去发现活动</button>
- </view>
- <!-- Loading state -->
- <view class="loading-state" v-if="mineLoading">
- <view class="loading-spinner"></view>
- <text class="loading-text">加载中...</text>
- </view>
- <!-- Load more tip -->
- <view class="load-more-tip" v-if="myActivities.length > 0 && !hasMore && currentTab === 'mine'">
- <text class="load-more-text">没有更多了</text>
- </view>
- </view>
- <!-- Tab 2: discover -->
- <view v-if="currentTab === 'discover'">
- <!-- Filter chips (dimension) -->
- <scroll-view class="filter-scroll" scroll-x enable-flex>
- <view class="filter-chips">
- <view
- class="filter-chip"
- :class="{ active: currentDimension === filter.value }"
- v-for="filter in dimensionFilters"
- :key="filter.value"
- @click="onDimensionChange(filter.value)"
- >
- <text class="filter-label">{{ filter.label }}</text>
- </view>
- </view>
- </scroll-view>
- <!-- Activity cards -->
- <view class="card-list" v-if="discoverActivities.length > 0">
- <view
- class="activity-card"
- v-for="act in discoverActivities"
- :key="act.id"
- @click="goDetail(act)"
- >
- <image
- class="card-cover"
- :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
- mode="aspectFill"
- lazy-load />
- <view class="card-info">
- <text class="card-title">{{ act.title }}</text>
- <view class="card-tags" v-if="tagList(act.tags).length">
- <text class="tag-chip" v-for="(t, ti) in tagList(act.tags)" :key="ti">{{ t }}</text>
- </view>
- <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
- <text class="card-desc" v-if="act.intro || act.description">{{ act.intro || act.description }}</text>
- <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
- <view class="card-bottom">
- <text class="card-status" :class="'status-' + (act.displayStatus || 'open')">
- {{ act.displayLabel || '报名中' }}
- </text>
- <text class="card-price" v-if="hasFee(act)">¥{{ minFee(act) }}</text>
- <text class="card-price free" v-else>免费</text>
- </view>
- </view>
- </view>
- </view>
- <!-- Empty state for discover -->
- <view class="empty-state" v-else-if="!discoverLoading">
- <text class="empty-icon">🔍</text>
- <text class="empty-title">暂无活动</text>
- <text class="empty-desc">稍后再来看看吧</text>
- </view>
- <!-- Loading state -->
- <view class="loading-state" v-if="discoverLoading">
- <view class="loading-spinner"></view>
- <text class="loading-text">加载中...</text>
- </view>
- <!-- Load more tip -->
- <view class="load-more-tip" v-if="discoverActivities.length > 0 && !hasMore && currentTab === 'discover'">
- <text class="load-more-text">没有更多了</text>
- </view>
- </view>
- <!-- Tab 3: history -->
- <view v-if="currentTab === 'history'">
- <!-- Filter chips (same as mine) -->
- <scroll-view class="filter-scroll" scroll-x enable-flex>
- <view class="filter-chips">
- <view
- class="filter-chip"
- :class="{ active: currentMineFilter === filter.value }"
- v-for="filter in mineFilters"
- :key="filter.value"
- @click="onMineFilterChange(filter.value)"
- >
- <text class="filter-label">{{ filter.label }}</text>
- </view>
- </view>
- </scroll-view>
- <!-- Activity cards -->
- <view class="card-list" v-if="historyActivities.length > 0">
- <view
- class="activity-card"
- v-for="act in historyActivities"
- :key="act.id"
- @click="goDetail(act)"
- >
- <image
- class="card-cover"
- :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
- mode="aspectFill"
- lazy-load />
- <view class="card-info">
- <text class="card-title">{{ act.title }}</text>
- <view class="card-tags" v-if="tagList(act.tags).length">
- <text class="tag-chip" v-for="(t, ti) in tagList(act.tags)" :key="ti">{{ t }}</text>
- </view>
- <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
- <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
- <view class="card-bottom">
- <text class="card-status status-ended">已结束</text>
- <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
- <text class="card-price free" v-else>免费</text>
- </view>
- </view>
- </view>
- </view>
- <!-- Empty state for history -->
- <view class="empty-state" v-else-if="!historyLoading">
- <text class="empty-icon">📜</text>
- <text class="empty-title">暂无历史活动</text>
- <text class="empty-desc">参加过的活动会显示在这里</text>
- </view>
- <!-- Loading state -->
- <view class="loading-state" v-if="historyLoading">
- <view class="loading-spinner"></view>
- <text class="loading-text">加载中...</text>
- </view>
- <!-- Load more tip -->
- <view class="load-more-tip" v-if="historyActivities.length > 0 && !hasMore && currentTab === 'history'">
- <text class="load-more-text">没有更多了</text>
- </view>
- </view>
- <!-- Tab 4: manage(visibleTabs 已按权限过滤,此处再兜底一次,避免无权限时白屏) -->
- <view v-if="currentTab === 'manage' && canManageActivity">
- <!-- Manage overview stats -->
- <view class="manage-overview">
- <view class="manage-stat-card">
- <text class="manage-stat-num">{{ manageStats.total }}</text>
- <text class="manage-stat-label">全部活动</text>
- </view>
- <view class="manage-stat-card">
- <text class="manage-stat-num manage-published">{{ manageStats.published }}</text>
- <text class="manage-stat-label">已发布</text>
- </view>
- <view class="manage-stat-card">
- <text class="manage-stat-num manage-draft">{{ manageStats.draft }}</text>
- <text class="manage-stat-label">草稿</text>
- </view>
- <view class="manage-stat-card">
- <text class="manage-stat-num manage-ended">{{ manageStats.ended }}</text>
- <text class="manage-stat-label">已结束</text>
- </view>
- </view>
- <!-- Quick actions -->
- <view class="manage-actions">
- <view class="manage-action-btn" @click="goCreate">
- <text class="manage-action-icon">+</text>
- <text class="manage-action-text">创建活动</text>
- </view>
- </view>
- <!-- My managed activities list -->
- <view class="manage-section-title">
- <text>我的活动管理</text>
- </view>
- <view class="card-list" v-if="manageActivities.length > 0">
- <view
- class="activity-card"
- v-for="act in manageActivities"
- :key="act.id"
- @click="goEdit(act)"
- >
- <image
- class="card-cover"
- :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
- mode="aspectFill"
- lazy-load />
- <view class="card-info">
- <text class="card-title">{{ act.title }}</text>
- <view class="card-tags" v-if="tagList(act.tags).length">
- <text class="tag-chip" v-for="(t, ti) in tagList(act.tags)" :key="ti">{{ t }}</text>
- </view>
- <text class="card-meta">{{ act.startTime }}</text>
- <view class="card-bottom">
- <text class="card-status" :class="'status-' + (act.status || 'draft')">
- {{ statusLabel(act.status) }}
- </text>
- <view class="manage-action-group">
- <text class="manage-action-small" v-if="act.status === 'draft'" @click.stop="doPublish(act.id)">{{ canDirectPublish ? '发布' : '提交审核' }}</text>
- <text class="manage-action-small" v-if="act.status === 'rejected'" @click.stop="doPublish(act.id)">重新提交</text>
- <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doEnd(act.id)">结束</text>
- <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doWithdraw(act.id)">撤回</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="empty-state" v-else-if="!manageLoading">
- <text class="empty-icon">📊</text>
- <text class="empty-title">暂无管理的活动</text>
- <text class="empty-desc">点击上方「创建活动」开始</text>
- </view>
- <view class="loading-state" v-if="manageLoading">
- <view class="loading-spinner"></view>
- <text class="loading-text">加载中...</text>
- </view>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import { getActivityList, getMyActivityRegistrations, activityCheckin, cancelActivityRegistration, adminListMyActivities, adminPublishActivity, adminEndActivity, adminWithdrawActivity, submitActivityForReview, vendorStatus, reportAppEnter} from '@/utils/api.js'
- import config from '@/config.js'
- import { parseDate, formatDateTime } from '../../utils/format.js'
- import { hasActivityManageRole, isApprovedActivityProvider } from '@/utils/activity-role.js'
- import fontScaleMixin from '@/mixins/font-scale.js'
- export default {
- mixins: [fontScaleMixin],
- computed: {
- // 管理 tab 只对有活动管理权限的账号展示(普通家长/孩子不显示,避免点进去是空白)
- visibleTabs: function() {
- var list = [
- { key: 'mine', label: '我的活动' },
- { key: 'discover', label: '发现活动' },
- { key: 'history', label: '历史记录' }
- ]
- if (this.canManageActivity) {
- list.push({ key: 'manage', label: '管理' })
- }
- return list
- }
- },
- data() {
- return {
- // 活动管理权限:后台角色(admin/activity_admin/activity_manager)或已通过审核的活动提供商
- canManageActivity: false,
- // 是否有权直接发布(后台活动管理员);服务商只能提交审核
- canDirectPublish: false,
- currentTab: 'mine',
- mineFilters: [
- { label: '全部', value: '' },
- { label: '待开始', value: 'upcoming' },
- { label: '待审核', value: 'pending' },
- { label: '已签到', value: 'checked_in' }
- ],
- dimensionFilters: [
- { label: '全部', value: '' },
- { label: '身', value: 'body' },
- { label: '心', value: 'mind' },
- { label: '智', value: 'wisdom' },
- { label: '行', value: 'action' },
- { label: '富', value: 'wealth' }
- ],
- currentMineFilter: '',
- currentDimension: '',
- myActivities: [],
- discoverActivities: [],
- historyActivities: [],
- mineLoading: false,
- discoverLoading: false,
- historyLoading: false,
- minePage: 1,
- discoverPage: 1,
- historyPage: 1,
- pageSize: 10,
- hasMore: true,
- isRefreshing: false,
- // Manage tab data
- manageLoading: false,
- manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
- manageActivities: []
- }
- },
- onLoad: function(options) {
- reportAppEnter('activity');
- if (options && options.tab) {
- this.currentTab = options.tab
- }
- this.resolveManagePermission()
- this.loadData()
- this._onLoadFired = true
- },
- onShow: function() {
- if (this._onLoadFired) {
- this._onLoadFired = false // 首次进入:onLoad 已加载,跳过避免双发
- } else {
- // 切 Tab/从子页返回:刷新权限态(同步部分不发请求)+ 当前 tab 数据
- this.resolveManagePermission()
- this.loadData()
- }
- },
- methods: {
- tagList: function(tags) {
- return String(tags || '').split(/[,,、]/).map(function(t) { return t.trim() }).filter(function(t) { return !!t })
- },
- // 活动管理权限判定:与后端 ActivityController.hasActivityManageRole 对齐。
- // 后台角色(admin / activity_admin / activity_manager)→ 可直接发布;
- // 其余账号查服务商入驻状态,vendorType=activity_provider 且审核通过 → 可管理(只能提交审核)。
- resolveManagePermission: function() {
- var self = this
- if (hasActivityManageRole()) {
- self.canDirectPublish = true
- self.canManageActivity = true
- self.onPermissionResolved()
- return
- }
- // 未登录不发 vendorStatus:请求层会因 401 触发静默续期/跳登录,影响游客浏览活动
- if (!uni.getStorageSync('token')) {
- return
- }
- vendorStatus().then(function(res) {
- var approvedProvider = isApprovedActivityProvider((res && res.data) || {})
- // 非后台角色才由服务商审核状态决定(后台角色已在上面提前返回,不会被覆盖)
- if (!self.canDirectPublish) {
- self.canManageActivity = approvedProvider
- }
- self.onPermissionResolved()
- }).catch(function() {
- if (!self.canDirectPublish) {
- self.canManageActivity = false
- }
- self.onPermissionResolved()
- })
- },
- // 权限解析完成后的兜底:以 ?tab=manage 进来但无权限时回落到「我的活动」,避免空白页
- onPermissionResolved: function() {
- if (this.currentTab === 'manage' && !this.canManageActivity) {
- this.currentTab = 'mine'
- this.loadData()
- }
- },
- getImageUrl: function(path) {
- if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
- var s = String(path).trim()
- if (!s || s === 'null' || s === '/null') return ''
- if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
- return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
- },
- onTabChange: function(key) {
- this.currentTab = key
- this.hasMore = true
- if (key === 'mine') {
- this.minePage = 1
- this.myActivities = []
- } else if (key === 'discover') {
- this.discoverPage = 1
- this.discoverActivities = []
- } else if (key === 'history') {
- this.historyPage = 1
- this.historyActivities = []
- }
- this.loadData()
- },
- loadData: function() {
- if (this.currentTab === 'mine') {
- this.loadMyActivities()
- } else if (this.currentTab === 'discover') {
- this.loadDiscoverActivities()
- } else if (this.currentTab === 'history') {
- this.loadHistoryActivities()
- } else if (this.currentTab === 'manage') {
- // 权限未解析/无权限时不发管理列表请求(onPermissionResolved 会回落 mine)
- if (this.canManageActivity) {
- this.loadManageData()
- }
- }
- },
- loadManageData: function() {
- var self = this
- this.manageLoading = true
- // 活动服务商(非后台角色)只看自己创建/负责的活动,后台活动管理员由后端按角色隔离
- var params = { page: 1, size: 100 }
- if (!self.canDirectPublish) {
- params.mineOnly = true
- }
- adminListMyActivities(params).then(function(res) {
- self.manageLoading = false
- if (res && res.code === 200 && res.data) {
- var records = res.data.records || []
- self.manageActivities = records.slice(0, 20)
- var total = records.length
- var published = 0
- var draft = 0
- var ended = 0
- for (var i = 0; i < records.length; i++) {
- var s = records[i].status
- if (s === 'published') published++
- else if (s === 'draft') draft++
- else if (s === 'ended' || s === 'cancelled' || s === 'withdrawn') ended++
- }
- self.manageStats = { total: total, published: published, draft: draft, ended: ended }
- } else {
- self.manageActivities = []
- self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
- }
- }).catch(function() {
- self.manageLoading = false
- self.manageActivities = []
- self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
- })
- },
- goCreate: function() {
- uni.navigateTo({ url: '/pages/activity/create' })
- },
- goEdit: function(act) {
- uni.navigateTo({ url: '/pages/activity/create?id=' + act.id })
- },
- statusLabel: function(status) {
- var map = {
- draft: '草稿',
- pending: '待审核',
- rejected: '已驳回',
- published: '进行中',
- ended: '已结束',
- withdrawn: '已撤回',
- cancelled: '已取消'
- }
- return map[status] || status
- },
- doPublish: function(id) {
- var self = this
- uni.showModal({
- title: '提示',
- content: '确认发布此活动吗?发布后将对外可见。',
- success: function(res) {
- if (res.confirm) {
- uni.showLoading({ title: '发布中...' })
- if (self.canDirectPublish) {
- adminPublishActivity(id).then(function(r) {
- uni.hideLoading()
- if (r && r.code === 200) {
- uni.showToast({ title: '发布成功', icon: 'success' })
- self.loadManageData()
- } else {
- uni.showToast({ title: (r && r.message) || '发布失败', icon: 'none' })
- }
- }).catch(function() {
- uni.hideLoading()
- uni.showToast({ title: '发布失败', icon: 'none' })
- })
- } else {
- submitActivityForReview(id).then(function(r) {
- uni.hideLoading()
- if (r && r.code === 200) {
- uni.showToast({ title: '已提交审核', icon: 'success' })
- self.loadManageData()
- } else {
- uni.showToast({ title: (r && r.message) || '提交审核失败', icon: 'none' })
- }
- }).catch(function() {
- uni.hideLoading()
- uni.showToast({ title: '提交审核失败', icon: 'none' })
- })
- }
- }
- }
- })
- },
- doEnd: function(id) {
- var self = this
- uni.showModal({
- title: '提示',
- content: '确认结束此活动吗?结束后不再接受新参与者。',
- success: function(res) {
- if (res.confirm) {
- uni.showLoading({ title: '操作中...' })
- adminEndActivity(id).then(function(r) {
- uni.hideLoading()
- if (r && r.code === 200) {
- uni.showToast({ title: '已结束', icon: 'success' })
- self.loadManageData()
- } else {
- uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
- }
- }).catch(function() {
- uni.hideLoading()
- uni.showToast({ title: '网络异常', icon: 'none' })
- })
- }
- }
- })
- },
- doWithdraw: function(id) {
- var self = this
- uni.showModal({
- title: '提示',
- content: '确认撤回此活动吗?撤回后不再对外展示,可重新编辑。',
- success: function(res) {
- if (res.confirm) {
- uni.showLoading({ title: '操作中...' })
- adminWithdrawActivity(id).then(function(r) {
- uni.hideLoading()
- if (r && r.code === 200) {
- uni.showToast({ title: '已撤回', icon: 'success' })
- self.loadManageData()
- } else {
- uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
- }
- }).catch(function() {
- uni.hideLoading()
- uni.showToast({ title: '网络异常', icon: 'none' })
- })
- }
- }
- })
- },
- onMineFilterChange: function(value) {
- this.currentMineFilter = value
- this.minePage = 1
- this.myActivities = []
- this.hasMore = true
- if (this.currentTab === 'mine') {
- this.loadMyActivities()
- } else if (this.currentTab === 'history') {
- this.loadHistoryActivities()
- }
- },
- onDimensionChange: function(value) {
- this.currentDimension = value
- this.discoverPage = 1
- this.discoverActivities = []
- this.hasMore = true
- this.loadDiscoverActivities()
- },
- onLoadMore: function() {
- if (!this.hasMore) return
- if (this.currentTab === 'mine' && !this.mineLoading) {
- this.minePage++
- this.loadMyActivities()
- } else if (this.currentTab === 'discover' && !this.discoverLoading) {
- this.discoverPage++
- this.loadDiscoverActivities()
- } else if (this.currentTab === 'history' && !this.historyLoading) {
- this.historyPage++
- this.loadHistoryActivities()
- }
- },
- onRefresh: function() {
- var self = this
- this.isRefreshing = true
- if (this.currentTab === 'mine') {
- this.loadMyActivities(true).finally(function() {
- self.isRefreshing = false
- })
- } else if (this.currentTab === 'discover') {
- this.loadDiscoverActivities(true).finally(function() {
- self.isRefreshing = false
- })
- } else if (this.currentTab === 'history') {
- this.loadHistoryActivities(true).finally(function() {
- self.isRefreshing = false
- })
- } else {
- this.isRefreshing = false
- }
- },
- loadMyActivities: function(refresh) {
- var self = this
- if (refresh) {
- this.minePage = 1
- this.myActivities = []
- }
- this.mineLoading = true
- var memberId = uni.getStorageSync('currentChildId')
- if (!memberId) {
- this.mineLoading = false
- return
- }
- var params = {
- memberId: memberId,
- page: this.minePage,
- size: this.pageSize
- }
- if (this.currentMineFilter && this.currentMineFilter !== 'upcoming') {
- params.status = this.currentMineFilter
- }
- getMyActivityRegistrations(params).then(function(res) {
- self.mineLoading = false
- if (res && res.code === 200 && res.data) {
- var records = res.data.records || []
- for (var ni = 0; ni < records.length; ni++) {
- self.normalizeRegistration(records[ni])
- }
- if (self.currentMineFilter === 'upcoming') {
- var now = new Date()
- var filtered = []
- for (var i = 0; i < records.length; i++) {
- var act = records[i]
- if (act.startTime) {
- var startTime = parseDate(act.startTime)
- if (!startTime) continue
- if (startTime > now && act.status === 'approved') {
- filtered.push(act)
- }
- }
- }
- records = filtered
- }
- for (var di = 0; di < records.length; di++) {
- self.decorateActivity(records[di])
- }
- if (refresh) {
- self.myActivities = records
- } else {
- self.myActivities = self.myActivities.concat(records)
- }
- self.hasMore = records.length >= self.pageSize
- }
- }).catch(function() {
- self.mineLoading = false
- })
- },
- loadDiscoverActivities: function(refresh) {
- var self = this
- if (refresh) {
- this.discoverPage = 1
- this.discoverActivities = []
- }
- this.discoverLoading = true
- var params = {
- page: this.discoverPage,
- size: this.pageSize
- }
- if (this.currentDimension) {
- params.dimensionCode = this.currentDimension
- }
- getActivityList(params).then(function(res) {
- self.discoverLoading = false
- if (res && res.code === 200 && res.data) {
- var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
- if (refresh) {
- self.discoverActivities = list
- } else {
- self.discoverActivities = self.discoverActivities.concat(list)
- }
- self.hasMore = list.length >= self.pageSize
- }
- }).catch(function() {
- self.discoverLoading = false
- })
- },
- loadHistoryActivities: function(refresh) {
- var self = this
- if (refresh) {
- this.historyPage = 1
- this.historyActivities = []
- }
- this.historyLoading = true
- var memberId = uni.getStorageSync('currentChildId')
- if (!memberId) {
- this.historyLoading = false
- return
- }
- var params = {
- memberId: memberId,
- page: this.historyPage,
- size: this.pageSize
- }
- getMyActivityRegistrations(params).then(function(res) {
- self.historyLoading = false
- if (res && res.code === 200 && res.data) {
- var records = res.data.records || []
- var now = new Date()
- var ended = []
- for (var i = 0; i < records.length; i++) {
- var act = records[i]
- self.normalizeRegistration(act)
- var endTime = parseDate(act.endTime)
- var startTime = parseDate(act.startTime)
- // 有结束时间按结束时间判断;无结束时间(如线上活动)按开始时间已过判断
- var isPast = (endTime && endTime < now) || (!endTime && startTime && startTime < now)
- if (isPast || act.status === 'cancelled' || act.status === 'rejected') {
- ended.push(act)
- }
- }
- if (refresh) {
- self.historyActivities = ended
- } else {
- self.historyActivities = self.historyActivities.concat(ended)
- }
- self.hasMore = records.length >= self.pageSize
- }
- }).catch(function() {
- self.historyLoading = false
- })
- },
- // 报名记录 → 卡片所需字段:/api/activity/my-registrations 返回的是
- // activityTitle/activityStartTime/... ,直接渲染会标题/时间/封面/费用全空
- normalizeRegistration: function(act) {
- if (!act) return act
- if (!act.title && act.activityTitle) act.title = act.activityTitle
- if (act.activityStartTime) act.startTime = formatDateTime(act.activityStartTime)
- if (act.activityEndTime) act.endTime = formatDateTime(act.activityEndTime)
- if (!act.coverImage && act.activityCoverImage) act.coverImage = act.activityCoverImage
- if (!act.location && act.activityLocation) act.location = act.activityLocation
- var fees = [act.activityChildFee, act.activityChildMemberFee, act.activityParentFee, act.activityParentMemberFee]
- var price = 0
- for (var i = 0; i < fees.length; i++) {
- var f = Number(fees[i]) || 0
- if (f > 0 && (price === 0 || f < price)) price = f
- }
- act.price = price
- return act
- },
- goDetail: function(act) {
- // 报名记录的 id 是报名 id,必须取 activityId;发现列表的 id 即活动 id
- var id = act.activityId || act.id
- uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + id })
- },
- switchToDiscover: function() {
- this.currentTab = 'discover'
- this.hasMore = true
- this.discoverPage = 1
- this.discoverActivities = []
- this.loadDiscoverActivities()
- },
- formatPrice: function(price) {
- return (price / 100).toFixed(2)
- },
- formatDateTime: formatDateTime,
- hasFee: function(act) {
- return (act.childFee > 0) || (act.childMemberFee > 0) || (act.parentFee > 0) || (act.parentMemberFee > 0)
- },
- minFee: function(act) {
- var fees = [act.childFee, act.childMemberFee, act.parentFee, act.parentMemberFee]
- var min = 0
- for (var i = 0; i < fees.length; i++) {
- if (fees[i] > 0 && (min === 0 || fees[i] < min)) min = fees[i]
- }
- return this.formatPrice(min)
- },
- decorateActivity: function(act) {
- if (act.status) {
- act._cls = act.status
- var map = { pending: '待审核', approved: '报名成功', rejected: '已拒绝', cancelled: '已取消', checked_in: '已签到' }
- act._txt = map[act.status] || act.status
- } else {
- if (act.endTime) {
- var endTime = parseDate(act.endTime)
- if (endTime && endTime < new Date()) {
- act._cls = 'ended'
- act._txt = '已结束'
- return act
- }
- }
- act._cls = 'upcoming'
- act._txt = '待开始'
- }
- return act
- },
- onCheckin: function(act) {
- var self = this
- var memberId = uni.getStorageSync('currentChildId')
- if (!memberId) {
- uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
- return
- }
- activityCheckin({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
- if (res && res.code === 200) {
- uni.showToast({ title: '签到成功', icon: 'success' })
- self.loadMyActivities(true)
- } else {
- uni.showToast({ title: (res && res.message) || '签到失败', icon: 'none' })
- }
- }).catch(function() {
- uni.showToast({ title: '网络异常', icon: 'none' })
- })
- },
- onCancel: function(act) {
- var self = this
- uni.showModal({
- title: '提示',
- content: '确定要取消报名吗?',
- success: function(res) {
- if (res.confirm) {
- var memberId = uni.getStorageSync('currentChildId')
- if (!memberId) {
- uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
- return
- }
- cancelActivityRegistration({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
- if (res && res.code === 200) {
- uni.showToast({ title: '已取消报名', icon: 'success' })
- self.loadMyActivities(true)
- } else {
- uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
- }
- }).catch(function() {
- uni.showToast({ title: '网络异常', icon: 'none' })
- })
- }
- }
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .activity-container {
- min-height: 100vh;
- background: $facade-fill-2;
- display: flex;
- flex-direction: column;
- }
- .tab-bar {
- background: $app-surface;
- display: flex;
- flex-direction: row;
- border-bottom: 1rpx solid $facade-hairline-2;
- }
- .tab-item {
- flex: 1;
- padding: 24rpx 0;
- text-align: center;
- border-bottom: 4rpx solid transparent;
- }
- .tab-item.active {
- border-bottom-color: $brand-primary;
- }
- .tab-label {
- font-size: 28rpx;
- color: $facade-text-body;
- }
- .tab-item.active .tab-label {
- color: $brand-primary;
- font-weight: 600;
- }
- .content-scroll {
- flex: 1;
- height: calc(100vh - 200rpx);
- }
- .filter-scroll {
- padding: 20rpx 24rpx;
- background: $app-surface;
- }
- .filter-chips {
- display: flex;
- flex-direction: row;
- gap: 16rpx;
- }
- .filter-chip {
- padding: 12rpx 24rpx;
- border-radius: 16px;
- background: $app-surface;
- border: 1rpx solid $facade-border-soft;
- flex-shrink: 0;
- }
- .filter-chip.active {
- background: $uni-primary-pale;
- border-color: $brand-primary;
- }
- .filter-label {
- font-size: 24rpx;
- color: $facade-text-body;
- }
- .filter-chip.active .filter-label {
- color: $brand-primary;
- font-weight: 500;
- }
- .card-list {
- padding: 0 24rpx 24rpx;
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- }
- .activity-card {
- background: $app-surface;
- border-radius: 12rpx;
- padding: 20rpx;
- display: flex;
- box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
- }
- .card-cover {
- width: 144rpx;
- height: 144rpx;
- border-radius: 8rpx;
- flex-shrink: 0;
- background: $facade-fill;
- }
- .card-info {
- flex: 1;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- }
- .card-tags {
- display: flex;
- flex-wrap: wrap;
- margin-top: 10rpx;
- }
- .tag-chip {
- font-size: 22rpx;
- color: $brand-primary;
- background: $uni-primary-pale;
- padding: 2rpx 12rpx;
- border-radius: 6rpx;
- margin-right: 8rpx;
- margin-bottom: 4rpx;
- }
- .card-title {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $facade-text-strong;
- line-height: 1.4;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .card-meta {
- font-size: 24rpx;
- color: $facade-text-muted;
- margin-top: 8rpx;
- }
- .card-bottom {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- margin-top: auto;
- padding-top: 12rpx;
- }
- .card-status {
- font-size: 22rpx;
- padding: 4rpx 12rpx;
- border-radius: 6rpx;
- }
- .status-pending {
- background: $uni-primary-pale;
- color: $brand-primary;
- }
- .status-approved {
- background: $status-success-tint-2;
- color: $status-success-2;
- }
- .status-rejected {
- background: $status-danger-tint-2;
- color: $status-danger;
- }
- .status-cancelled {
- background: $facade-fill-2;
- color: $facade-text-muted;
- }
- .status-checked_in {
- background: $status-info-soft;
- color: $status-info;
- }
- .status-upcoming {
- background: $uni-primary-pale;
- color: $brand-primary;
- }
- .status-ended {
- background: $facade-fill-2;
- color: $facade-text-muted;
- }
- .status-published {
- background: $status-success-tint-2;
- color: $status-success-2;
- }
- .status-draft {
- background: $uni-primary-pale;
- color: $brand-primary;
- }
- .card-price {
- font-size: 28rpx;
- color: $brand-primary;
- font-weight: 600;
- }
- .card-price.free {
- color: $status-success-2;
- }
- .card-actions {
- display: flex;
- flex-direction: row;
- gap: 12rpx;
- margin-top: 12rpx;
- }
- .btn-cancel {
- padding: 8rpx 20rpx;
- font-size: 22rpx;
- color: $facade-text-muted;
- background: $app-surface;
- border: 1rpx solid $facade-border-soft;
- border-radius: 20rpx;
- line-height: 1.5;
- }
- .btn-checkin {
- padding: 8rpx 20rpx;
- font-size: 22rpx;
- color: $app-surface;
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- border: none;
- border-radius: 20rpx;
- line-height: 1.5;
- }
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 120rpx 40rpx;
- }
- .empty-icon {
- font-size: 80rpx;
- margin-bottom: 20rpx;
- }
- .empty-title {
- font-size: 32rpx;
- font-weight: 600;
- color: $facade-text-strong;
- margin-bottom: 12rpx;
- }
- .empty-desc {
- font-size: 26rpx;
- color: $facade-text-muted;
- margin-bottom: 40rpx;
- }
- .empty-btn {
- padding: 16rpx 48rpx;
- font-size: 28rpx;
- color: $app-surface;
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- border: none;
- border-radius: 40rpx;
- }
- .loading-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 80rpx 40rpx;
- }
- .loading-spinner {
- width: 60rpx;
- height: 60rpx;
- border: 4rpx solid $status-warning-light;
- border-top-color: $brand-primary;
- border-radius: 50%;
- animation: spin 0.8s linear infinite;
- margin-bottom: 20rpx;
- }
- @keyframes spin {
- to { transform: rotate(360deg); }
- }
- .loading-text {
- font-size: 26rpx;
- color: $facade-text-muted;
- }
- .load-more-tip {
- text-align: center;
- padding: 30rpx;
- }
- .load-more-text {
- font-size: 24rpx;
- color: $facade-text-muted;
- }
- /* Nav add button */
- .nav-add-btn {
- position: absolute;
- right: 24rpx;
- top: 50%;
- transform: translateY(-50%);
- width: 56rpx;
- height: 56rpx;
- background: rgba(255, 255, 255, 0.15);
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .nav-add-icon {
- color: $app-surface;
- font-size: 36rpx;
- font-weight: 300;
- line-height: 1;
- }
- /* Manage overview stats */
- .manage-overview {
- display: flex;
- flex-direction: row;
- padding: 24rpx;
- gap: 16rpx;
- background: $app-surface;
- margin: 24rpx 24rpx 0;
- border-radius: 12rpx;
- box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
- }
- .manage-stat-card {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 16rpx 0;
- }
- .manage-stat-num {
- font-size: 40rpx;
- font-weight: 700;
- color: $facade-text-strong;
- line-height: 1.2;
- }
- .manage-published {
- color: $status-success-2;
- }
- .manage-draft {
- color: $brand-primary;
- }
- .manage-ended {
- color: $facade-text-muted;
- }
- .manage-stat-label {
- font-size: 22rpx;
- color: $facade-text-muted;
- margin-top: 8rpx;
- }
- /* Quick action button */
- .manage-actions {
- padding: 24rpx 24rpx 0;
- }
- .manage-action-btn {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: center;
- gap: 12rpx;
- padding: 24rpx 0;
- background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
- border-radius: 12rpx;
- margin: 0 24rpx;
- }
- .manage-action-icon {
- color: $app-surface;
- font-size: 36rpx;
- font-weight: 300;
- }
- .manage-action-text {
- color: $app-surface;
- font-size: 28rpx;
- font-weight: 600;
- }
- /* Section title */
- .manage-section-title {
- padding: 24rpx 24rpx 12rpx;
- }
- .manage-section-title text {
- font-size: 28rpx;
- font-weight: 600;
- color: $facade-text-strong;
- }
- /* Manage action group in card */
- .manage-action-group {
- display: flex;
- flex-direction: row;
- gap: 16rpx;
- align-items: center;
- }
- .manage-action-small {
- font-size: 22rpx;
- padding: 4rpx 16rpx;
- border-radius: 20rpx;
- background: $brand-primary;
- color: $app-surface;
- font-weight: 500;
- }
- </style>
|