index.vue 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. <template>
  2. <view class="activity-container" :style="{ '--font-scale': fontScale }">
  3. <!-- Nav bar with title "活动中心" and admin "+" button -->
  4. <!-- Tab bar(管理 tab 仅对有活动管理权限的账号可见:活动管理员 / 已通过审核的活动提供商) -->
  5. <view class="tab-bar">
  6. <view
  7. class="tab-item"
  8. :class="{ active: currentTab === tab.key }"
  9. v-for="tab in visibleTabs"
  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. lazy-load />
  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">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</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. lazy-load />
  123. <view class="card-info">
  124. <text class="card-title">{{ act.title }}</text>
  125. <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
  126. <text class="card-desc" v-if="act.description">{{ act.description }}</text>
  127. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  128. <view class="card-bottom">
  129. <text class="card-status" :class="'status-' + (act.displayStatus || 'open')">
  130. {{ act.displayLabel || '报名中' }}
  131. </text>
  132. <text class="card-price" v-if="hasFee(act)">¥{{ minFee(act) }}</text>
  133. <text class="card-price free" v-else>免费</text>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. <!-- Empty state for discover -->
  139. <view class="empty-state" v-else-if="!discoverLoading">
  140. <text class="empty-icon">🔍</text>
  141. <text class="empty-title">暂无活动</text>
  142. <text class="empty-desc">稍后再来看看吧</text>
  143. </view>
  144. <!-- Loading state -->
  145. <view class="loading-state" v-if="discoverLoading">
  146. <view class="loading-spinner"></view>
  147. <text class="loading-text">加载中...</text>
  148. </view>
  149. <!-- Load more tip -->
  150. <view class="load-more-tip" v-if="discoverActivities.length > 0 && !hasMore && currentTab === 'discover'">
  151. <text class="load-more-text">没有更多了</text>
  152. </view>
  153. </view>
  154. <!-- Tab 3: history -->
  155. <view v-if="currentTab === 'history'">
  156. <!-- Filter chips (same as mine) -->
  157. <scroll-view class="filter-scroll" scroll-x enable-flex>
  158. <view class="filter-chips">
  159. <view
  160. class="filter-chip"
  161. :class="{ active: currentMineFilter === filter.value }"
  162. v-for="filter in mineFilters"
  163. :key="filter.value"
  164. @click="onMineFilterChange(filter.value)"
  165. >
  166. <text class="filter-label">{{ filter.label }}</text>
  167. </view>
  168. </view>
  169. </scroll-view>
  170. <!-- Activity cards -->
  171. <view class="card-list" v-if="historyActivities.length > 0">
  172. <view
  173. class="activity-card"
  174. v-for="act in historyActivities"
  175. :key="act.id"
  176. @click="goDetail(act)"
  177. >
  178. <image
  179. class="card-cover"
  180. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  181. mode="aspectFill"
  182. lazy-load />
  183. <view class="card-info">
  184. <text class="card-title">{{ act.title }}</text>
  185. <text class="card-meta">开始 {{ formatDateTime(act.startTime) }}{{ act.endTime ? ' 结束 ' + formatDateTime(act.endTime) : '' }}</text>
  186. <text class="card-meta" v-if="act.location">📍 {{ act.location }}</text>
  187. <view class="card-bottom">
  188. <text class="card-status status-ended">已结束</text>
  189. <text class="card-price" v-if="act.price > 0">¥{{ formatPrice(act.price) }}</text>
  190. <text class="card-price free" v-else>免费</text>
  191. </view>
  192. </view>
  193. </view>
  194. </view>
  195. <!-- Empty state for history -->
  196. <view class="empty-state" v-else-if="!historyLoading">
  197. <text class="empty-icon">📜</text>
  198. <text class="empty-title">暂无历史活动</text>
  199. <text class="empty-desc">参加过的活动会显示在这里</text>
  200. </view>
  201. <!-- Loading state -->
  202. <view class="loading-state" v-if="historyLoading">
  203. <view class="loading-spinner"></view>
  204. <text class="loading-text">加载中...</text>
  205. </view>
  206. <!-- Load more tip -->
  207. <view class="load-more-tip" v-if="historyActivities.length > 0 && !hasMore && currentTab === 'history'">
  208. <text class="load-more-text">没有更多了</text>
  209. </view>
  210. </view>
  211. <!-- Tab 4: manage(visibleTabs 已按权限过滤,此处再兜底一次,避免无权限时白屏) -->
  212. <view v-if="currentTab === 'manage' && canManageActivity">
  213. <!-- Manage overview stats -->
  214. <view class="manage-overview">
  215. <view class="manage-stat-card">
  216. <text class="manage-stat-num">{{ manageStats.total }}</text>
  217. <text class="manage-stat-label">全部活动</text>
  218. </view>
  219. <view class="manage-stat-card">
  220. <text class="manage-stat-num manage-published">{{ manageStats.published }}</text>
  221. <text class="manage-stat-label">已发布</text>
  222. </view>
  223. <view class="manage-stat-card">
  224. <text class="manage-stat-num manage-draft">{{ manageStats.draft }}</text>
  225. <text class="manage-stat-label">草稿</text>
  226. </view>
  227. <view class="manage-stat-card">
  228. <text class="manage-stat-num manage-ended">{{ manageStats.ended }}</text>
  229. <text class="manage-stat-label">已结束</text>
  230. </view>
  231. </view>
  232. <!-- Quick actions -->
  233. <view class="manage-actions">
  234. <view class="manage-action-btn" @click="goCreate">
  235. <text class="manage-action-icon">+</text>
  236. <text class="manage-action-text">创建活动</text>
  237. </view>
  238. </view>
  239. <!-- My managed activities list -->
  240. <view class="manage-section-title">
  241. <text>我的活动管理</text>
  242. </view>
  243. <view class="card-list" v-if="manageActivities.length > 0">
  244. <view
  245. class="activity-card"
  246. v-for="act in manageActivities"
  247. :key="act.id"
  248. @click="goEdit(act)"
  249. >
  250. <image
  251. class="card-cover"
  252. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  253. mode="aspectFill"
  254. lazy-load />
  255. <view class="card-info">
  256. <text class="card-title">{{ act.title }}</text>
  257. <text class="card-meta">{{ act.startTime }}</text>
  258. <view class="card-bottom">
  259. <text class="card-status" :class="'status-' + (act.status || 'draft')">
  260. {{ statusLabel(act.status) }}
  261. </text>
  262. <view class="manage-action-group">
  263. <text class="manage-action-small" v-if="act.status === 'draft'" @click.stop="doPublish(act.id)">{{ canDirectPublish ? '发布' : '提交审核' }}</text>
  264. <text class="manage-action-small" v-if="act.status === 'rejected'" @click.stop="doPublish(act.id)">重新提交</text>
  265. <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doEnd(act.id)">结束</text>
  266. <text class="manage-action-small" v-if="act.status === 'published'" @click.stop="doWithdraw(act.id)">撤回</text>
  267. </view>
  268. </view>
  269. </view>
  270. </view>
  271. </view>
  272. <view class="empty-state" v-else-if="!manageLoading">
  273. <text class="empty-icon">📊</text>
  274. <text class="empty-title">暂无管理的活动</text>
  275. <text class="empty-desc">点击上方「创建活动」开始</text>
  276. </view>
  277. <view class="loading-state" v-if="manageLoading">
  278. <view class="loading-spinner"></view>
  279. <text class="loading-text">加载中...</text>
  280. </view>
  281. </view>
  282. </scroll-view>
  283. </view>
  284. </template>
  285. <script>
  286. import { getActivityList, getMyActivityRegistrations, activityCheckin, cancelActivityRegistration, adminListMyActivities, adminPublishActivity, adminEndActivity, adminWithdrawActivity, submitActivityForReview, vendorStatus, reportAppEnter} from '@/utils/api.js'
  287. import config from '@/config.js'
  288. import { parseDate, formatDateTime } from '../../utils/format.js'
  289. import { hasActivityManageRole, isApprovedActivityProvider } from '@/utils/activity-role.js'
  290. import fontScaleMixin from '@/mixins/font-scale.js'
  291. export default {
  292. mixins: [fontScaleMixin],
  293. computed: {
  294. // 管理 tab 只对有活动管理权限的账号展示(普通家长/孩子不显示,避免点进去是空白)
  295. visibleTabs: function() {
  296. var list = [
  297. { key: 'mine', label: '我的活动' },
  298. { key: 'discover', label: '发现活动' },
  299. { key: 'history', label: '历史记录' }
  300. ]
  301. if (this.canManageActivity) {
  302. list.push({ key: 'manage', label: '管理' })
  303. }
  304. return list
  305. }
  306. },
  307. data() {
  308. return {
  309. // 活动管理权限:后台角色(admin/activity_admin/activity_manager)或已通过审核的活动提供商
  310. canManageActivity: false,
  311. // 是否有权直接发布(后台活动管理员);服务商只能提交审核
  312. canDirectPublish: false,
  313. currentTab: 'mine',
  314. mineFilters: [
  315. { label: '全部', value: '' },
  316. { label: '待开始', value: 'upcoming' },
  317. { label: '待审核', value: 'pending' },
  318. { label: '已签到', value: 'checked_in' }
  319. ],
  320. dimensionFilters: [
  321. { label: '全部', value: '' },
  322. { label: '身', value: 'body' },
  323. { label: '心', value: 'mind' },
  324. { label: '智', value: 'wisdom' },
  325. { label: '行', value: 'action' },
  326. { label: '富', value: 'wealth' }
  327. ],
  328. currentMineFilter: '',
  329. currentDimension: '',
  330. myActivities: [],
  331. discoverActivities: [],
  332. historyActivities: [],
  333. mineLoading: false,
  334. discoverLoading: false,
  335. historyLoading: false,
  336. minePage: 1,
  337. discoverPage: 1,
  338. historyPage: 1,
  339. pageSize: 10,
  340. hasMore: true,
  341. isRefreshing: false,
  342. // Manage tab data
  343. manageLoading: false,
  344. manageStats: { total: 0, published: 0, draft: 0, ended: 0 },
  345. manageActivities: []
  346. }
  347. },
  348. onLoad: function(options) {
  349. reportAppEnter('activity');
  350. if (options && options.tab) {
  351. this.currentTab = options.tab
  352. }
  353. this.resolveManagePermission()
  354. this.loadData()
  355. this._onLoadFired = true
  356. },
  357. onShow: function() {
  358. if (this._onLoadFired) {
  359. this._onLoadFired = false // 首次进入:onLoad 已加载,跳过避免双发
  360. } else {
  361. // 切 Tab/从子页返回:刷新权限态(同步部分不发请求)+ 当前 tab 数据
  362. this.resolveManagePermission()
  363. this.loadData()
  364. }
  365. },
  366. methods: {
  367. // 活动管理权限判定:与后端 ActivityController.hasActivityManageRole 对齐。
  368. // 后台角色(admin / activity_admin / activity_manager)→ 可直接发布;
  369. // 其余账号查服务商入驻状态,vendorType=activity_provider 且审核通过 → 可管理(只能提交审核)。
  370. resolveManagePermission: function() {
  371. var self = this
  372. if (hasActivityManageRole()) {
  373. self.canDirectPublish = true
  374. self.canManageActivity = true
  375. self.onPermissionResolved()
  376. return
  377. }
  378. // 未登录不发 vendorStatus:请求层会因 401 触发静默续期/跳登录,影响游客浏览活动
  379. if (!uni.getStorageSync('token')) {
  380. return
  381. }
  382. vendorStatus().then(function(res) {
  383. var approvedProvider = isApprovedActivityProvider((res && res.data) || {})
  384. // 非后台角色才由服务商审核状态决定(后台角色已在上面提前返回,不会被覆盖)
  385. if (!self.canDirectPublish) {
  386. self.canManageActivity = approvedProvider
  387. }
  388. self.onPermissionResolved()
  389. }).catch(function() {
  390. if (!self.canDirectPublish) {
  391. self.canManageActivity = false
  392. }
  393. self.onPermissionResolved()
  394. })
  395. },
  396. // 权限解析完成后的兜底:以 ?tab=manage 进来但无权限时回落到「我的活动」,避免空白页
  397. onPermissionResolved: function() {
  398. if (this.currentTab === 'manage' && !this.canManageActivity) {
  399. this.currentTab = 'mine'
  400. this.loadData()
  401. }
  402. },
  403. getImageUrl: function(path) {
  404. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  405. var s = String(path).trim()
  406. if (!s || s === 'null' || s === '/null') return ''
  407. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  408. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  409. },
  410. onTabChange: function(key) {
  411. this.currentTab = key
  412. this.hasMore = true
  413. if (key === 'mine') {
  414. this.minePage = 1
  415. this.myActivities = []
  416. } else if (key === 'discover') {
  417. this.discoverPage = 1
  418. this.discoverActivities = []
  419. } else if (key === 'history') {
  420. this.historyPage = 1
  421. this.historyActivities = []
  422. }
  423. this.loadData()
  424. },
  425. loadData: function() {
  426. if (this.currentTab === 'mine') {
  427. this.loadMyActivities()
  428. } else if (this.currentTab === 'discover') {
  429. this.loadDiscoverActivities()
  430. } else if (this.currentTab === 'history') {
  431. this.loadHistoryActivities()
  432. } else if (this.currentTab === 'manage') {
  433. // 权限未解析/无权限时不发管理列表请求(onPermissionResolved 会回落 mine)
  434. if (this.canManageActivity) {
  435. this.loadManageData()
  436. }
  437. }
  438. },
  439. loadManageData: function() {
  440. var self = this
  441. this.manageLoading = true
  442. // 活动服务商(非后台角色)只看自己创建/负责的活动,后台活动管理员由后端按角色隔离
  443. var params = { page: 1, size: 100 }
  444. if (!self.canDirectPublish) {
  445. params.mineOnly = true
  446. }
  447. adminListMyActivities(params).then(function(res) {
  448. self.manageLoading = false
  449. if (res && res.code === 200 && res.data) {
  450. var records = res.data.records || []
  451. self.manageActivities = records.slice(0, 20)
  452. var total = records.length
  453. var published = 0
  454. var draft = 0
  455. var ended = 0
  456. for (var i = 0; i < records.length; i++) {
  457. var s = records[i].status
  458. if (s === 'published') published++
  459. else if (s === 'draft') draft++
  460. else if (s === 'ended' || s === 'cancelled' || s === 'withdrawn') ended++
  461. }
  462. self.manageStats = { total: total, published: published, draft: draft, ended: ended }
  463. } else {
  464. self.manageActivities = []
  465. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  466. }
  467. }).catch(function() {
  468. self.manageLoading = false
  469. self.manageActivities = []
  470. self.manageStats = { total: 0, published: 0, draft: 0, ended: 0 }
  471. })
  472. },
  473. goCreate: function() {
  474. uni.navigateTo({ url: '/pages/activity/create' })
  475. },
  476. goEdit: function(act) {
  477. uni.navigateTo({ url: '/pages/activity/create?id=' + act.id })
  478. },
  479. statusLabel: function(status) {
  480. var map = {
  481. draft: '草稿',
  482. pending: '待审核',
  483. rejected: '已驳回',
  484. published: '进行中',
  485. ended: '已结束',
  486. withdrawn: '已撤回',
  487. cancelled: '已取消'
  488. }
  489. return map[status] || status
  490. },
  491. doPublish: function(id) {
  492. var self = this
  493. uni.showModal({
  494. title: '提示',
  495. content: '确认发布此活动吗?发布后将对外可见。',
  496. success: function(res) {
  497. if (res.confirm) {
  498. uni.showLoading({ title: '发布中...' })
  499. if (self.canDirectPublish) {
  500. adminPublishActivity(id).then(function(r) {
  501. uni.hideLoading()
  502. if (r && r.code === 200) {
  503. uni.showToast({ title: '发布成功', icon: 'success' })
  504. self.loadManageData()
  505. } else {
  506. uni.showToast({ title: (r && r.message) || '发布失败', icon: 'none' })
  507. }
  508. }).catch(function() {
  509. uni.hideLoading()
  510. uni.showToast({ title: '发布失败', icon: 'none' })
  511. })
  512. } else {
  513. submitActivityForReview(id).then(function(r) {
  514. uni.hideLoading()
  515. if (r && r.code === 200) {
  516. uni.showToast({ title: '已提交审核', icon: 'success' })
  517. self.loadManageData()
  518. } else {
  519. uni.showToast({ title: (r && r.message) || '提交审核失败', icon: 'none' })
  520. }
  521. }).catch(function() {
  522. uni.hideLoading()
  523. uni.showToast({ title: '提交审核失败', icon: 'none' })
  524. })
  525. }
  526. }
  527. }
  528. })
  529. },
  530. doEnd: function(id) {
  531. var self = this
  532. uni.showModal({
  533. title: '提示',
  534. content: '确认结束此活动吗?结束后不再接受新参与者。',
  535. success: function(res) {
  536. if (res.confirm) {
  537. uni.showLoading({ title: '操作中...' })
  538. adminEndActivity(id).then(function(r) {
  539. uni.hideLoading()
  540. if (r && r.code === 200) {
  541. uni.showToast({ title: '已结束', icon: 'success' })
  542. self.loadManageData()
  543. } else {
  544. uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
  545. }
  546. }).catch(function() {
  547. uni.hideLoading()
  548. uni.showToast({ title: '网络异常', icon: 'none' })
  549. })
  550. }
  551. }
  552. })
  553. },
  554. doWithdraw: function(id) {
  555. var self = this
  556. uni.showModal({
  557. title: '提示',
  558. content: '确认撤回此活动吗?撤回后不再对外展示,可重新编辑。',
  559. success: function(res) {
  560. if (res.confirm) {
  561. uni.showLoading({ title: '操作中...' })
  562. adminWithdrawActivity(id).then(function(r) {
  563. uni.hideLoading()
  564. if (r && r.code === 200) {
  565. uni.showToast({ title: '已撤回', icon: 'success' })
  566. self.loadManageData()
  567. } else {
  568. uni.showToast({ title: (r && r.message) || '操作失败', icon: 'none' })
  569. }
  570. }).catch(function() {
  571. uni.hideLoading()
  572. uni.showToast({ title: '网络异常', icon: 'none' })
  573. })
  574. }
  575. }
  576. })
  577. },
  578. onMineFilterChange: function(value) {
  579. this.currentMineFilter = value
  580. this.minePage = 1
  581. this.myActivities = []
  582. this.hasMore = true
  583. if (this.currentTab === 'mine') {
  584. this.loadMyActivities()
  585. } else if (this.currentTab === 'history') {
  586. this.loadHistoryActivities()
  587. }
  588. },
  589. onDimensionChange: function(value) {
  590. this.currentDimension = value
  591. this.discoverPage = 1
  592. this.discoverActivities = []
  593. this.hasMore = true
  594. this.loadDiscoverActivities()
  595. },
  596. onLoadMore: function() {
  597. if (!this.hasMore) return
  598. if (this.currentTab === 'mine' && !this.mineLoading) {
  599. this.minePage++
  600. this.loadMyActivities()
  601. } else if (this.currentTab === 'discover' && !this.discoverLoading) {
  602. this.discoverPage++
  603. this.loadDiscoverActivities()
  604. } else if (this.currentTab === 'history' && !this.historyLoading) {
  605. this.historyPage++
  606. this.loadHistoryActivities()
  607. }
  608. },
  609. onRefresh: function() {
  610. var self = this
  611. this.isRefreshing = true
  612. if (this.currentTab === 'mine') {
  613. this.loadMyActivities(true).finally(function() {
  614. self.isRefreshing = false
  615. })
  616. } else if (this.currentTab === 'discover') {
  617. this.loadDiscoverActivities(true).finally(function() {
  618. self.isRefreshing = false
  619. })
  620. } else if (this.currentTab === 'history') {
  621. this.loadHistoryActivities(true).finally(function() {
  622. self.isRefreshing = false
  623. })
  624. } else {
  625. this.isRefreshing = false
  626. }
  627. },
  628. loadMyActivities: function(refresh) {
  629. var self = this
  630. if (refresh) {
  631. this.minePage = 1
  632. this.myActivities = []
  633. }
  634. this.mineLoading = true
  635. var memberId = uni.getStorageSync('currentChildId')
  636. if (!memberId) {
  637. this.mineLoading = false
  638. return
  639. }
  640. var params = {
  641. memberId: memberId,
  642. page: this.minePage,
  643. size: this.pageSize
  644. }
  645. if (this.currentMineFilter && this.currentMineFilter !== 'upcoming') {
  646. params.status = this.currentMineFilter
  647. }
  648. getMyActivityRegistrations(params).then(function(res) {
  649. self.mineLoading = false
  650. if (res && res.code === 200 && res.data) {
  651. var records = res.data.records || []
  652. for (var ni = 0; ni < records.length; ni++) {
  653. self.normalizeRegistration(records[ni])
  654. }
  655. if (self.currentMineFilter === 'upcoming') {
  656. var now = new Date()
  657. var filtered = []
  658. for (var i = 0; i < records.length; i++) {
  659. var act = records[i]
  660. if (act.startTime) {
  661. var startTime = parseDate(act.startTime)
  662. if (!startTime) continue
  663. if (startTime > now && act.status === 'approved') {
  664. filtered.push(act)
  665. }
  666. }
  667. }
  668. records = filtered
  669. }
  670. for (var di = 0; di < records.length; di++) {
  671. self.decorateActivity(records[di])
  672. }
  673. if (refresh) {
  674. self.myActivities = records
  675. } else {
  676. self.myActivities = self.myActivities.concat(records)
  677. }
  678. self.hasMore = records.length >= self.pageSize
  679. }
  680. }).catch(function() {
  681. self.mineLoading = false
  682. })
  683. },
  684. loadDiscoverActivities: function(refresh) {
  685. var self = this
  686. if (refresh) {
  687. this.discoverPage = 1
  688. this.discoverActivities = []
  689. }
  690. this.discoverLoading = true
  691. var params = {
  692. page: this.discoverPage,
  693. size: this.pageSize
  694. }
  695. if (this.currentDimension) {
  696. params.dimensionCode = this.currentDimension
  697. }
  698. getActivityList(params).then(function(res) {
  699. self.discoverLoading = false
  700. if (res && res.code === 200 && res.data) {
  701. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  702. if (refresh) {
  703. self.discoverActivities = list
  704. } else {
  705. self.discoverActivities = self.discoverActivities.concat(list)
  706. }
  707. self.hasMore = list.length >= self.pageSize
  708. }
  709. }).catch(function() {
  710. self.discoverLoading = false
  711. })
  712. },
  713. loadHistoryActivities: function(refresh) {
  714. var self = this
  715. if (refresh) {
  716. this.historyPage = 1
  717. this.historyActivities = []
  718. }
  719. this.historyLoading = true
  720. var memberId = uni.getStorageSync('currentChildId')
  721. if (!memberId) {
  722. this.historyLoading = false
  723. return
  724. }
  725. var params = {
  726. memberId: memberId,
  727. page: this.historyPage,
  728. size: this.pageSize
  729. }
  730. getMyActivityRegistrations(params).then(function(res) {
  731. self.historyLoading = false
  732. if (res && res.code === 200 && res.data) {
  733. var records = res.data.records || []
  734. var now = new Date()
  735. var ended = []
  736. for (var i = 0; i < records.length; i++) {
  737. var act = records[i]
  738. self.normalizeRegistration(act)
  739. var endTime = parseDate(act.endTime)
  740. var startTime = parseDate(act.startTime)
  741. // 有结束时间按结束时间判断;无结束时间(如线上活动)按开始时间已过判断
  742. var isPast = (endTime && endTime < now) || (!endTime && startTime && startTime < now)
  743. if (isPast || act.status === 'cancelled' || act.status === 'rejected') {
  744. ended.push(act)
  745. }
  746. }
  747. if (refresh) {
  748. self.historyActivities = ended
  749. } else {
  750. self.historyActivities = self.historyActivities.concat(ended)
  751. }
  752. self.hasMore = records.length >= self.pageSize
  753. }
  754. }).catch(function() {
  755. self.historyLoading = false
  756. })
  757. },
  758. // 报名记录 → 卡片所需字段:/api/activity/my-registrations 返回的是
  759. // activityTitle/activityStartTime/... ,直接渲染会标题/时间/封面/费用全空
  760. normalizeRegistration: function(act) {
  761. if (!act) return act
  762. if (!act.title && act.activityTitle) act.title = act.activityTitle
  763. if (act.activityStartTime) act.startTime = formatDateTime(act.activityStartTime)
  764. if (act.activityEndTime) act.endTime = formatDateTime(act.activityEndTime)
  765. if (!act.coverImage && act.activityCoverImage) act.coverImage = act.activityCoverImage
  766. if (!act.location && act.activityLocation) act.location = act.activityLocation
  767. var fees = [act.activityChildFee, act.activityChildMemberFee, act.activityParentFee, act.activityParentMemberFee]
  768. var price = 0
  769. for (var i = 0; i < fees.length; i++) {
  770. var f = Number(fees[i]) || 0
  771. if (f > 0 && (price === 0 || f < price)) price = f
  772. }
  773. act.price = price
  774. return act
  775. },
  776. goDetail: function(act) {
  777. // 报名记录的 id 是报名 id,必须取 activityId;发现列表的 id 即活动 id
  778. var id = act.activityId || act.id
  779. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + id })
  780. },
  781. switchToDiscover: function() {
  782. this.currentTab = 'discover'
  783. this.hasMore = true
  784. this.discoverPage = 1
  785. this.discoverActivities = []
  786. this.loadDiscoverActivities()
  787. },
  788. formatPrice: function(price) {
  789. return (price / 100).toFixed(2)
  790. },
  791. formatDateTime: formatDateTime,
  792. hasFee: function(act) {
  793. return (act.childFee > 0) || (act.childMemberFee > 0) || (act.parentFee > 0) || (act.parentMemberFee > 0)
  794. },
  795. minFee: function(act) {
  796. var fees = [act.childFee, act.childMemberFee, act.parentFee, act.parentMemberFee]
  797. var min = 0
  798. for (var i = 0; i < fees.length; i++) {
  799. if (fees[i] > 0 && (min === 0 || fees[i] < min)) min = fees[i]
  800. }
  801. return this.formatPrice(min)
  802. },
  803. decorateActivity: function(act) {
  804. if (act.status) {
  805. act._cls = act.status
  806. var map = { pending: '待审核', approved: '报名成功', rejected: '已拒绝', cancelled: '已取消', checked_in: '已签到' }
  807. act._txt = map[act.status] || act.status
  808. } else {
  809. if (act.endTime) {
  810. var endTime = parseDate(act.endTime)
  811. if (endTime && endTime < new Date()) {
  812. act._cls = 'ended'
  813. act._txt = '已结束'
  814. return act
  815. }
  816. }
  817. act._cls = 'upcoming'
  818. act._txt = '待开始'
  819. }
  820. return act
  821. },
  822. onCheckin: function(act) {
  823. var self = this
  824. var memberId = uni.getStorageSync('currentChildId')
  825. if (!memberId) {
  826. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  827. return
  828. }
  829. activityCheckin({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  830. if (res && res.code === 200) {
  831. uni.showToast({ title: '签到成功', icon: 'success' })
  832. self.loadMyActivities(true)
  833. } else {
  834. uni.showToast({ title: (res && res.message) || '签到失败', icon: 'none' })
  835. }
  836. }).catch(function() {
  837. uni.showToast({ title: '网络异常', icon: 'none' })
  838. })
  839. },
  840. onCancel: function(act) {
  841. var self = this
  842. uni.showModal({
  843. title: '提示',
  844. content: '确定要取消报名吗?',
  845. success: function(res) {
  846. if (res.confirm) {
  847. var memberId = uni.getStorageSync('currentChildId')
  848. if (!memberId) {
  849. uni.showToast({ title: '请先选择家庭成员身份', icon: 'none' })
  850. return
  851. }
  852. cancelActivityRegistration({ id: act.activityId || act.id, memberId: memberId }).then(function(res) {
  853. if (res && res.code === 200) {
  854. uni.showToast({ title: '已取消报名', icon: 'success' })
  855. self.loadMyActivities(true)
  856. } else {
  857. uni.showToast({ title: (res && res.message) || '取消失败', icon: 'none' })
  858. }
  859. }).catch(function() {
  860. uni.showToast({ title: '网络异常', icon: 'none' })
  861. })
  862. }
  863. }
  864. })
  865. }
  866. }
  867. }
  868. </script>
  869. <style scoped lang="scss">
  870. .activity-container {
  871. min-height: 100vh;
  872. background: $facade-fill-2;
  873. display: flex;
  874. flex-direction: column;
  875. }
  876. .tab-bar {
  877. background: $app-surface;
  878. display: flex;
  879. flex-direction: row;
  880. border-bottom: 1rpx solid $facade-hairline-2;
  881. }
  882. .tab-item {
  883. flex: 1;
  884. padding: 24rpx 0;
  885. text-align: center;
  886. border-bottom: 4rpx solid transparent;
  887. }
  888. .tab-item.active {
  889. border-bottom-color: $brand-primary;
  890. }
  891. .tab-label {
  892. font-size: 28rpx;
  893. color: $facade-text-body;
  894. }
  895. .tab-item.active .tab-label {
  896. color: $brand-primary;
  897. font-weight: 600;
  898. }
  899. .content-scroll {
  900. flex: 1;
  901. height: calc(100vh - 200rpx);
  902. }
  903. .filter-scroll {
  904. padding: 20rpx 24rpx;
  905. background: $app-surface;
  906. }
  907. .filter-chips {
  908. display: flex;
  909. flex-direction: row;
  910. gap: 16rpx;
  911. }
  912. .filter-chip {
  913. padding: 12rpx 24rpx;
  914. border-radius: 16px;
  915. background: $app-surface;
  916. border: 1rpx solid $facade-border-soft;
  917. flex-shrink: 0;
  918. }
  919. .filter-chip.active {
  920. background: $uni-primary-pale;
  921. border-color: $brand-primary;
  922. }
  923. .filter-label {
  924. font-size: 24rpx;
  925. color: $facade-text-body;
  926. }
  927. .filter-chip.active .filter-label {
  928. color: $brand-primary;
  929. font-weight: 500;
  930. }
  931. .card-list {
  932. padding: 0 24rpx 24rpx;
  933. display: flex;
  934. flex-direction: column;
  935. gap: 20rpx;
  936. }
  937. .activity-card {
  938. background: $app-surface;
  939. border-radius: 12rpx;
  940. padding: 20rpx;
  941. display: flex;
  942. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  943. }
  944. .card-cover {
  945. width: 144rpx;
  946. height: 144rpx;
  947. border-radius: 8rpx;
  948. flex-shrink: 0;
  949. background: $facade-fill;
  950. }
  951. .card-info {
  952. flex: 1;
  953. margin-left: 20rpx;
  954. display: flex;
  955. flex-direction: column;
  956. }
  957. .card-title {
  958. font-size: calc(28rpx * var(--font-scale, 1));
  959. font-weight: 600;
  960. color: $facade-text-strong;
  961. line-height: 1.4;
  962. overflow: hidden;
  963. text-overflow: ellipsis;
  964. white-space: nowrap;
  965. }
  966. .card-meta {
  967. font-size: 24rpx;
  968. color: $facade-text-muted;
  969. margin-top: 8rpx;
  970. }
  971. .card-bottom {
  972. display: flex;
  973. flex-direction: row;
  974. align-items: center;
  975. justify-content: space-between;
  976. margin-top: auto;
  977. padding-top: 12rpx;
  978. }
  979. .card-status {
  980. font-size: 22rpx;
  981. padding: 4rpx 12rpx;
  982. border-radius: 6rpx;
  983. }
  984. .status-pending {
  985. background: $uni-primary-pale;
  986. color: $brand-primary;
  987. }
  988. .status-approved {
  989. background: $status-success-tint-2;
  990. color: $status-success-2;
  991. }
  992. .status-rejected {
  993. background: #FEF2F2;
  994. color: $status-danger;
  995. }
  996. .status-cancelled {
  997. background: $facade-fill-2;
  998. color: $facade-text-muted;
  999. }
  1000. .status-checked_in {
  1001. background: $status-info-soft;
  1002. color: $status-info;
  1003. }
  1004. .status-upcoming {
  1005. background: $uni-primary-pale;
  1006. color: $brand-primary;
  1007. }
  1008. .status-ended {
  1009. background: $facade-fill-2;
  1010. color: $facade-text-muted;
  1011. }
  1012. .status-published {
  1013. background: $status-success-tint-2;
  1014. color: $status-success-2;
  1015. }
  1016. .status-draft {
  1017. background: $uni-primary-pale;
  1018. color: $brand-primary;
  1019. }
  1020. .card-price {
  1021. font-size: 28rpx;
  1022. color: $brand-primary;
  1023. font-weight: 600;
  1024. }
  1025. .card-price.free {
  1026. color: $status-success-2;
  1027. }
  1028. .card-actions {
  1029. display: flex;
  1030. flex-direction: row;
  1031. gap: 12rpx;
  1032. margin-top: 12rpx;
  1033. }
  1034. .btn-cancel {
  1035. padding: 8rpx 20rpx;
  1036. font-size: 22rpx;
  1037. color: $facade-text-muted;
  1038. background: $app-surface;
  1039. border: 1rpx solid $facade-border-soft;
  1040. border-radius: 20rpx;
  1041. line-height: 1.5;
  1042. }
  1043. .btn-checkin {
  1044. padding: 8rpx 20rpx;
  1045. font-size: 22rpx;
  1046. color: $app-surface;
  1047. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  1048. border: none;
  1049. border-radius: 20rpx;
  1050. line-height: 1.5;
  1051. }
  1052. .empty-state {
  1053. display: flex;
  1054. flex-direction: column;
  1055. align-items: center;
  1056. justify-content: center;
  1057. padding: 120rpx 40rpx;
  1058. }
  1059. .empty-icon {
  1060. font-size: 80rpx;
  1061. margin-bottom: 20rpx;
  1062. }
  1063. .empty-title {
  1064. font-size: 32rpx;
  1065. font-weight: 600;
  1066. color: $facade-text-strong;
  1067. margin-bottom: 12rpx;
  1068. }
  1069. .empty-desc {
  1070. font-size: 26rpx;
  1071. color: $facade-text-muted;
  1072. margin-bottom: 40rpx;
  1073. }
  1074. .empty-btn {
  1075. padding: 16rpx 48rpx;
  1076. font-size: 28rpx;
  1077. color: $app-surface;
  1078. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  1079. border: none;
  1080. border-radius: 40rpx;
  1081. }
  1082. .loading-state {
  1083. display: flex;
  1084. flex-direction: column;
  1085. align-items: center;
  1086. justify-content: center;
  1087. padding: 80rpx 40rpx;
  1088. }
  1089. .loading-spinner {
  1090. width: 60rpx;
  1091. height: 60rpx;
  1092. border: 4rpx solid #FDE68A;
  1093. border-top-color: $brand-primary;
  1094. border-radius: 50%;
  1095. animation: spin 0.8s linear infinite;
  1096. margin-bottom: 20rpx;
  1097. }
  1098. @keyframes spin {
  1099. to { transform: rotate(360deg); }
  1100. }
  1101. .loading-text {
  1102. font-size: 26rpx;
  1103. color: $facade-text-muted;
  1104. }
  1105. .load-more-tip {
  1106. text-align: center;
  1107. padding: 30rpx;
  1108. }
  1109. .load-more-text {
  1110. font-size: 24rpx;
  1111. color: $facade-text-muted;
  1112. }
  1113. /* Nav add button */
  1114. .nav-add-btn {
  1115. position: absolute;
  1116. right: 24rpx;
  1117. top: 50%;
  1118. transform: translateY(-50%);
  1119. width: 56rpx;
  1120. height: 56rpx;
  1121. background: rgba(255, 255, 255, 0.15);
  1122. border-radius: 50%;
  1123. display: flex;
  1124. align-items: center;
  1125. justify-content: center;
  1126. }
  1127. .nav-add-icon {
  1128. color: $app-surface;
  1129. font-size: 36rpx;
  1130. font-weight: 300;
  1131. line-height: 1;
  1132. }
  1133. /* Manage overview stats */
  1134. .manage-overview {
  1135. display: flex;
  1136. flex-direction: row;
  1137. padding: 24rpx;
  1138. gap: 16rpx;
  1139. background: $app-surface;
  1140. margin: 24rpx 24rpx 0;
  1141. border-radius: 12rpx;
  1142. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  1143. }
  1144. .manage-stat-card {
  1145. flex: 1;
  1146. display: flex;
  1147. flex-direction: column;
  1148. align-items: center;
  1149. padding: 16rpx 0;
  1150. }
  1151. .manage-stat-num {
  1152. font-size: 40rpx;
  1153. font-weight: 700;
  1154. color: $facade-text-strong;
  1155. line-height: 1.2;
  1156. }
  1157. .manage-published {
  1158. color: $status-success-2;
  1159. }
  1160. .manage-draft {
  1161. color: $brand-primary;
  1162. }
  1163. .manage-ended {
  1164. color: $facade-text-muted;
  1165. }
  1166. .manage-stat-label {
  1167. font-size: 22rpx;
  1168. color: $facade-text-muted;
  1169. margin-top: 8rpx;
  1170. }
  1171. /* Quick action button */
  1172. .manage-actions {
  1173. padding: 24rpx 24rpx 0;
  1174. }
  1175. .manage-action-btn {
  1176. display: flex;
  1177. flex-direction: row;
  1178. align-items: center;
  1179. justify-content: center;
  1180. gap: 12rpx;
  1181. padding: 24rpx 0;
  1182. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  1183. border-radius: 12rpx;
  1184. margin: 0 24rpx;
  1185. }
  1186. .manage-action-icon {
  1187. color: $app-surface;
  1188. font-size: 36rpx;
  1189. font-weight: 300;
  1190. }
  1191. .manage-action-text {
  1192. color: $app-surface;
  1193. font-size: 28rpx;
  1194. font-weight: 600;
  1195. }
  1196. /* Section title */
  1197. .manage-section-title {
  1198. padding: 24rpx 24rpx 12rpx;
  1199. }
  1200. .manage-section-title text {
  1201. font-size: 28rpx;
  1202. font-weight: 600;
  1203. color: $facade-text-strong;
  1204. }
  1205. /* Manage action group in card */
  1206. .manage-action-group {
  1207. display: flex;
  1208. flex-direction: row;
  1209. gap: 16rpx;
  1210. align-items: center;
  1211. }
  1212. .manage-action-small {
  1213. font-size: 22rpx;
  1214. padding: 4rpx 16rpx;
  1215. border-radius: 20rpx;
  1216. background: $brand-primary;
  1217. color: $app-surface;
  1218. font-weight: 500;
  1219. }
  1220. </style>