index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. <template>
  2. <view class="activity-container" :style="{ '--font-scale': fontScale }">
  3. <!-- Nav bar with title "活动中心" and admin "+" button -->
  4. <!-- Tab bar (4 tabs) -->
  5. <view class="tab-bar">
  6. <view
  7. class="tab-item"
  8. :class="{ active: currentTab === tab.key }"
  9. v-for="tab in tabs"
  10. :key="tab.key"
  11. @click="onTabChange(tab.key)"
  12. >
  13. <text class="tab-label">{{ tab.label }}</text>
  14. </view>
  15. </view>
  16. <!-- ScrollView content area -->
  17. <scroll-view
  18. class="content-scroll"
  19. scroll-y
  20. :refresher-enabled="true"
  21. :refresher-triggered="isRefreshing"
  22. @refresherrefresh="onRefresh"
  23. @scrolltolower="onLoadMore"
  24. >
  25. <!-- Tab 1: mine -->
  26. <view v-if="currentTab === 'mine'">
  27. <!-- Filter chips -->
  28. <scroll-view class="filter-scroll" scroll-x enable-flex>
  29. <view class="filter-chips">
  30. <view
  31. class="filter-chip"
  32. :class="{ active: currentMineFilter === filter.value }"
  33. v-for="filter in mineFilters"
  34. :key="filter.value"
  35. @click="onMineFilterChange(filter.value)"
  36. >
  37. <text class="filter-label">{{ filter.label }}</text>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. <!-- Activity cards -->
  42. <view class="card-list" v-if="myActivities.length > 0">
  43. <view
  44. class="activity-card"
  45. v-for="act in myActivities"
  46. :key="act.id"
  47. @click="goDetail(act)"
  48. >
  49. <image
  50. class="card-cover"
  51. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  52. mode="aspectFill"
  53. />
  54. <view class="card-info">
  55. <text class="card-title">{{ act.title }}</text>
  56. <text class="card-meta" v-if="act.registrantName">报名人:{{ act.registrantName }}</text>
  57. <text class="card-meta">{{ act.startTime }}</text>
  58. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  59. <view class="card-bottom">
  60. <text class="card-status" :class="'status-' + (act._cls || 'upcoming')">
  61. {{ act._txt || '待开始' }}
  62. </text>
  63. <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
  64. <text class="card-price free" v-else>免费</text>
  65. </view>
  66. <!-- Action buttons for approved status -->
  67. <view
  68. v-if="act.status === 'approved'"
  69. class="card-actions"
  70. >
  71. <button class="btn-cancel" @click.stop="onCancel(act)">取消报名</button>
  72. <button class="btn-checkin" @click.stop="onCheckin(act)">签到</button>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- Empty state for mine -->
  78. <view class="empty-state" v-else-if="!mineLoading">
  79. <text class="empty-icon">📋</text>
  80. <text class="empty-title">暂无报名的活动</text>
  81. <text class="empty-desc">去发现页探索精彩活动吧</text>
  82. <button class="empty-btn" @click="switchToDiscover">去发现活动</button>
  83. </view>
  84. <!-- Loading state -->
  85. <view class="loading-state" v-if="mineLoading">
  86. <view class="loading-spinner"></view>
  87. <text class="loading-text">加载中...</text>
  88. </view>
  89. <!-- Load more tip -->
  90. <view class="load-more-tip" v-if="myActivities.length > 0 && !hasMore && currentTab === 'mine'">
  91. <text class="load-more-text">没有更多了</text>
  92. </view>
  93. </view>
  94. <!-- Tab 2: discover -->
  95. <view v-if="currentTab === 'discover'">
  96. <!-- Filter chips (dimension) -->
  97. <scroll-view class="filter-scroll" scroll-x enable-flex>
  98. <view class="filter-chips">
  99. <view
  100. class="filter-chip"
  101. :class="{ active: currentDimension === filter.value }"
  102. v-for="filter in dimensionFilters"
  103. :key="filter.value"
  104. @click="onDimensionChange(filter.value)"
  105. >
  106. <text class="filter-label">{{ filter.label }}</text>
  107. </view>
  108. </view>
  109. </scroll-view>
  110. <!-- Activity cards -->
  111. <view class="card-list" v-if="discoverActivities.length > 0">
  112. <view
  113. class="activity-card"
  114. v-for="act in discoverActivities"
  115. :key="act.id"
  116. @click="goDetail(act)"
  117. >
  118. <image
  119. class="card-cover"
  120. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  121. mode="aspectFill"
  122. />
  123. <view class="card-info">
  124. <text class="card-title">{{ act.title }}</text>
  125. <text class="card-meta">{{ act.startTime }}</text>
  126. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  127. <view class="card-bottom">
  128. <text class="card-status" :class="'status-' + (act.displayStatus || 'open')">
  129. {{ act.displayLabel || '报名中' }}
  130. </text>
  131. <text class="card-price" v-if="hasFee(act)">¥{{ minFee(act) }}</text>
  132. <text class="card-price free" v-else>免费</text>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. <!-- Empty state for discover -->
  138. <view class="empty-state" v-else-if="!discoverLoading">
  139. <text class="empty-icon">🔍</text>
  140. <text class="empty-title">暂无活动</text>
  141. <text class="empty-desc">稍后再来看看吧</text>
  142. </view>
  143. <!-- Loading state -->
  144. <view class="loading-state" v-if="discoverLoading">
  145. <view class="loading-spinner"></view>
  146. <text class="loading-text">加载中...</text>
  147. </view>
  148. <!-- Load more tip -->
  149. <view class="load-more-tip" v-if="discoverActivities.length > 0 && !hasMore && currentTab === 'discover'">
  150. <text class="load-more-text">没有更多了</text>
  151. </view>
  152. </view>
  153. <!-- Tab 3: history -->
  154. <view v-if="currentTab === 'history'">
  155. <!-- Filter chips (same as mine) -->
  156. <scroll-view class="filter-scroll" scroll-x enable-flex>
  157. <view class="filter-chips">
  158. <view
  159. class="filter-chip"
  160. :class="{ active: currentMineFilter === filter.value }"
  161. v-for="filter in mineFilters"
  162. :key="filter.value"
  163. @click="onMineFilterChange(filter.value)"
  164. >
  165. <text class="filter-label">{{ filter.label }}</text>
  166. </view>
  167. </view>
  168. </scroll-view>
  169. <!-- Activity cards -->
  170. <view class="card-list" v-if="historyActivities.length > 0">
  171. <view
  172. class="activity-card"
  173. v-for="act in historyActivities"
  174. :key="act.id"
  175. @click="goDetail(act)"
  176. >
  177. <image
  178. class="card-cover"
  179. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  180. mode="aspectFill"
  181. />
  182. <view class="card-info">
  183. <text class="card-title">{{ act.title }}</text>
  184. <text class="card-meta">{{ act.startTime }}</text>
  185. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  186. <view class="card-bottom">
  187. <text class="card-status status-ended">已结束</text>
  188. <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
  189. <text class="card-price free" v-else>免费</text>
  190. </view>
  191. </view>
  192. </view>
  193. </view>
  194. <!-- Empty state for history -->
  195. <view class="empty-state" v-else-if="!historyLoading">
  196. <text class="empty-icon">📜</text>
  197. <text class="empty-title">暂无历史活动</text>
  198. <text class="empty-desc">参加过的活动会显示在这里</text>
  199. </view>
  200. <!-- Loading state -->
  201. <view class="loading-state" v-if="historyLoading">
  202. <view class="loading-spinner"></view>
  203. <text class="loading-text">加载中...</text>
  204. </view>
  205. <!-- Load more tip -->
  206. <view class="load-more-tip" v-if="historyActivities.length > 0 && !hasMore && currentTab === 'history'">
  207. <text class="load-more-text">没有更多了</text>
  208. </view>
  209. </view>
  210. <!-- Tab 4: manage (admin or activity_provider) -->
  211. <view v-if="currentTab === 'manage' && (isAdmin || isActivityProvider)">
  212. <!-- Manage overview stats -->
  213. <view class="manage-overview">
  214. <view class="manage-stat-card">
  215. <text class="manage-stat-num">{{ manageStats.total }}</text>
  216. <text class="manage-stat-label">全部活动</text>
  217. </view>
  218. <view class="manage-stat-card">
  219. <text class="manage-stat-num manage-published">{{ manageStats.published }}</text>
  220. <text class="manage-stat-label">已发布</text>
  221. </view>
  222. <view class="manage-stat-card">
  223. <text class="manage-stat-num manage-draft">{{ manageStats.draft }}</text>
  224. <text class="manage-stat-label">草稿</text>
  225. </view>
  226. <view class="manage-stat-card">
  227. <text class="manage-stat-num manage-ended">{{ manageStats.ended }}</text>
  228. <text class="manage-stat-label">已结束</text>
  229. </view>
  230. </view>
  231. <!-- Quick actions -->
  232. <view class="manage-actions">
  233. <view class="manage-action-btn" @click="goCreate">
  234. <text class="manage-action-icon">+</text>
  235. <text class="manage-action-text">创建活动</text>
  236. </view>
  237. </view>
  238. <!-- My managed activities list -->
  239. <view class="manage-section-title">
  240. <text>我的活动管理</text>
  241. </view>
  242. <view class="card-list" v-if="manageActivities.length > 0">
  243. <view
  244. class="activity-card"
  245. v-for="act in manageActivities"
  246. :key="act.id"
  247. @click="goEdit(act)"
  248. >
  249. <image
  250. class="card-cover"
  251. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  252. mode="aspectFill"
  253. />
  254. <view class="card-info">
  255. <text class="card-title">{{ act.title }}</text>
  256. <text class="card-meta">{{ act.startTime }}</text>
  257. <view class="card-bottom">
  258. <text class="card-status" :class="'status-' + (act.status || 'draft')">
  259. {{ statusLabel(act.status) }}
  260. </text>
  261. <view class="manage-action-group">
  262. <text class="manage-action-small" v-if="act.status === 'draft'" @click.stop="doPublish(act.id)">{{ isAdmin ? '发布' : '提交审核' }}</text>
  263. <text class="manage-action-small" v-if="act.status === 'rejected'" @click.stop="doPublish(act.id)">重新提交</text>
  264. <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doEnd(act.id)">结束</text>
  265. <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doWithdraw(act.id)">撤回</text>
  266. </view>
  267. </view>
  268. </view>
  269. </view>
  270. </view>
  271. <view class="empty-state" v-else-if="!manageLoading">
  272. <text class="empty-icon">📊</text>
  273. <text class="empty-title">暂无管理的活动</text>
  274. <text class="empty-desc">点击上方「创建活动」开始</text>
  275. </view>
  276. <view class="loading-state" v-if="manageLoading">
  277. <view class="loading-spinner"></view>
  278. <text class="loading-text">加载中...</text>
  279. </view>
  280. </view>
  281. </scroll-view>
  282. </view>
  283. </template>
  284. <script>
  285. import { getActivityList, getMyActivityRegistrations, activityCheckin, cancelActivityRegistration, adminListMyActivities, adminPublishActivity, adminEndActivity, adminWithdrawActivity, submitActivityForReview, reportAppEnter} from '@/utils/api.js'
  286. import config from '@/config.js'
  287. import { parseDate } from '../../utils/format.js'
  288. import fontScaleMixin from '@/mixins/font-scale.js'
  289. export default {
  290. mixins: [fontScaleMixin],
  291. computed: {
  292. isAdmin: function() {
  293. var userInfo = uni.getStorageSync('userInfo')
  294. if (!userInfo) return false
  295. if (userInfo.role === 'admin' || userInfo.role === 'activity_admin' || userInfo.role === 'activity_manager') return true
  296. if (userInfo.roles && userInfo.roles.length) {
  297. for (var i = 0; i < userInfo.roles.length; i++) {
  298. var r = userInfo.roles[i]
  299. if (r === 'activity_admin' || r === 'activity_manager' || r === 'admin') return true
  300. }
  301. }
  302. return false
  303. },
  304. isActivityProvider: function() {
  305. var userInfo = uni.getStorageSync('userInfo')
  306. return userInfo && userInfo.vendorType === 'activity_provider' && userInfo.activityProviderStatus === 'approved'
  307. }
  308. },
  309. data() {
  310. return {
  311. tabs: [
  312. { key: 'mine', label: '我的活动' },
  313. { key: 'discover', label: '发现活动' },
  314. { key: 'history', label: '历史记录' },
  315. { key: 'manage', label: '管理' }
  316. ],
  317. currentTab: 'mine',
  318. mineFilters: [
  319. { label: '全部', value: '' },
  320. { label: '待开始', value: 'upcoming' },
  321. { label: '待审核', value: 'pending' },
  322. { label: '已签到', value: 'checked_in' }
  323. ],
  324. dimensionFilters: [
  325. { label: '全部', value: '' },
  326. { label: '身', value: 'body' },
  327. { label: '心', value: 'mind' },
  328. { label: '智', value: 'wisdom' },
  329. { label: '行', value: 'action' },
  330. { label: '富', value: 'wealth' }
  331. ],
  332. currentMineFilter: '',
  333. currentDimension: '',
  334. myActivities: [],
  335. discoverActivities: [],
  336. historyActivities: [],
  337. mineLoading: false,
  338. discoverLoading: false,
  339. historyLoading: false,
  340. minePage: 1,
  341. discoverPage: 1,
  342. historyPage: 1,
  343. pageSize: 10,
  344. hasMore: true,
  345. isRefreshing: false,
  346. // Manage tab data
  347. manageLoading: false,
  348. manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
  349. manageActivities: []
  350. }
  351. },
  352. onLoad: function(options) {
  353. reportAppEnter('activity');
  354. if (options && options.tab) {
  355. this.currentTab = options.tab
  356. this.loadData()
  357. }
  358. },
  359. onShow: function() {
  360. if (this.currentTab === 'mine') {
  361. this.loadMyActivities(true)
  362. } else if (this.currentTab === 'manage') {
  363. this.loadManageData()
  364. }
  365. },
  366. methods: {
  367. getImageUrl: function(path) {
  368. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  369. var s = String(path).trim()
  370. if (!s || s === 'null' || s === '/null') return ''
  371. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  372. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  373. },
  374. onTabChange: function(key) {
  375. this.currentTab = key
  376. this.hasMore = true
  377. if (key === 'mine') {
  378. this.minePage = 1
  379. this.myActivities = []
  380. } else if (key === 'discover') {
  381. this.discoverPage = 1
  382. this.discoverActivities = []
  383. } else if (key === 'history') {
  384. this.historyPage = 1
  385. this.historyActivities = []
  386. } else if (key === 'manage') {
  387. this.loadManageData()
  388. }
  389. this.loadData()
  390. },
  391. loadData: function() {
  392. if (this.currentTab === 'mine') {
  393. this.loadMyActivities()
  394. } else if (this.currentTab === 'discover') {
  395. this.loadDiscoverActivities()
  396. } else if (this.currentTab === 'history') {
  397. this.loadHistoryActivities()
  398. }
  399. },
  400. loadManageData: function() {
  401. var self = this
  402. this.manageLoading = true
  403. adminListMyActivities({ page: 1, size: 100 }).then(function(res) {
  404. self.manageLoading = false
  405. if (res && res.code === 200 && res.data) {
  406. var records = res.data.records || []
  407. self.manageActivities = records.slice(0, 20)
  408. var total = records.length
  409. var published = 0
  410. var draft = 0
  411. var ended = 0
  412. for (var i = 0; i < records.length; i++) {
  413. var s = records[i].status
  414. if (s === 'published') published++
  415. else if (s === 'draft') draft++
  416. else if (s === 'ended' || s === 'cancelled' || s === 'withdrawn') ended++
  417. }
  418. self.manageStats = { total: total, published: published, draft: draft, ended: ended }
  419. } else {
  420. self.manageActivities = []
  421. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  422. }
  423. }).catch(function() {
  424. self.manageLoading = false
  425. self.manageActivities = []
  426. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  427. })
  428. },
  429. goCreate: function() {
  430. uni.navigateTo({ url: '/pages/activity/create' })
  431. },
  432. goEdit: function(act) {
  433. uni.navigateTo({ url: '/pages/activity/create?id=' + act.id })
  434. },
  435. statusLabel: function(status) {
  436. var map = {
  437. draft: '草稿',
  438. pending: '待审核',
  439. rejected: '已驳回',
  440. published: '进行中',
  441. ended: '已结束',
  442. withdrawn: '已撤回',
  443. cancelled: '已取消'
  444. }
  445. return map[status] || status
  446. },
  447. doPublish: function(id) {
  448. var self = this
  449. uni.showModal({
  450. title: '提示',
  451. content: '确认发布此活动吗?发布后将对外可见。',
  452. success: function(res) {
  453. if (res.confirm) {
  454. uni.showLoading({ title: '发布中...' })
  455. if (self.isAdmin) {
  456. adminPublishActivity(id).then(function(r) {
  457. uni.hideLoading()
  458. if (r && r.code === 200) {
  459. uni.showToast({ title: '发布成功', icon: 'success' })
  460. self.loadManageData()
  461. } else {
  462. uni.showToast({ title: (r && r.message) || '发布失败', icon: 'none' })
  463. }
  464. }).catch(function() {
  465. uni.hideLoading()
  466. uni.showToast({ title: '发布失败', icon: 'none' })
  467. })
  468. } else {
  469. submitActivityForReview(id).then(function(r) {
  470. uni.hideLoading()
  471. if (r && r.code === 200) {
  472. uni.showToast({ title: '已提交审核', icon: 'success' })
  473. self.loadManageData()
  474. } else {
  475. uni.showToast({ title: (r && r.message) || '提交审核失败', icon: 'none' })
  476. }
  477. }).catch(function() {
  478. uni.hideLoading()
  479. uni.showToast({ title: '提交审核失败', icon: 'none' })
  480. })
  481. }
  482. }
  483. }
  484. })
  485. },
  486. doEnd: function(id) {
  487. var self = this
  488. uni.showModal({
  489. title: '提示',
  490. content: '确认结束此活动吗?结束后不再接受新参与者。',
  491. success: function(res) {
  492. if (res.confirm) {
  493. uni.showLoading({ title: '操作中...' })
  494. adminEndActivity(id).then(function(r) {
  495. uni.hideLoading()
  496. if (r && r.code === 200) {
  497. uni.showToast({ title: '已结束', icon: 'success' })
  498. self.loadManageData()
  499. } else {
  500. uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
  501. }
  502. }).catch(function() {
  503. uni.hideLoading()
  504. uni.showToast({ title: '网络异常', icon: 'none' })
  505. })
  506. }
  507. }
  508. })
  509. },
  510. doWithdraw: function(id) {
  511. var self = this
  512. uni.showModal({
  513. title: '提示',
  514. content: '确认撤回此活动吗?撤回后不再对外展示,可重新编辑。',
  515. success: function(res) {
  516. if (res.confirm) {
  517. uni.showLoading({ title: '操作中...' })
  518. adminWithdrawActivity(id).then(function(r) {
  519. uni.hideLoading()
  520. if (r && r.code === 200) {
  521. uni.showToast({ title: '已撤回', icon: 'success' })
  522. self.loadManageData()
  523. } else {
  524. uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
  525. }
  526. }).catch(function() {
  527. uni.hideLoading()
  528. uni.showToast({ title: '网络异常', icon: 'none' })
  529. })
  530. }
  531. }
  532. })
  533. },
  534. onMineFilterChange: function(value) {
  535. this.currentMineFilter = value
  536. this.minePage = 1
  537. this.myActivities = []
  538. this.hasMore = true
  539. if (this.currentTab === 'mine') {
  540. this.loadMyActivities()
  541. } else if (this.currentTab === 'history') {
  542. this.loadHistoryActivities()
  543. }
  544. },
  545. onDimensionChange: function(value) {
  546. this.currentDimension = value
  547. this.discoverPage = 1
  548. this.discoverActivities = []
  549. this.hasMore = true
  550. this.loadDiscoverActivities()
  551. },
  552. onLoadMore: function() {
  553. if (!this.hasMore) return
  554. if (this.currentTab === 'mine' && !this.mineLoading) {
  555. this.minePage++
  556. this.loadMyActivities()
  557. } else if (this.currentTab === 'discover' && !this.discoverLoading) {
  558. this.discoverPage++
  559. this.loadDiscoverActivities()
  560. } else if (this.currentTab === 'history' && !this.historyLoading) {
  561. this.historyPage++
  562. this.loadHistoryActivities()
  563. }
  564. },
  565. onRefresh: function() {
  566. var self = this
  567. this.isRefreshing = true
  568. if (this.currentTab === 'mine') {
  569. this.loadMyActivities(true).finally(function() {
  570. self.isRefreshing = false
  571. })
  572. } else if (this.currentTab === 'discover') {
  573. this.loadDiscoverActivities(true).finally(function() {
  574. self.isRefreshing = false
  575. })
  576. } else if (this.currentTab === 'history') {
  577. this.loadHistoryActivities(true).finally(function() {
  578. self.isRefreshing = false
  579. })
  580. } else {
  581. this.isRefreshing = false
  582. }
  583. },
  584. loadMyActivities: function(refresh) {
  585. var self = this
  586. if (refresh) {
  587. this.minePage = 1
  588. this.myActivities = []
  589. }
  590. this.mineLoading = true
  591. var memberId = uni.getStorageSync('currentChildId')
  592. if (!memberId) {
  593. this.mineLoading = false
  594. return
  595. }
  596. var params = {
  597. memberId: memberId,
  598. page: this.minePage,
  599. size: this.pageSize
  600. }
  601. if (this.currentMineFilter && this.currentMineFilter !== 'upcoming') {
  602. params.status = this.currentMineFilter
  603. }
  604. getMyActivityRegistrations(params).then(function(res) {
  605. self.mineLoading = false
  606. if (res && res.code === 200 && res.data) {
  607. var records = res.data.records || []
  608. if (self.currentMineFilter === 'upcoming') {
  609. var now = new Date()
  610. var filtered = []
  611. for (var i = 0; i < records.length; i++) {
  612. var act = records[i]
  613. if (act.startTime) {
  614. var startTime = parseDate(act.startTime)
  615. if (!startTime) continue
  616. if (startTime > now && act.status === 'approved') {
  617. filtered.push(act)
  618. }
  619. }
  620. }
  621. records = filtered
  622. }
  623. for (var di = 0; di < records.length; di++) {
  624. self.decorateActivity(records[di])
  625. }
  626. if (refresh) {
  627. self.myActivities = records
  628. } else {
  629. self.myActivities = self.myActivities.concat(records)
  630. }
  631. self.hasMore = records.length >= self.pageSize
  632. }
  633. }).catch(function() {
  634. self.mineLoading = false
  635. })
  636. },
  637. loadDiscoverActivities: function(refresh) {
  638. var self = this
  639. if (refresh) {
  640. this.discoverPage = 1
  641. this.discoverActivities = []
  642. }
  643. this.discoverLoading = true
  644. var params = {
  645. page: this.discoverPage,
  646. size: this.pageSize
  647. }
  648. if (this.currentDimension) {
  649. params.dimensionCode = this.currentDimension
  650. }
  651. getActivityList(params).then(function(res) {
  652. self.discoverLoading = false
  653. if (res && res.code === 200 && res.data) {
  654. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  655. if (refresh) {
  656. self.discoverActivities = list
  657. } else {
  658. self.discoverActivities = self.discoverActivities.concat(list)
  659. }
  660. self.hasMore = list.length >= self.pageSize
  661. }
  662. }).catch(function() {
  663. self.discoverLoading = false
  664. })
  665. },
  666. loadHistoryActivities: function(refresh) {
  667. var self = this
  668. if (refresh) {
  669. this.historyPage = 1
  670. this.historyActivities = []
  671. }
  672. this.historyLoading = true
  673. var memberId = uni.getStorageSync('currentChildId')
  674. if (!memberId) {
  675. this.historyLoading = false
  676. return
  677. }
  678. var params = {
  679. memberId: memberId,
  680. page: this.historyPage,
  681. size: this.pageSize
  682. }
  683. getMyActivityRegistrations(params).then(function(res) {
  684. self.historyLoading = false
  685. if (res && res.code === 200 && res.data) {
  686. var records = res.data.records || []
  687. var now = new Date()
  688. var ended = []
  689. for (var i = 0; i < records.length; i++) {
  690. var act = records[i]
  691. if (act.endTime) {
  692. var endTime = parseDate(act.endTime)
  693. if ((endTime && endTime < now) || act.status === 'cancelled' || act.status === 'rejected') {
  694. ended.push(act)
  695. }
  696. } else {
  697. ended.push(act)
  698. }
  699. }
  700. if (refresh) {
  701. self.historyActivities = ended
  702. } else {
  703. self.historyActivities = self.historyActivities.concat(ended)
  704. }
  705. self.hasMore = records.length >= self.pageSize
  706. }
  707. }).catch(function() {
  708. self.historyLoading = false
  709. })
  710. },
  711. goDetail: function(act) {
  712. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + act.id })
  713. },
  714. switchToDiscover: function() {
  715. this.currentTab = 'discover'
  716. this.loadData()
  717. },
  718. formatPrice: function(price) {
  719. return (price / 100).toFixed(2)
  720. },
  721. hasFee: function(act) {
  722. return (act.childFee > 0) || (act.childMemberFee > 0) || (act.parentFee > 0) || (act.parentMemberFee > 0)
  723. },
  724. minFee: function(act) {
  725. var fees = [act.childFee, act.childMemberFee, act.parentFee, act.parentMemberFee]
  726. var min = 0
  727. for (var i = 0; i < fees.length; i++) {
  728. if (fees[i] > 0 && (min === 0 || fees[i] < min)) min = fees[i]
  729. }
  730. return this.formatPrice(min)
  731. },
  732. decorateActivity: function(act) {
  733. if (act.status) {
  734. act._cls = act.status
  735. var map = { pending: '待审核', approved: '报名成功', rejected: '已拒绝', cancelled: '已取消', checked_in: '已签到' }
  736. act._txt = map[act.status] || act.status
  737. } else {
  738. if (act.endTime) {
  739. var endTime = parseDate(act.endTime)
  740. if (endTime && endTime < new Date()) {
  741. act._cls = 'ended'
  742. act._txt = '已结束'
  743. return act
  744. }
  745. }
  746. act._cls = 'upcoming'
  747. act._txt = '待开始'
  748. }
  749. return act
  750. },
  751. onCheckin: function(act) {
  752. var self = this
  753. var memberId = uni.getStorageSync('currentChildId')
  754. if (!memberId) {
  755. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  756. return
  757. }
  758. activityCheckin({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  759. if (res && res.code === 200) {
  760. uni.showToast({ title: '签到成功', icon: 'success' })
  761. self.loadMyActivities(true)
  762. } else {
  763. uni.showToast({ title: (res && res.message) || '签到失败', icon: 'none' })
  764. }
  765. }).catch(function() {
  766. uni.showToast({ title: '网络异常', icon: 'none' })
  767. })
  768. },
  769. onCancel: function(act) {
  770. var self = this
  771. uni.showModal({
  772. title: '提示',
  773. content: '确定要取消报名吗?',
  774. success: function(res) {
  775. if (res.confirm) {
  776. var memberId = uni.getStorageSync('currentChildId')
  777. if (!memberId) {
  778. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  779. return
  780. }
  781. cancelActivityRegistration({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  782. if (res && res.code === 200) {
  783. uni.showToast({ title: '已取消报名', icon: 'success' })
  784. self.loadMyActivities(true)
  785. } else {
  786. uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
  787. }
  788. }).catch(function() {
  789. uni.showToast({ title: '网络异常', icon: 'none' })
  790. })
  791. }
  792. }
  793. })
  794. }
  795. }
  796. }
  797. </script>
  798. <style scoped>
  799. .activity-container {
  800. min-height: 100vh;
  801. background: #F5F5F5;
  802. display: flex;
  803. flex-direction: column;
  804. }
  805. .tab-bar {
  806. background: #fff;
  807. display: flex;
  808. flex-direction: row;
  809. border-bottom: 1rpx solid #eee;
  810. }
  811. .tab-item {
  812. flex: 1;
  813. padding: 24rpx 0;
  814. text-align: center;
  815. border-bottom: 4rpx solid transparent;
  816. }
  817. .tab-item.active {
  818. border-bottom-color: #F97316;
  819. }
  820. .tab-label {
  821. font-size: 28rpx;
  822. color: #666;
  823. }
  824. .tab-item.active .tab-label {
  825. color: #F97316;
  826. font-weight: 600;
  827. }
  828. .content-scroll {
  829. flex: 1;
  830. height: calc(100vh - 200rpx);
  831. }
  832. .filter-scroll {
  833. padding: 20rpx 24rpx;
  834. background: #fff;
  835. }
  836. .filter-chips {
  837. display: flex;
  838. flex-direction: row;
  839. gap: 16rpx;
  840. }
  841. .filter-chip {
  842. padding: 12rpx 24rpx;
  843. border-radius: 16px;
  844. background: #fff;
  845. border: 1rpx solid #ddd;
  846. flex-shrink: 0;
  847. }
  848. .filter-chip.active {
  849. background: #FFF7ED;
  850. border-color: #F97316;
  851. }
  852. .filter-label {
  853. font-size: 24rpx;
  854. color: #666;
  855. }
  856. .filter-chip.active .filter-label {
  857. color: #F97316;
  858. font-weight: 500;
  859. }
  860. .card-list {
  861. padding: 0 24rpx 24rpx;
  862. display: flex;
  863. flex-direction: column;
  864. gap: 20rpx;
  865. }
  866. .activity-card {
  867. background: #fff;
  868. border-radius: 12rpx;
  869. padding: 20rpx;
  870. display: flex;
  871. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  872. }
  873. .card-cover {
  874. width: 144rpx;
  875. height: 144rpx;
  876. border-radius: 8rpx;
  877. flex-shrink: 0;
  878. background: #f0f0f0;
  879. }
  880. .card-info {
  881. flex: 1;
  882. margin-left: 20rpx;
  883. display: flex;
  884. flex-direction: column;
  885. }
  886. .card-title {
  887. font-size: calc(28rpx * var(--font-scale, 1));
  888. font-weight: 600;
  889. color: #333;
  890. line-height: 1.4;
  891. overflow: hidden;
  892. text-overflow: ellipsis;
  893. white-space: nowrap;
  894. }
  895. .card-meta {
  896. font-size: 24rpx;
  897. color: #999;
  898. margin-top: 8rpx;
  899. }
  900. .card-bottom {
  901. display: flex;
  902. flex-direction: row;
  903. align-items: center;
  904. justify-content: space-between;
  905. margin-top: auto;
  906. padding-top: 12rpx;
  907. }
  908. .card-status {
  909. font-size: 22rpx;
  910. padding: 4rpx 12rpx;
  911. border-radius: 6rpx;
  912. }
  913. .status-pending {
  914. background: #FFF7ED;
  915. color: #F97316;
  916. }
  917. .status-approved {
  918. background: #F0FDF4;
  919. color: #22C55E;
  920. }
  921. .status-rejected {
  922. background: #FEF2F2;
  923. color: #EF4444;
  924. }
  925. .status-cancelled {
  926. background: #F5F5F5;
  927. color: #999;
  928. }
  929. .status-checked_in {
  930. background: #DBEAFE;
  931. color: #3B82F6;
  932. }
  933. .status-upcoming {
  934. background: #FFF7ED;
  935. color: #F97316;
  936. }
  937. .status-ended {
  938. background: #F5F5F5;
  939. color: #999;
  940. }
  941. .status-published {
  942. background: #F0FDF4;
  943. color: #22C55E;
  944. }
  945. .status-draft {
  946. background: #FFF7ED;
  947. color: #F97316;
  948. }
  949. .card-price {
  950. font-size: 28rpx;
  951. color: #F97316;
  952. font-weight: 600;
  953. }
  954. .card-price.free {
  955. color: #22C55E;
  956. }
  957. .card-actions {
  958. display: flex;
  959. flex-direction: row;
  960. gap: 12rpx;
  961. margin-top: 12rpx;
  962. }
  963. .btn-cancel {
  964. padding: 8rpx 20rpx;
  965. font-size: 22rpx;
  966. color: #999;
  967. background: #fff;
  968. border: 1rpx solid #ddd;
  969. border-radius: 20rpx;
  970. line-height: 1.5;
  971. }
  972. .btn-checkin {
  973. padding: 8rpx 20rpx;
  974. font-size: 22rpx;
  975. color: #fff;
  976. background: linear-gradient(135deg, #F97316, #FB923C);
  977. border: none;
  978. border-radius: 20rpx;
  979. line-height: 1.5;
  980. }
  981. .empty-state {
  982. display: flex;
  983. flex-direction: column;
  984. align-items: center;
  985. justify-content: center;
  986. padding: 120rpx 40rpx;
  987. }
  988. .empty-icon {
  989. font-size: 80rpx;
  990. margin-bottom: 20rpx;
  991. }
  992. .empty-title {
  993. font-size: 32rpx;
  994. font-weight: 600;
  995. color: #333;
  996. margin-bottom: 12rpx;
  997. }
  998. .empty-desc {
  999. font-size: 26rpx;
  1000. color: #999;
  1001. margin-bottom: 40rpx;
  1002. }
  1003. .empty-btn {
  1004. padding: 16rpx 48rpx;
  1005. font-size: 28rpx;
  1006. color: #fff;
  1007. background: linear-gradient(135deg, #F97316, #FB923C);
  1008. border: none;
  1009. border-radius: 40rpx;
  1010. }
  1011. .loading-state {
  1012. display: flex;
  1013. flex-direction: column;
  1014. align-items: center;
  1015. justify-content: center;
  1016. padding: 80rpx 40rpx;
  1017. }
  1018. .loading-spinner {
  1019. width: 60rpx;
  1020. height: 60rpx;
  1021. border: 4rpx solid #FDE68A;
  1022. border-top-color: #F97316;
  1023. border-radius: 50%;
  1024. animation: spin 0.8s linear infinite;
  1025. margin-bottom: 20rpx;
  1026. }
  1027. @keyframes spin {
  1028. to { transform: rotate(360deg); }
  1029. }
  1030. .loading-text {
  1031. font-size: 26rpx;
  1032. color: #999;
  1033. }
  1034. .load-more-tip {
  1035. text-align: center;
  1036. padding: 30rpx;
  1037. }
  1038. .load-more-text {
  1039. font-size: 24rpx;
  1040. color: #999;
  1041. }
  1042. /* Nav add button */
  1043. .nav-add-btn {
  1044. position: absolute;
  1045. right: 24rpx;
  1046. top: 50%;
  1047. transform: translateY(-50%);
  1048. width: 56rpx;
  1049. height: 56rpx;
  1050. background: rgba(255, 255, 255, 0.15);
  1051. border-radius: 50%;
  1052. display: flex;
  1053. align-items: center;
  1054. justify-content: center;
  1055. }
  1056. .nav-add-icon {
  1057. color: #fff;
  1058. font-size: 36rpx;
  1059. font-weight: 300;
  1060. line-height: 1;
  1061. }
  1062. /* Manage overview stats */
  1063. .manage-overview {
  1064. display: flex;
  1065. flex-direction: row;
  1066. padding: 24rpx;
  1067. gap: 16rpx;
  1068. background: #fff;
  1069. margin: 24rpx 24rpx 0;
  1070. border-radius: 12rpx;
  1071. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  1072. }
  1073. .manage-stat-card {
  1074. flex: 1;
  1075. display: flex;
  1076. flex-direction: column;
  1077. align-items: center;
  1078. padding: 16rpx 0;
  1079. }
  1080. .manage-stat-num {
  1081. font-size: 40rpx;
  1082. font-weight: 700;
  1083. color: #333;
  1084. line-height: 1.2;
  1085. }
  1086. .manage-published {
  1087. color: #22C55E;
  1088. }
  1089. .manage-draft {
  1090. color: #F97316;
  1091. }
  1092. .manage-ended {
  1093. color: #999;
  1094. }
  1095. .manage-stat-label {
  1096. font-size: 22rpx;
  1097. color: #999;
  1098. margin-top: 8rpx;
  1099. }
  1100. /* Quick action button */
  1101. .manage-actions {
  1102. padding: 24rpx 24rpx 0;
  1103. }
  1104. .manage-action-btn {
  1105. display: flex;
  1106. flex-direction: row;
  1107. align-items: center;
  1108. justify-content: center;
  1109. gap: 12rpx;
  1110. padding: 24rpx 0;
  1111. background: linear-gradient(135deg, #F97316, #FB923C);
  1112. border-radius: 12rpx;
  1113. margin: 0 24rpx;
  1114. }
  1115. .manage-action-icon {
  1116. color: #fff;
  1117. font-size: 36rpx;
  1118. font-weight: 300;
  1119. }
  1120. .manage-action-text {
  1121. color: #fff;
  1122. font-size: 28rpx;
  1123. font-weight: 600;
  1124. }
  1125. /* Section title */
  1126. .manage-section-title {
  1127. padding: 24rpx 24rpx 12rpx;
  1128. }
  1129. .manage-section-title text {
  1130. font-size: 28rpx;
  1131. font-weight: 600;
  1132. color: #333;
  1133. }
  1134. /* Manage action group in card */
  1135. .manage-action-group {
  1136. display: flex;
  1137. flex-direction: row;
  1138. gap: 16rpx;
  1139. align-items: center;
  1140. }
  1141. .manage-action-small {
  1142. font-size: 22rpx;
  1143. padding: 4rpx 16rpx;
  1144. border-radius: 20rpx;
  1145. background: #F97316;
  1146. color: #fff;
  1147. font-weight: 500;
  1148. }
  1149. </style>