index.vue 33 KB

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