index.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. <template>
  2. <view class="activity-container">
  3. <!-- Nav bar with title "活动中心" and admin "+" button -->
  4. <!-- Tab bar (4 tabs) -->
  5. <view class="tab-bar">
  6. <view
  7. class="tab-item"
  8. :class="{ active: currentTab === tab.key }"
  9. v-for="tab in tabs"
  10. :key="tab.key"
  11. @click="onTabChange(tab.key)"
  12. >
  13. <text class="tab-label">{{ tab.label }}</text>
  14. </view>
  15. </view>
  16. <!-- ScrollView content area -->
  17. <scroll-view
  18. class="content-scroll"
  19. scroll-y
  20. :refresher-enabled="true"
  21. :refresher-triggered="isRefreshing"
  22. @refresherrefresh="onRefresh"
  23. @scrolltolower="onLoadMore"
  24. >
  25. <!-- Tab 1: mine -->
  26. <view v-if="currentTab === 'mine'">
  27. <!-- Filter chips -->
  28. <scroll-view class="filter-scroll" scroll-x enable-flex>
  29. <view class="filter-chips">
  30. <view
  31. class="filter-chip"
  32. :class="{ active: currentMineFilter === filter.value }"
  33. v-for="filter in mineFilters"
  34. :key="filter.value"
  35. @click="onMineFilterChange(filter.value)"
  36. >
  37. <text class="filter-label">{{ filter.label }}</text>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. <!-- Activity cards -->
  42. <view class="card-list" v-if="myActivities.length > 0">
  43. <view
  44. class="activity-card"
  45. v-for="act in myActivities"
  46. :key="act.id"
  47. @click="goDetail(act)"
  48. >
  49. <image
  50. class="card-cover"
  51. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  52. mode="aspectFill"
  53. />
  54. <view class="card-info">
  55. <text class="card-title">{{ act.title }}</text>
  56. <text class="card-meta" v-if="act.registrantName">报名人:{{ act.registrantName }}</text>
  57. <text class="card-meta">{{ act.startTime }}</text>
  58. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  59. <view class="card-bottom">
  60. <text class="card-status" :class="'status-' + (act._cls || 'upcoming')">
  61. {{ act._txt || '待开始' }}
  62. </text>
  63. <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
  64. <text class="card-price free" v-else>免费</text>
  65. </view>
  66. <!-- Action buttons for approved status -->
  67. <view
  68. v-if="act.status === 'approved'"
  69. class="card-actions"
  70. >
  71. <button class="btn-cancel" @click.stop="onCancel(act)">取消报名</button>
  72. <button class="btn-checkin" @click.stop="onCheckin(act)">签到</button>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- Empty state for mine -->
  78. <view class="empty-state" v-else-if="!mineLoading">
  79. <text class="empty-icon">📋</text>
  80. <text class="empty-title">暂无报名的活动</text>
  81. <text class="empty-desc">去发现页探索精彩活动吧</text>
  82. <button class="empty-btn" @click="switchToDiscover">去发现活动</button>
  83. </view>
  84. <!-- Loading state -->
  85. <view class="loading-state" v-if="mineLoading">
  86. <view class="loading-spinner"></view>
  87. <text class="loading-text">加载中...</text>
  88. </view>
  89. <!-- Load more tip -->
  90. <view class="load-more-tip" v-if="myActivities.length > 0 && !hasMore && currentTab === 'mine'">
  91. <text class="load-more-text">没有更多了</text>
  92. </view>
  93. </view>
  94. <!-- Tab 2: discover -->
  95. <view v-if="currentTab === 'discover'">
  96. <!-- Filter chips (dimension) -->
  97. <scroll-view class="filter-scroll" scroll-x enable-flex>
  98. <view class="filter-chips">
  99. <view
  100. class="filter-chip"
  101. :class="{ active: currentDimension === filter.value }"
  102. v-for="filter in dimensionFilters"
  103. :key="filter.value"
  104. @click="onDimensionChange(filter.value)"
  105. >
  106. <text class="filter-label">{{ filter.label }}</text>
  107. </view>
  108. </view>
  109. </scroll-view>
  110. <!-- Activity cards -->
  111. <view class="card-list" v-if="discoverActivities.length > 0">
  112. <view
  113. class="activity-card"
  114. v-for="act in discoverActivities"
  115. :key="act.id"
  116. @click="goDetail(act)"
  117. >
  118. <image
  119. class="card-cover"
  120. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  121. mode="aspectFill"
  122. />
  123. <view class="card-info">
  124. <text class="card-title">{{ act.title }}</text>
  125. <text class="card-meta">{{ act.startTime }}</text>
  126. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  127. <view class="card-bottom">
  128. <text class="card-status" :class="'status-' + (act.displayStatus || 'open')">
  129. {{ act.displayLabel || '报名中' }}
  130. </text>
  131. <text class="card-price" v-if="hasFee(act)">¥{{ minFee(act) }}</text>
  132. <text class="card-price free" v-else>免费</text>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. <!-- Empty state for discover -->
  138. <view class="empty-state" v-else-if="!discoverLoading">
  139. <text class="empty-icon">🔍</text>
  140. <text class="empty-title">暂无活动</text>
  141. <text class="empty-desc">稍后再来看看吧</text>
  142. </view>
  143. <!-- Loading state -->
  144. <view class="loading-state" v-if="discoverLoading">
  145. <view class="loading-spinner"></view>
  146. <text class="loading-text">加载中...</text>
  147. </view>
  148. <!-- Load more tip -->
  149. <view class="load-more-tip" v-if="discoverActivities.length > 0 && !hasMore && currentTab === 'discover'">
  150. <text class="load-more-text">没有更多了</text>
  151. </view>
  152. </view>
  153. <!-- Tab 3: history -->
  154. <view v-if="currentTab === 'history'">
  155. <!-- Filter chips (same as mine) -->
  156. <scroll-view class="filter-scroll" scroll-x enable-flex>
  157. <view class="filter-chips">
  158. <view
  159. class="filter-chip"
  160. :class="{ active: currentMineFilter === filter.value }"
  161. v-for="filter in mineFilters"
  162. :key="filter.value"
  163. @click="onMineFilterChange(filter.value)"
  164. >
  165. <text class="filter-label">{{ filter.label }}</text>
  166. </view>
  167. </view>
  168. </scroll-view>
  169. <!-- Activity cards -->
  170. <view class="card-list" v-if="historyActivities.length > 0">
  171. <view
  172. class="activity-card"
  173. v-for="act in historyActivities"
  174. :key="act.id"
  175. @click="goDetail(act)"
  176. >
  177. <image
  178. class="card-cover"
  179. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  180. mode="aspectFill"
  181. />
  182. <view class="card-info">
  183. <text class="card-title">{{ act.title }}</text>
  184. <text class="card-meta">{{ act.startTime }}</text>
  185. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  186. <view class="card-bottom">
  187. <text class="card-status status-ended">已结束</text>
  188. <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
  189. <text class="card-price free" v-else>免费</text>
  190. </view>
  191. </view>
  192. </view>
  193. </view>
  194. <!-- Empty state for history -->
  195. <view class="empty-state" v-else-if="!historyLoading">
  196. <text class="empty-icon">📜</text>
  197. <text class="empty-title">暂无历史活动</text>
  198. <text class="empty-desc">参加过的活动会显示在这里</text>
  199. </view>
  200. <!-- Loading state -->
  201. <view class="loading-state" v-if="historyLoading">
  202. <view class="loading-spinner"></view>
  203. <text class="loading-text">加载中...</text>
  204. </view>
  205. <!-- Load more tip -->
  206. <view class="load-more-tip" v-if="historyActivities.length > 0 && !hasMore && currentTab === 'history'">
  207. <text class="load-more-text">没有更多了</text>
  208. </view>
  209. </view>
  210. <!-- Tab 4: manage (admin only) -->
  211. <view v-if="currentTab === 'manage' && isAdmin">
  212. <!-- Manage overview stats -->
  213. <view class="manage-overview">
  214. <view class="manage-stat-card">
  215. <text class="manage-stat-num">{{ manageStats.total }}</text>
  216. <text class="manage-stat-label">全部活动</text>
  217. </view>
  218. <view class="manage-stat-card">
  219. <text class="manage-stat-num manage-published">{{ manageStats.published }}</text>
  220. <text class="manage-stat-label">已发布</text>
  221. </view>
  222. <view class="manage-stat-card">
  223. <text class="manage-stat-num manage-draft">{{ manageStats.draft }}</text>
  224. <text class="manage-stat-label">草稿</text>
  225. </view>
  226. <view class="manage-stat-card">
  227. <text class="manage-stat-num manage-ended">{{ manageStats.ended }}</text>
  228. <text class="manage-stat-label">已结束</text>
  229. </view>
  230. </view>
  231. <!-- Quick actions -->
  232. <view class="manage-actions">
  233. <view class="manage-action-btn" @click="goCreate">
  234. <text class="manage-action-icon">+</text>
  235. <text class="manage-action-text">创建活动</text>
  236. </view>
  237. </view>
  238. <!-- My managed activities list -->
  239. <view class="manage-section-title">
  240. <text>我的活动管理</text>
  241. </view>
  242. <view class="card-list" v-if="manageActivities.length > 0">
  243. <view
  244. class="activity-card"
  245. v-for="act in manageActivities"
  246. :key="act.id"
  247. @click="goEdit(act)"
  248. >
  249. <image
  250. class="card-cover"
  251. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  252. mode="aspectFill"
  253. />
  254. <view class="card-info">
  255. <text class="card-title">{{ act.title }}</text>
  256. <text class="card-meta">{{ act.startTime }}</text>
  257. <view class="card-bottom">
  258. <text class="card-status" :class="'status-' + (act.status || 'draft')">
  259. {{ statusLabel(act.status) }}
  260. </text>
  261. <view class="manage-action-group">
  262. <text class="manage-action-small" v-if="act.status === 'draft'" @click.stop="doPublish(act.id)">{{ isAdmin ? '发布' : '提交审核' }}</text>
  263. <text class="manage-action-small" v-if="act.status === 'rejected'" @click.stop="doPublish(act.id)">重新提交</text>
  264. <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doEnd(act.id)">结束</text>
  265. </view>
  266. </view>
  267. </view>
  268. </view>
  269. </view>
  270. <view class="empty-state" v-else-if="!manageLoading">
  271. <text class="empty-icon">📊</text>
  272. <text class="empty-title">暂无管理的活动</text>
  273. <text class="empty-desc">点击上方「创建活动」开始</text>
  274. </view>
  275. <view class="loading-state" v-if="manageLoading">
  276. <view class="loading-spinner"></view>
  277. <text class="loading-text">加载中...</text>
  278. </view>
  279. </view>
  280. </scroll-view>
  281. </view>
  282. </template>
  283. <script>
  284. import { getActivityList, getMyActivityRegistrations, activityCheckin, cancelActivityRegistration, adminListMyActivities, adminPublishActivity, submitActivityForReview, reportAppEnter} from '@/utils/api.js'
  285. import config from '@/config.js'
  286. import { parseDate } from '../../utils/format.js'
  287. export default {
  288. computed: {
  289. isAdmin: function() {
  290. var userInfo = uni.getStorageSync('userInfo')
  291. return userInfo && (userInfo.role === 'admin' || userInfo.role === 'activity_admin' || (userInfo.roles && userInfo.roles.indexOf('activity_admin') >= 0))
  292. }
  293. },
  294. data() {
  295. return {
  296. tabs: [
  297. { key: 'mine', label: '我的活动' },
  298. { key: 'discover', label: '发现活动' },
  299. { key: 'history', label: '历史记录' },
  300. { key: 'manage', label: '管理' }
  301. ],
  302. currentTab: 'mine',
  303. mineFilters: [
  304. { label: '全部', value: '' },
  305. { label: '待开始', value: 'upcoming' },
  306. { label: '待审核', value: 'pending' },
  307. { label: '已签到', value: 'checked_in' }
  308. ],
  309. dimensionFilters: [
  310. { label: '全部', value: '' },
  311. { label: '身', value: 'body' },
  312. { label: '心', value: 'mind' },
  313. { label: '智', value: 'wisdom' },
  314. { label: '行', value: 'action' },
  315. { label: '富', value: 'wealth' }
  316. ],
  317. currentMineFilter: '',
  318. currentDimension: '',
  319. myActivities: [],
  320. discoverActivities: [],
  321. historyActivities: [],
  322. mineLoading: false,
  323. discoverLoading: false,
  324. historyLoading: false,
  325. minePage: 1,
  326. discoverPage: 1,
  327. historyPage: 1,
  328. pageSize: 10,
  329. hasMore: true,
  330. isRefreshing: false,
  331. // Manage tab data
  332. manageLoading: false,
  333. manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
  334. manageActivities: []
  335. }
  336. },
  337. onLoad: function(options) {
  338. reportAppEnter('activity');
  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>