| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305 |
- <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>
- <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>
- <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
- <text class="card-desc" v-if="act.description">{{ 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>
- <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>
- <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: {
- // 活动管理权限判定:与后端 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-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: #FEF2F2;
- 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 #FDE68A;
- 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>
|