index.vue 33 KB

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