index.vue 33 KB

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