index.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. <template>
  2. <view class="activity-container">
  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 only) -->
  211. <view v-if="currentTab === 'manage' && isAdmin">
  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. </view>
  266. </view>
  267. </view>
  268. </view>
  269. </view>
  270. <view class="empty-state" v-else-if="!manageLoading">
  271. <text class="empty-icon">📊</text>
  272. <text class="empty-title">暂无管理的活动</text>
  273. <text class="empty-desc">点击上方「创建活动」开始</text>
  274. </view>
  275. <view class="loading-state" v-if="manageLoading">
  276. <view class="loading-spinner"></view>
  277. <text class="loading-text">加载中...</text>
  278. </view>
  279. </view>
  280. </scroll-view>
  281. </view>
  282. </template>
  283. <script>
  284. import { getActivityList, getMyActivityRegistrations, activityCheckin, cancelActivityRegistration, adminListMyActivities, adminPublishActivity, submitActivityForReview } from '@/utils/api.js'
  285. import config from '@/config.js'
  286. import { parseDate } from '../../utils/format.js'
  287. export default {
  288. computed: {
  289. isAdmin: function() {
  290. var userInfo = uni.getStorageSync('userInfo')
  291. return userInfo && (userInfo.role === 'admin' || userInfo.role === 'activity_admin' || (userInfo.roles && userInfo.roles.indexOf('activity_admin') >= 0))
  292. }
  293. },
  294. data() {
  295. return {
  296. tabs: [
  297. { key: 'mine', label: '我的活动' },
  298. { key: 'discover', label: '发现活动' },
  299. { key: 'history', label: '历史记录' },
  300. { key: 'manage', label: '管理' }
  301. ],
  302. currentTab: 'mine',
  303. mineFilters: [
  304. { label: '全部', value: '' },
  305. { label: '待开始', value: 'upcoming' },
  306. { label: '待审核', value: 'pending' },
  307. { label: '已签到', value: 'checked_in' }
  308. ],
  309. dimensionFilters: [
  310. { label: '全部', value: '' },
  311. { label: '身', value: 'body' },
  312. { label: '心', value: 'mind' },
  313. { label: '智', value: 'wisdom' },
  314. { label: '行', value: 'action' },
  315. { label: '富', value: 'wealth' }
  316. ],
  317. currentMineFilter: '',
  318. currentDimension: '',
  319. myActivities: [],
  320. discoverActivities: [],
  321. historyActivities: [],
  322. mineLoading: false,
  323. discoverLoading: false,
  324. historyLoading: false,
  325. minePage: 1,
  326. discoverPage: 1,
  327. historyPage: 1,
  328. pageSize: 10,
  329. hasMore: true,
  330. isRefreshing: false,
  331. // Manage tab data
  332. manageLoading: false,
  333. manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
  334. manageActivities: []
  335. }
  336. },
  337. onLoad: function(options) {
  338. if (options && options.tab) {
  339. this.currentTab = options.tab
  340. this.loadData()
  341. }
  342. },
  343. onShow: function() {
  344. if (this.currentTab === 'mine') {
  345. this.loadMyActivities(true)
  346. } else if (this.currentTab === 'manage') {
  347. this.loadManageData()
  348. }
  349. },
  350. methods: {
  351. getImageUrl: function(path) {
  352. if (!path) return ''
  353. if (path.indexOf('http://') === 0 || path.indexOf('https://') === 0) return path
  354. return config.API_BASE_URL + path
  355. },
  356. onTabChange: function(key) {
  357. this.currentTab = key
  358. this.hasMore = true
  359. if (key === 'mine') {
  360. this.minePage = 1
  361. this.myActivities = []
  362. } else if (key === 'discover') {
  363. this.discoverPage = 1
  364. this.discoverActivities = []
  365. } else if (key === 'history') {
  366. this.historyPage = 1
  367. this.historyActivities = []
  368. } else if (key === 'manage') {
  369. this.loadManageData()
  370. }
  371. this.loadData()
  372. },
  373. loadData: function() {
  374. if (this.currentTab === 'mine') {
  375. this.loadMyActivities()
  376. } else if (this.currentTab === 'discover') {
  377. this.loadDiscoverActivities()
  378. } else if (this.currentTab === 'history') {
  379. this.loadHistoryActivities()
  380. }
  381. },
  382. loadManageData: function() {
  383. var self = this
  384. this.manageLoading = true
  385. adminListMyActivities({ page: 1, size: 100 }).then(function(res) {
  386. self.manageLoading = false
  387. if (res && res.code === 200 && res.data) {
  388. var records = res.data.records || []
  389. self.manageActivities = records.slice(0, 20)
  390. var total = records.length
  391. var published = 0
  392. var draft = 0
  393. var ended = 0
  394. for (var i = 0; i < records.length; i++) {
  395. var s = records[i].status
  396. if (s === 'published') published++
  397. else if (s === 'draft') draft++
  398. else if (s === 'ended' || s === 'cancelled') ended++
  399. }
  400. self.manageStats = { total: total, published: published, draft: draft, ended: ended }
  401. } else {
  402. self.manageActivities = []
  403. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  404. }
  405. }).catch(function() {
  406. self.manageLoading = false
  407. self.manageActivities = []
  408. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  409. })
  410. },
  411. goCreate: function() {
  412. uni.navigateTo({ url: '/pages/activity/create' })
  413. },
  414. goEdit: function(act) {
  415. uni.navigateTo({ url: '/pages/activity/create?id=' + act.id })
  416. },
  417. statusLabel: function(status) {
  418. var map = {
  419. draft: '草稿',
  420. pending: '待审核',
  421. rejected: '已驳回',
  422. published: '进行中',
  423. ended: '已结束',
  424. cancelled: '已取消'
  425. }
  426. return map[status] || status
  427. },
  428. doPublish: function(id) {
  429. var self = this
  430. uni.showModal({
  431. title: '提示',
  432. content: '确认发布此活动吗?发布后将对外可见。',
  433. success: function(res) {
  434. if (res.confirm) {
  435. uni.showLoading({ title: '发布中...' })
  436. if (self.isAdmin) {
  437. adminPublishActivity(id).then(function(r) {
  438. uni.hideLoading()
  439. if (r && r.code === 200) {
  440. uni.showToast({ title: '发布成功', icon: 'success' })
  441. self.loadManageData()
  442. } else {
  443. uni.showToast({ title: (r && r.message) || '发布失败', icon: 'none' })
  444. }
  445. }).catch(function() {
  446. uni.hideLoading()
  447. uni.showToast({ title: '发布失败', icon: 'none' })
  448. })
  449. } else {
  450. submitActivityForReview(id).then(function(r) {
  451. uni.hideLoading()
  452. if (r && r.code === 200) {
  453. uni.showToast({ title: '已提交审核', icon: 'success' })
  454. self.loadManageData()
  455. } else {
  456. uni.showToast({ title: (r && r.message) || '提交审核失败', icon: 'none' })
  457. }
  458. }).catch(function() {
  459. uni.hideLoading()
  460. uni.showToast({ title: '提交审核失败', icon: 'none' })
  461. })
  462. }
  463. }
  464. }
  465. })
  466. },
  467. doEnd: function(id) {
  468. var self = this
  469. uni.showModal({
  470. title: '提示',
  471. content: '确认结束此活动吗?结束后不再接受新参与者。',
  472. success: function(res) {
  473. if (res.confirm) {
  474. uni.showLoading({ title: '操作中...' })
  475. setTimeout(function() {
  476. uni.hideLoading()
  477. uni.showToast({ title: '操作成功', icon: 'success' })
  478. self.loadManageData()
  479. }, 500)
  480. }
  481. }
  482. })
  483. },
  484. onMineFilterChange: function(value) {
  485. this.currentMineFilter = value
  486. this.minePage = 1
  487. this.myActivities = []
  488. this.hasMore = true
  489. if (this.currentTab === 'mine') {
  490. this.loadMyActivities()
  491. } else if (this.currentTab === 'history') {
  492. this.loadHistoryActivities()
  493. }
  494. },
  495. onDimensionChange: function(value) {
  496. this.currentDimension = value
  497. this.discoverPage = 1
  498. this.discoverActivities = []
  499. this.hasMore = true
  500. this.loadDiscoverActivities()
  501. },
  502. onLoadMore: function() {
  503. if (!this.hasMore) return
  504. if (this.currentTab === 'mine' && !this.mineLoading) {
  505. this.minePage++
  506. this.loadMyActivities()
  507. } else if (this.currentTab === 'discover' && !this.discoverLoading) {
  508. this.discoverPage++
  509. this.loadDiscoverActivities()
  510. } else if (this.currentTab === 'history' && !this.historyLoading) {
  511. this.historyPage++
  512. this.loadHistoryActivities()
  513. }
  514. },
  515. onRefresh: function() {
  516. var self = this
  517. this.isRefreshing = true
  518. if (this.currentTab === 'mine') {
  519. this.loadMyActivities(true).finally(function() {
  520. self.isRefreshing = false
  521. })
  522. } else if (this.currentTab === 'discover') {
  523. this.loadDiscoverActivities(true).finally(function() {
  524. self.isRefreshing = false
  525. })
  526. } else if (this.currentTab === 'history') {
  527. this.loadHistoryActivities(true).finally(function() {
  528. self.isRefreshing = false
  529. })
  530. } else {
  531. this.isRefreshing = false
  532. }
  533. },
  534. loadMyActivities: function(refresh) {
  535. var self = this
  536. if (refresh) {
  537. this.minePage = 1
  538. this.myActivities = []
  539. }
  540. this.mineLoading = true
  541. var memberId = uni.getStorageSync('currentChildId')
  542. if (!memberId) {
  543. this.mineLoading = false
  544. return
  545. }
  546. var params = {
  547. memberId: memberId,
  548. page: this.minePage,
  549. size: this.pageSize
  550. }
  551. if (this.currentMineFilter && this.currentMineFilter !== 'upcoming') {
  552. params.status = this.currentMineFilter
  553. }
  554. getMyActivityRegistrations(params).then(function(res) {
  555. self.mineLoading = false
  556. if (res && res.code === 200 && res.data) {
  557. var records = res.data.records || []
  558. if (self.currentMineFilter === 'upcoming') {
  559. var now = new Date()
  560. var filtered = []
  561. for (var i = 0; i < records.length; i++) {
  562. var act = records[i]
  563. if (act.startTime) {
  564. var startTime = parseDate(act.startTime)
  565. if (!startTime) continue
  566. if (startTime > now && act.status === 'approved') {
  567. filtered.push(act)
  568. }
  569. }
  570. }
  571. records = filtered
  572. }
  573. for (var di = 0; di < records.length; di++) {
  574. self.decorateActivity(records[di])
  575. }
  576. if (refresh) {
  577. self.myActivities = records
  578. } else {
  579. self.myActivities = self.myActivities.concat(records)
  580. }
  581. self.hasMore = records.length >= self.pageSize
  582. }
  583. }).catch(function() {
  584. self.mineLoading = false
  585. })
  586. },
  587. loadDiscoverActivities: function(refresh) {
  588. var self = this
  589. if (refresh) {
  590. this.discoverPage = 1
  591. this.discoverActivities = []
  592. }
  593. this.discoverLoading = true
  594. var params = {
  595. page: this.discoverPage,
  596. size: this.pageSize
  597. }
  598. if (this.currentDimension) {
  599. params.dimensionCode = this.currentDimension
  600. }
  601. getActivityList(params).then(function(res) {
  602. self.discoverLoading = false
  603. if (res && res.code === 200 && res.data) {
  604. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  605. if (refresh) {
  606. self.discoverActivities = list
  607. } else {
  608. self.discoverActivities = self.discoverActivities.concat(list)
  609. }
  610. self.hasMore = list.length >= self.pageSize
  611. }
  612. }).catch(function() {
  613. self.discoverLoading = false
  614. })
  615. },
  616. loadHistoryActivities: function(refresh) {
  617. var self = this
  618. if (refresh) {
  619. this.historyPage = 1
  620. this.historyActivities = []
  621. }
  622. this.historyLoading = true
  623. var memberId = uni.getStorageSync('currentChildId')
  624. if (!memberId) {
  625. this.historyLoading = false
  626. return
  627. }
  628. var params = {
  629. memberId: memberId,
  630. page: this.historyPage,
  631. size: this.pageSize
  632. }
  633. getMyActivityRegistrations(params).then(function(res) {
  634. self.historyLoading = false
  635. if (res && res.code === 200 && res.data) {
  636. var records = res.data.records || []
  637. var now = new Date()
  638. var ended = []
  639. for (var i = 0; i < records.length; i++) {
  640. var act = records[i]
  641. if (act.endTime) {
  642. var endTime = parseDate(act.endTime)
  643. if ((endTime && endTime < now) || act.status === 'cancelled' || act.status === 'rejected') {
  644. ended.push(act)
  645. }
  646. } else {
  647. ended.push(act)
  648. }
  649. }
  650. if (refresh) {
  651. self.historyActivities = ended
  652. } else {
  653. self.historyActivities = self.historyActivities.concat(ended)
  654. }
  655. self.hasMore = records.length >= self.pageSize
  656. }
  657. }).catch(function() {
  658. self.historyLoading = false
  659. })
  660. },
  661. goDetail: function(act) {
  662. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + act.id })
  663. },
  664. switchToDiscover: function() {
  665. this.currentTab = 'discover'
  666. this.loadData()
  667. },
  668. formatPrice: function(price) {
  669. return (price / 100).toFixed(2)
  670. },
  671. hasFee: function(act) {
  672. return (act.childFee > 0) || (act.childMemberFee > 0) || (act.parentFee > 0) || (act.parentMemberFee > 0)
  673. },
  674. minFee: function(act) {
  675. var fees = [act.childFee, act.childMemberFee, act.parentFee, act.parentMemberFee]
  676. var min = 0
  677. for (var i = 0; i < fees.length; i++) {
  678. if (fees[i] > 0 && (min === 0 || fees[i] < min)) min = fees[i]
  679. }
  680. return this.formatPrice(min)
  681. },
  682. decorateActivity: function(act) {
  683. if (act.status) {
  684. act._cls = act.status
  685. var map = { pending: '待审核', approved: '报名成功', rejected: '已拒绝', cancelled: '已取消', checked_in: '已签到' }
  686. act._txt = map[act.status] || act.status
  687. } else {
  688. if (act.endTime) {
  689. var endTime = parseDate(act.endTime)
  690. if (endTime && endTime < new Date()) {
  691. act._cls = 'ended'
  692. act._txt = '已结束'
  693. return act
  694. }
  695. }
  696. act._cls = 'upcoming'
  697. act._txt = '待开始'
  698. }
  699. return act
  700. },
  701. onCheckin: function(act) {
  702. var self = this
  703. var memberId = uni.getStorageSync('currentChildId')
  704. if (!memberId) {
  705. uni.showToast({ title: '请先选择孩子身份', icon: 'none' })
  706. return
  707. }
  708. activityCheckin({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  709. if (res && res.code === 200) {
  710. uni.showToast({ title: '签到成功', icon: 'success' })
  711. self.loadMyActivities(true)
  712. } else {
  713. uni.showToast({ title: (res && res.message) || '签到失败', icon: 'none' })
  714. }
  715. }).catch(function() {
  716. uni.showToast({ title: '网络异常', icon: 'none' })
  717. })
  718. },
  719. onCancel: function(act) {
  720. var self = this
  721. uni.showModal({
  722. title: '提示',
  723. content: '确定要取消报名吗?',
  724. success: function(res) {
  725. if (res.confirm) {
  726. var memberId = uni.getStorageSync('currentChildId')
  727. if (!memberId) {
  728. uni.showToast({ title: '请先选择孩子身份', icon: 'none' })
  729. return
  730. }
  731. cancelActivityRegistration({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  732. if (res && res.code === 200) {
  733. uni.showToast({ title: '已取消报名', icon: 'success' })
  734. self.loadMyActivities(true)
  735. } else {
  736. uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
  737. }
  738. }).catch(function() {
  739. uni.showToast({ title: '网络异常', icon: 'none' })
  740. })
  741. }
  742. }
  743. })
  744. }
  745. }
  746. }
  747. </script>
  748. <style scoped>
  749. .activity-container {
  750. min-height: 100vh;
  751. background: #F5F5F5;
  752. display: flex;
  753. flex-direction: column;
  754. }
  755. .tab-bar {
  756. background: #fff;
  757. display: flex;
  758. flex-direction: row;
  759. border-bottom: 1rpx solid #eee;
  760. }
  761. .tab-item {
  762. flex: 1;
  763. padding: 24rpx 0;
  764. text-align: center;
  765. border-bottom: 4rpx solid transparent;
  766. }
  767. .tab-item.active {
  768. border-bottom-color: #F97316;
  769. }
  770. .tab-label {
  771. font-size: 28rpx;
  772. color: #666;
  773. }
  774. .tab-item.active .tab-label {
  775. color: #F97316;
  776. font-weight: 600;
  777. }
  778. .content-scroll {
  779. flex: 1;
  780. height: calc(100vh - 200rpx);
  781. }
  782. .filter-scroll {
  783. padding: 20rpx 24rpx;
  784. background: #fff;
  785. }
  786. .filter-chips {
  787. display: flex;
  788. flex-direction: row;
  789. gap: 16rpx;
  790. }
  791. .filter-chip {
  792. padding: 12rpx 24rpx;
  793. border-radius: 16px;
  794. background: #fff;
  795. border: 1rpx solid #ddd;
  796. flex-shrink: 0;
  797. }
  798. .filter-chip.active {
  799. background: #FFF7ED;
  800. border-color: #F97316;
  801. }
  802. .filter-label {
  803. font-size: 24rpx;
  804. color: #666;
  805. }
  806. .filter-chip.active .filter-label {
  807. color: #F97316;
  808. font-weight: 500;
  809. }
  810. .card-list {
  811. padding: 0 24rpx 24rpx;
  812. display: flex;
  813. flex-direction: column;
  814. gap: 20rpx;
  815. }
  816. .activity-card {
  817. background: #fff;
  818. border-radius: 12rpx;
  819. padding: 20rpx;
  820. display: flex;
  821. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  822. }
  823. .card-cover {
  824. width: 144rpx;
  825. height: 144rpx;
  826. border-radius: 8rpx;
  827. flex-shrink: 0;
  828. background: #f0f0f0;
  829. }
  830. .card-info {
  831. flex: 1;
  832. margin-left: 20rpx;
  833. display: flex;
  834. flex-direction: column;
  835. }
  836. .card-title {
  837. font-size: 28rpx;
  838. font-weight: 600;
  839. color: #333;
  840. line-height: 1.4;
  841. overflow: hidden;
  842. text-overflow: ellipsis;
  843. white-space: nowrap;
  844. }
  845. .card-meta {
  846. font-size: 24rpx;
  847. color: #999;
  848. margin-top: 8rpx;
  849. }
  850. .card-bottom {
  851. display: flex;
  852. flex-direction: row;
  853. align-items: center;
  854. justify-content: space-between;
  855. margin-top: auto;
  856. padding-top: 12rpx;
  857. }
  858. .card-status {
  859. font-size: 22rpx;
  860. padding: 4rpx 12rpx;
  861. border-radius: 6rpx;
  862. }
  863. .status-pending {
  864. background: #FFF7ED;
  865. color: #F97316;
  866. }
  867. .status-approved {
  868. background: #F0FDF4;
  869. color: #22C55E;
  870. }
  871. .status-rejected {
  872. background: #FEF2F2;
  873. color: #EF4444;
  874. }
  875. .status-cancelled {
  876. background: #F5F5F5;
  877. color: #999;
  878. }
  879. .status-checked_in {
  880. background: #DBEAFE;
  881. color: #3B82F6;
  882. }
  883. .status-upcoming {
  884. background: #FFF7ED;
  885. color: #F97316;
  886. }
  887. .status-ended {
  888. background: #F5F5F5;
  889. color: #999;
  890. }
  891. .status-published {
  892. background: #F0FDF4;
  893. color: #22C55E;
  894. }
  895. .status-draft {
  896. background: #FFF7ED;
  897. color: #F97316;
  898. }
  899. .card-price {
  900. font-size: 28rpx;
  901. color: #F97316;
  902. font-weight: 600;
  903. }
  904. .card-price.free {
  905. color: #22C55E;
  906. }
  907. .card-actions {
  908. display: flex;
  909. flex-direction: row;
  910. gap: 12rpx;
  911. margin-top: 12rpx;
  912. }
  913. .btn-cancel {
  914. padding: 8rpx 20rpx;
  915. font-size: 22rpx;
  916. color: #999;
  917. background: #fff;
  918. border: 1rpx solid #ddd;
  919. border-radius: 20rpx;
  920. line-height: 1.5;
  921. }
  922. .btn-checkin {
  923. padding: 8rpx 20rpx;
  924. font-size: 22rpx;
  925. color: #fff;
  926. background: linear-gradient(135deg, #F97316, #FB923C);
  927. border: none;
  928. border-radius: 20rpx;
  929. line-height: 1.5;
  930. }
  931. .empty-state {
  932. display: flex;
  933. flex-direction: column;
  934. align-items: center;
  935. justify-content: center;
  936. padding: 120rpx 40rpx;
  937. }
  938. .empty-icon {
  939. font-size: 80rpx;
  940. margin-bottom: 20rpx;
  941. }
  942. .empty-title {
  943. font-size: 32rpx;
  944. font-weight: 600;
  945. color: #333;
  946. margin-bottom: 12rpx;
  947. }
  948. .empty-desc {
  949. font-size: 26rpx;
  950. color: #999;
  951. margin-bottom: 40rpx;
  952. }
  953. .empty-btn {
  954. padding: 16rpx 48rpx;
  955. font-size: 28rpx;
  956. color: #fff;
  957. background: linear-gradient(135deg, #F97316, #FB923C);
  958. border: none;
  959. border-radius: 40rpx;
  960. }
  961. .loading-state {
  962. display: flex;
  963. flex-direction: column;
  964. align-items: center;
  965. justify-content: center;
  966. padding: 80rpx 40rpx;
  967. }
  968. .loading-spinner {
  969. width: 60rpx;
  970. height: 60rpx;
  971. border: 4rpx solid #FDE68A;
  972. border-top-color: #F97316;
  973. border-radius: 50%;
  974. animation: spin 0.8s linear infinite;
  975. margin-bottom: 20rpx;
  976. }
  977. @keyframes spin {
  978. to { transform: rotate(360deg); }
  979. }
  980. .loading-text {
  981. font-size: 26rpx;
  982. color: #999;
  983. }
  984. .load-more-tip {
  985. text-align: center;
  986. padding: 30rpx;
  987. }
  988. .load-more-text {
  989. font-size: 24rpx;
  990. color: #999;
  991. }
  992. /* Nav add button */
  993. .nav-add-btn {
  994. position: absolute;
  995. right: 24rpx;
  996. top: 50%;
  997. transform: translateY(-50%);
  998. width: 56rpx;
  999. height: 56rpx;
  1000. background: rgba(255, 255, 255, 0.15);
  1001. border-radius: 50%;
  1002. display: flex;
  1003. align-items: center;
  1004. justify-content: center;
  1005. }
  1006. .nav-add-icon {
  1007. color: #fff;
  1008. font-size: 36rpx;
  1009. font-weight: 300;
  1010. line-height: 1;
  1011. }
  1012. /* Manage overview stats */
  1013. .manage-overview {
  1014. display: flex;
  1015. flex-direction: row;
  1016. padding: 24rpx;
  1017. gap: 16rpx;
  1018. background: #fff;
  1019. margin: 24rpx 24rpx 0;
  1020. border-radius: 12rpx;
  1021. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  1022. }
  1023. .manage-stat-card {
  1024. flex: 1;
  1025. display: flex;
  1026. flex-direction: column;
  1027. align-items: center;
  1028. padding: 16rpx 0;
  1029. }
  1030. .manage-stat-num {
  1031. font-size: 40rpx;
  1032. font-weight: 700;
  1033. color: #333;
  1034. line-height: 1.2;
  1035. }
  1036. .manage-published {
  1037. color: #22C55E;
  1038. }
  1039. .manage-draft {
  1040. color: #F97316;
  1041. }
  1042. .manage-ended {
  1043. color: #999;
  1044. }
  1045. .manage-stat-label {
  1046. font-size: 22rpx;
  1047. color: #999;
  1048. margin-top: 8rpx;
  1049. }
  1050. /* Quick action button */
  1051. .manage-actions {
  1052. padding: 24rpx 24rpx 0;
  1053. }
  1054. .manage-action-btn {
  1055. display: flex;
  1056. flex-direction: row;
  1057. align-items: center;
  1058. justify-content: center;
  1059. gap: 12rpx;
  1060. padding: 24rpx 0;
  1061. background: linear-gradient(135deg, #F97316, #FB923C);
  1062. border-radius: 12rpx;
  1063. margin: 0 24rpx;
  1064. }
  1065. .manage-action-icon {
  1066. color: #fff;
  1067. font-size: 36rpx;
  1068. font-weight: 300;
  1069. }
  1070. .manage-action-text {
  1071. color: #fff;
  1072. font-size: 28rpx;
  1073. font-weight: 600;
  1074. }
  1075. /* Section title */
  1076. .manage-section-title {
  1077. padding: 24rpx 24rpx 12rpx;
  1078. }
  1079. .manage-section-title text {
  1080. font-size: 28rpx;
  1081. font-weight: 600;
  1082. color: #333;
  1083. }
  1084. /* Manage action group in card */
  1085. .manage-action-group {
  1086. display: flex;
  1087. flex-direction: row;
  1088. gap: 16rpx;
  1089. align-items: center;
  1090. }
  1091. .manage-action-small {
  1092. font-size: 22rpx;
  1093. padding: 4rpx 16rpx;
  1094. border-radius: 20rpx;
  1095. background: #F97316;
  1096. color: #fff;
  1097. font-weight: 500;
  1098. }
  1099. </style>