index.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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 or activity_provider) -->
  211. <view v-if="currentTab === 'manage' && (isAdmin || isActivityProvider)">
  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. isActivityProvider: function() {
  294. var userInfo = uni.getStorageSync('userInfo')
  295. return userInfo && userInfo.vendorType === 'activity_provider' && userInfo.activityProviderStatus === 'approved'
  296. }
  297. },
  298. data() {
  299. return {
  300. tabs: [
  301. { key: 'mine', label: '我的活动' },
  302. { key: 'discover', label: '发现活动' },
  303. { key: 'history', label: '历史记录' },
  304. { key: 'manage', label: '管理' }
  305. ],
  306. currentTab: 'mine',
  307. mineFilters: [
  308. { label: '全部', value: '' },
  309. { label: '待开始', value: 'upcoming' },
  310. { label: '待审核', value: 'pending' },
  311. { label: '已签到', value: 'checked_in' }
  312. ],
  313. dimensionFilters: [
  314. { label: '全部', value: '' },
  315. { label: '身', value: 'body' },
  316. { label: '心', value: 'mind' },
  317. { label: '智', value: 'wisdom' },
  318. { label: '行', value: 'action' },
  319. { label: '富', value: 'wealth' }
  320. ],
  321. currentMineFilter: '',
  322. currentDimension: '',
  323. myActivities: [],
  324. discoverActivities: [],
  325. historyActivities: [],
  326. mineLoading: false,
  327. discoverLoading: false,
  328. historyLoading: false,
  329. minePage: 1,
  330. discoverPage: 1,
  331. historyPage: 1,
  332. pageSize: 10,
  333. hasMore: true,
  334. isRefreshing: false,
  335. // Manage tab data
  336. manageLoading: false,
  337. manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
  338. manageActivities: []
  339. }
  340. },
  341. onLoad: function(options) {
  342. reportAppEnter('activity');
  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 = parseDate(act.startTime)
  570. if (!startTime) continue
  571. if (startTime > now && act.status === 'approved') {
  572. filtered.push(act)
  573. }
  574. }
  575. }
  576. records = filtered
  577. }
  578. for (var di = 0; di < records.length; di++) {
  579. self.decorateActivity(records[di])
  580. }
  581. if (refresh) {
  582. self.myActivities = records
  583. } else {
  584. self.myActivities = self.myActivities.concat(records)
  585. }
  586. self.hasMore = records.length >= self.pageSize
  587. }
  588. }).catch(function() {
  589. self.mineLoading = false
  590. })
  591. },
  592. loadDiscoverActivities: function(refresh) {
  593. var self = this
  594. if (refresh) {
  595. this.discoverPage = 1
  596. this.discoverActivities = []
  597. }
  598. this.discoverLoading = true
  599. var params = {
  600. page: this.discoverPage,
  601. size: this.pageSize
  602. }
  603. if (this.currentDimension) {
  604. params.dimensionCode = this.currentDimension
  605. }
  606. getActivityList(params).then(function(res) {
  607. self.discoverLoading = false
  608. if (res && res.code === 200 && res.data) {
  609. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  610. if (refresh) {
  611. self.discoverActivities = list
  612. } else {
  613. self.discoverActivities = self.discoverActivities.concat(list)
  614. }
  615. self.hasMore = list.length >= self.pageSize
  616. }
  617. }).catch(function() {
  618. self.discoverLoading = false
  619. })
  620. },
  621. loadHistoryActivities: function(refresh) {
  622. var self = this
  623. if (refresh) {
  624. this.historyPage = 1
  625. this.historyActivities = []
  626. }
  627. this.historyLoading = true
  628. var memberId = uni.getStorageSync('currentChildId')
  629. if (!memberId) {
  630. this.historyLoading = false
  631. return
  632. }
  633. var params = {
  634. memberId: memberId,
  635. page: this.historyPage,
  636. size: this.pageSize
  637. }
  638. getMyActivityRegistrations(params).then(function(res) {
  639. self.historyLoading = false
  640. if (res && res.code === 200 && res.data) {
  641. var records = res.data.records || []
  642. var now = new Date()
  643. var ended = []
  644. for (var i = 0; i < records.length; i++) {
  645. var act = records[i]
  646. if (act.endTime) {
  647. var endTime = parseDate(act.endTime)
  648. if ((endTime && endTime < now) || act.status === 'cancelled' || act.status === 'rejected') {
  649. ended.push(act)
  650. }
  651. } else {
  652. ended.push(act)
  653. }
  654. }
  655. if (refresh) {
  656. self.historyActivities = ended
  657. } else {
  658. self.historyActivities = self.historyActivities.concat(ended)
  659. }
  660. self.hasMore = records.length >= self.pageSize
  661. }
  662. }).catch(function() {
  663. self.historyLoading = false
  664. })
  665. },
  666. goDetail: function(act) {
  667. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + act.id })
  668. },
  669. switchToDiscover: function() {
  670. this.currentTab = 'discover'
  671. this.loadData()
  672. },
  673. formatPrice: function(price) {
  674. return (price / 100).toFixed(2)
  675. },
  676. hasFee: function(act) {
  677. return (act.childFee > 0) || (act.childMemberFee > 0) || (act.parentFee > 0) || (act.parentMemberFee > 0)
  678. },
  679. minFee: function(act) {
  680. var fees = [act.childFee, act.childMemberFee, act.parentFee, act.parentMemberFee]
  681. var min = 0
  682. for (var i = 0; i < fees.length; i++) {
  683. if (fees[i] > 0 && (min === 0 || fees[i] < min)) min = fees[i]
  684. }
  685. return this.formatPrice(min)
  686. },
  687. decorateActivity: function(act) {
  688. if (act.status) {
  689. act._cls = act.status
  690. var map = { pending: '待审核', approved: '报名成功', rejected: '已拒绝', cancelled: '已取消', checked_in: '已签到' }
  691. act._txt = map[act.status] || act.status
  692. } else {
  693. if (act.endTime) {
  694. var endTime = parseDate(act.endTime)
  695. if (endTime && endTime < new Date()) {
  696. act._cls = 'ended'
  697. act._txt = '已结束'
  698. return act
  699. }
  700. }
  701. act._cls = 'upcoming'
  702. act._txt = '待开始'
  703. }
  704. return act
  705. },
  706. onCheckin: function(act) {
  707. var self = this
  708. var memberId = uni.getStorageSync('currentChildId')
  709. if (!memberId) {
  710. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  711. return
  712. }
  713. activityCheckin({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  714. if (res && res.code === 200) {
  715. uni.showToast({ title: '签到成功', icon: 'success' })
  716. self.loadMyActivities(true)
  717. } else {
  718. uni.showToast({ title: (res && res.message) || '签到失败', icon: 'none' })
  719. }
  720. }).catch(function() {
  721. uni.showToast({ title: '网络异常', icon: 'none' })
  722. })
  723. },
  724. onCancel: function(act) {
  725. var self = this
  726. uni.showModal({
  727. title: '提示',
  728. content: '确定要取消报名吗?',
  729. success: function(res) {
  730. if (res.confirm) {
  731. var memberId = uni.getStorageSync('currentChildId')
  732. if (!memberId) {
  733. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  734. return
  735. }
  736. cancelActivityRegistration({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  737. if (res && res.code === 200) {
  738. uni.showToast({ title: '已取消报名', icon: 'success' })
  739. self.loadMyActivities(true)
  740. } else {
  741. uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
  742. }
  743. }).catch(function() {
  744. uni.showToast({ title: '网络异常', icon: 'none' })
  745. })
  746. }
  747. }
  748. })
  749. }
  750. }
  751. }
  752. </script>
  753. <style scoped>
  754. .activity-container {
  755. min-height: 100vh;
  756. background: #F5F5F5;
  757. display: flex;
  758. flex-direction: column;
  759. }
  760. .tab-bar {
  761. background: #fff;
  762. display: flex;
  763. flex-direction: row;
  764. border-bottom: 1rpx solid #eee;
  765. }
  766. .tab-item {
  767. flex: 1;
  768. padding: 24rpx 0;
  769. text-align: center;
  770. border-bottom: 4rpx solid transparent;
  771. }
  772. .tab-item.active {
  773. border-bottom-color: #F97316;
  774. }
  775. .tab-label {
  776. font-size: 28rpx;
  777. color: #666;
  778. }
  779. .tab-item.active .tab-label {
  780. color: #F97316;
  781. font-weight: 600;
  782. }
  783. .content-scroll {
  784. flex: 1;
  785. height: calc(100vh - 200rpx);
  786. }
  787. .filter-scroll {
  788. padding: 20rpx 24rpx;
  789. background: #fff;
  790. }
  791. .filter-chips {
  792. display: flex;
  793. flex-direction: row;
  794. gap: 16rpx;
  795. }
  796. .filter-chip {
  797. padding: 12rpx 24rpx;
  798. border-radius: 16px;
  799. background: #fff;
  800. border: 1rpx solid #ddd;
  801. flex-shrink: 0;
  802. }
  803. .filter-chip.active {
  804. background: #FFF7ED;
  805. border-color: #F97316;
  806. }
  807. .filter-label {
  808. font-size: 24rpx;
  809. color: #666;
  810. }
  811. .filter-chip.active .filter-label {
  812. color: #F97316;
  813. font-weight: 500;
  814. }
  815. .card-list {
  816. padding: 0 24rpx 24rpx;
  817. display: flex;
  818. flex-direction: column;
  819. gap: 20rpx;
  820. }
  821. .activity-card {
  822. background: #fff;
  823. border-radius: 12rpx;
  824. padding: 20rpx;
  825. display: flex;
  826. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  827. }
  828. .card-cover {
  829. width: 144rpx;
  830. height: 144rpx;
  831. border-radius: 8rpx;
  832. flex-shrink: 0;
  833. background: #f0f0f0;
  834. }
  835. .card-info {
  836. flex: 1;
  837. margin-left: 20rpx;
  838. display: flex;
  839. flex-direction: column;
  840. }
  841. .card-title {
  842. font-size: 28rpx;
  843. font-weight: 600;
  844. color: #333;
  845. line-height: 1.4;
  846. overflow: hidden;
  847. text-overflow: ellipsis;
  848. white-space: nowrap;
  849. }
  850. .card-meta {
  851. font-size: 24rpx;
  852. color: #999;
  853. margin-top: 8rpx;
  854. }
  855. .card-bottom {
  856. display: flex;
  857. flex-direction: row;
  858. align-items: center;
  859. justify-content: space-between;
  860. margin-top: auto;
  861. padding-top: 12rpx;
  862. }
  863. .card-status {
  864. font-size: 22rpx;
  865. padding: 4rpx 12rpx;
  866. border-radius: 6rpx;
  867. }
  868. .status-pending {
  869. background: #FFF7ED;
  870. color: #F97316;
  871. }
  872. .status-approved {
  873. background: #F0FDF4;
  874. color: #22C55E;
  875. }
  876. .status-rejected {
  877. background: #FEF2F2;
  878. color: #EF4444;
  879. }
  880. .status-cancelled {
  881. background: #F5F5F5;
  882. color: #999;
  883. }
  884. .status-checked_in {
  885. background: #DBEAFE;
  886. color: #3B82F6;
  887. }
  888. .status-upcoming {
  889. background: #FFF7ED;
  890. color: #F97316;
  891. }
  892. .status-ended {
  893. background: #F5F5F5;
  894. color: #999;
  895. }
  896. .status-published {
  897. background: #F0FDF4;
  898. color: #22C55E;
  899. }
  900. .status-draft {
  901. background: #FFF7ED;
  902. color: #F97316;
  903. }
  904. .card-price {
  905. font-size: 28rpx;
  906. color: #F97316;
  907. font-weight: 600;
  908. }
  909. .card-price.free {
  910. color: #22C55E;
  911. }
  912. .card-actions {
  913. display: flex;
  914. flex-direction: row;
  915. gap: 12rpx;
  916. margin-top: 12rpx;
  917. }
  918. .btn-cancel {
  919. padding: 8rpx 20rpx;
  920. font-size: 22rpx;
  921. color: #999;
  922. background: #fff;
  923. border: 1rpx solid #ddd;
  924. border-radius: 20rpx;
  925. line-height: 1.5;
  926. }
  927. .btn-checkin {
  928. padding: 8rpx 20rpx;
  929. font-size: 22rpx;
  930. color: #fff;
  931. background: linear-gradient(135deg, #F97316, #FB923C);
  932. border: none;
  933. border-radius: 20rpx;
  934. line-height: 1.5;
  935. }
  936. .empty-state {
  937. display: flex;
  938. flex-direction: column;
  939. align-items: center;
  940. justify-content: center;
  941. padding: 120rpx 40rpx;
  942. }
  943. .empty-icon {
  944. font-size: 80rpx;
  945. margin-bottom: 20rpx;
  946. }
  947. .empty-title {
  948. font-size: 32rpx;
  949. font-weight: 600;
  950. color: #333;
  951. margin-bottom: 12rpx;
  952. }
  953. .empty-desc {
  954. font-size: 26rpx;
  955. color: #999;
  956. margin-bottom: 40rpx;
  957. }
  958. .empty-btn {
  959. padding: 16rpx 48rpx;
  960. font-size: 28rpx;
  961. color: #fff;
  962. background: linear-gradient(135deg, #F97316, #FB923C);
  963. border: none;
  964. border-radius: 40rpx;
  965. }
  966. .loading-state {
  967. display: flex;
  968. flex-direction: column;
  969. align-items: center;
  970. justify-content: center;
  971. padding: 80rpx 40rpx;
  972. }
  973. .loading-spinner {
  974. width: 60rpx;
  975. height: 60rpx;
  976. border: 4rpx solid #FDE68A;
  977. border-top-color: #F97316;
  978. border-radius: 50%;
  979. animation: spin 0.8s linear infinite;
  980. margin-bottom: 20rpx;
  981. }
  982. @keyframes spin {
  983. to { transform: rotate(360deg); }
  984. }
  985. .loading-text {
  986. font-size: 26rpx;
  987. color: #999;
  988. }
  989. .load-more-tip {
  990. text-align: center;
  991. padding: 30rpx;
  992. }
  993. .load-more-text {
  994. font-size: 24rpx;
  995. color: #999;
  996. }
  997. /* Nav add button */
  998. .nav-add-btn {
  999. position: absolute;
  1000. right: 24rpx;
  1001. top: 50%;
  1002. transform: translateY(-50%);
  1003. width: 56rpx;
  1004. height: 56rpx;
  1005. background: rgba(255, 255, 255, 0.15);
  1006. border-radius: 50%;
  1007. display: flex;
  1008. align-items: center;
  1009. justify-content: center;
  1010. }
  1011. .nav-add-icon {
  1012. color: #fff;
  1013. font-size: 36rpx;
  1014. font-weight: 300;
  1015. line-height: 1;
  1016. }
  1017. /* Manage overview stats */
  1018. .manage-overview {
  1019. display: flex;
  1020. flex-direction: row;
  1021. padding: 24rpx;
  1022. gap: 16rpx;
  1023. background: #fff;
  1024. margin: 24rpx 24rpx 0;
  1025. border-radius: 12rpx;
  1026. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  1027. }
  1028. .manage-stat-card {
  1029. flex: 1;
  1030. display: flex;
  1031. flex-direction: column;
  1032. align-items: center;
  1033. padding: 16rpx 0;
  1034. }
  1035. .manage-stat-num {
  1036. font-size: 40rpx;
  1037. font-weight: 700;
  1038. color: #333;
  1039. line-height: 1.2;
  1040. }
  1041. .manage-published {
  1042. color: #22C55E;
  1043. }
  1044. .manage-draft {
  1045. color: #F97316;
  1046. }
  1047. .manage-ended {
  1048. color: #999;
  1049. }
  1050. .manage-stat-label {
  1051. font-size: 22rpx;
  1052. color: #999;
  1053. margin-top: 8rpx;
  1054. }
  1055. /* Quick action button */
  1056. .manage-actions {
  1057. padding: 24rpx 24rpx 0;
  1058. }
  1059. .manage-action-btn {
  1060. display: flex;
  1061. flex-direction: row;
  1062. align-items: center;
  1063. justify-content: center;
  1064. gap: 12rpx;
  1065. padding: 24rpx 0;
  1066. background: linear-gradient(135deg, #F97316, #FB923C);
  1067. border-radius: 12rpx;
  1068. margin: 0 24rpx;
  1069. }
  1070. .manage-action-icon {
  1071. color: #fff;
  1072. font-size: 36rpx;
  1073. font-weight: 300;
  1074. }
  1075. .manage-action-text {
  1076. color: #fff;
  1077. font-size: 28rpx;
  1078. font-weight: 600;
  1079. }
  1080. /* Section title */
  1081. .manage-section-title {
  1082. padding: 24rpx 24rpx 12rpx;
  1083. }
  1084. .manage-section-title text {
  1085. font-size: 28rpx;
  1086. font-weight: 600;
  1087. color: #333;
  1088. }
  1089. /* Manage action group in card */
  1090. .manage-action-group {
  1091. display: flex;
  1092. flex-direction: row;
  1093. gap: 16rpx;
  1094. align-items: center;
  1095. }
  1096. .manage-action-small {
  1097. font-size: 22rpx;
  1098. padding: 4rpx 16rpx;
  1099. border-radius: 20rpx;
  1100. background: #F97316;
  1101. color: #fff;
  1102. font-weight: 500;
  1103. }
  1104. </style>