index.vue 31 KB

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