index.vue 34 KB

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