index.vue 35 KB

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