index.vue 33 KB

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