child-detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 加载状态 -->
  4. <view class="loading-container" v-if="loading">
  5. <text class="loading-text">加载中...</text>
  6. </view>
  7. <template v-if="!loading">
  8. <!-- 儿童信息卡片 -->
  9. <view class="child-info-card">
  10. <view class="child-info-avatar" :class="'child-avatar-color-' + (memberId % 6)">
  11. <text class="child-avatar-text">{{ childName ? childName[0] : '?' }}</text>
  12. </view>
  13. <view class="child-info-body">
  14. <text class="child-info-name">{{ childName }}</text>
  15. <view class="child-info-stats">
  16. <text class="stat-item stat-points">⭐ {{ childInfo.totalPoints || 0 }} 分</text>
  17. <text class="stat-item stat-streak" v-if="childInfo.streakDays > 0">🔥 连续 {{ childInfo.streakDays }} 天</text>
  18. </view>
  19. <view class="child-info-progress" v-if="todayTasks.length > 0">
  20. <text class="progress-label">
  21. 今日任务 {{ completedCount }}/{{ todayTasks.length }} 完成
  22. </text>
  23. <view class="progress-bar-bg">
  24. <view class="progress-bar-fill" :style="{ width: taskProgressPercent + '%' }"></view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 操作区 -->
  30. <view class="action-section">
  31. <view class="section-title">快捷操作</view>
  32. <view class="action-grid">
  33. <view class="action-btn" @click="goToCreateTask">
  34. <view class="action-btn-icon create-icon">📝</view>
  35. <text class="action-btn-label">创建任务</text>
  36. </view>
  37. <view class="action-btn" @click="goToWishReview">
  38. <view class="action-btn-icon wish-icon">💝</view>
  39. <text class="action-btn-label">心愿审核</text>
  40. <text class="action-btn-badge" v-if="pendingWishCount > 0">{{ pendingWishCount }}</text>
  41. </view>
  42. <view class="action-btn" @click="goToGrowth">
  43. <view class="action-btn-icon growth-icon">📊</view>
  44. <text class="action-btn-label">成长记录</text>
  45. </view>
  46. <view class="action-btn" @click="goToCompletionStats">
  47. <view class="action-btn-icon stats-icon">📈</view>
  48. <text class="action-btn-label">完成分析</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 今日任务 -->
  53. <view class="tasks-section">
  54. <view class="section-title">今日任务</view>
  55. <view class="tasks-card" v-if="todayTasks.length > 0">
  56. <view
  57. class="task-item"
  58. v-for="task in todayTasks"
  59. :key="task.id"
  60. >
  61. <text class="task-status-icon">{{ task.status === 'completed' ? '✅' : '⏳' }}</text>
  62. <view class="task-info">
  63. <text class="task-title">{{ task.title }}</text>
  64. <text class="task-points" v-if="task.points">+{{ task.points }}CF</text>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="empty-card" v-else>
  69. <text class="empty-icon">🎉</text>
  70. <text class="empty-text">今日暂无任务</text>
  71. </view>
  72. </view>
  73. <!-- 待处理 -->
  74. <view class="pending-section">
  75. <view class="section-title">待处理</view>
  76. <view class="pending-card" v-if="pendingReviewTasks.length > 0 || pendingWishes.length > 0">
  77. <view
  78. class="pending-item"
  79. v-for="task in pendingReviewTasks"
  80. :key="task.id"
  81. >
  82. <text class="pending-icon">📋</text>
  83. <text class="pending-desc">{{ task.title }}</text>
  84. <text class="pending-tag tag-review">待审核</text>
  85. </view>
  86. <view
  87. class="pending-item"
  88. v-for="wish in pendingWishes"
  89. :key="wish.id"
  90. >
  91. <text class="pending-icon">💝</text>
  92. <text class="pending-desc">{{ wish.title }}</text>
  93. <text class="pending-tag tag-wish">{{ wish.status === 'draft' ? '待定价' : '待审批' }}</text>
  94. </view>
  95. </view>
  96. <view class="empty-card" v-else>
  97. <text class="empty-icon">✅</text>
  98. <text class="empty-text">全部已处理</text>
  99. </view>
  100. </view>
  101. </template>
  102. </view>
  103. </template>
  104. <script>
  105. import { getChildren, getTodayTasks, getPendingReviewTasks, getPendingWishes } from '../../utils/api.js'
  106. import fontScaleMixin from '@/mixins/font-scale.js'
  107. export default {
  108. mixins: [fontScaleMixin],
  109. data() {
  110. return {
  111. loading: true,
  112. memberId: '',
  113. childName: '',
  114. childInfo: {},
  115. todayTasks: [],
  116. pendingReviewTasks: [],
  117. pendingWishes: []
  118. }
  119. },
  120. computed: {
  121. completedCount() {
  122. return this.todayTasks.filter(t => t.status === 'completed').length
  123. },
  124. taskProgressPercent() {
  125. if (this.todayTasks.length === 0) return 0
  126. return Math.round((this.completedCount / this.todayTasks.length) * 100)
  127. },
  128. pendingWishCount() {
  129. return this.pendingWishes.length
  130. }
  131. },
  132. onLoad(options) {
  133. this.memberId = options.memberId || ''
  134. this.childName = options.childName ? decodeURIComponent(options.childName) : '成员'
  135. this.loadChildData()
  136. },
  137. methods: {
  138. async loadChildData() {
  139. this.loading = true
  140. try {
  141. // 获取儿童信息
  142. const childrenRes = await getChildren()
  143. const children = childrenRes.data || []
  144. const matched = children.find(c => String(c.id) === String(this.memberId))
  145. if (matched) {
  146. this.childInfo = matched
  147. if (!this.childName || this.childName === '成员') {
  148. this.childName = matched.nickname || matched.name || '成员'
  149. }
  150. }
  151. // 并行加载今日任务和待处理
  152. const [tasksRes, reviewRes, wishRes] = await Promise.all([
  153. getTodayTasks(this.memberId),
  154. getPendingReviewTasks(),
  155. getPendingWishes()
  156. ])
  157. this.todayTasks = tasksRes.data || []
  158. // 过滤属于该儿童的待审核任务
  159. const allReviewTasks = reviewRes.data || []
  160. this.pendingReviewTasks = allReviewTasks.filter(t => {
  161. return String(t.memberId || t.assigneeId) === String(this.memberId)
  162. }).slice(0, 5)
  163. // 过滤属于该儿童的待处理心愿
  164. const allWishes = wishRes.data || []
  165. this.pendingWishes = allWishes.filter(w => String(w.memberId) === String(this.memberId)).slice(0, 5)
  166. } catch (e) {
  167. console.error('加载成员详情失败', e)
  168. uni.showToast({ title: '加载失败', icon: 'none' })
  169. } finally {
  170. this.loading = false
  171. }
  172. },
  173. goToCreateTask() {
  174. uni.navigateTo({
  175. url: '/pages/tasks/create-task?memberId=' + this.memberId
  176. })
  177. },
  178. goToWishReview() {
  179. uni.navigateTo({
  180. url: '/pages/parent/wishes/index?memberId=' + this.memberId
  181. })
  182. },
  183. goToGrowth() {
  184. uni.switchTab({ url: '/pages/growth-main/index' })
  185. },
  186. goToCompletionStats() {
  187. uni.navigateTo({
  188. url: '/pages/stats/completion-rate?memberId=' + this.memberId
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped lang="scss">
  195. // ===== 成员详情页专属色阶(flat 图表青绿 + 米白卡片;单页专用,约定见 uni.scss §14)=====
  196. $flat-bg: $flat-bg; // 页面米白底
  197. $flat-card: $flat-card; // 暖白卡片底
  198. $flat-line: $flat-line; // 暖分隔线
  199. $flat-ink: $flat-ink; // 主文字(深灰)
  200. $flat-muted: $flat-muted; // 次要文字(灰)
  201. $flat-muted-2: $flat-muted-2; // 辅助文字(中灰)
  202. $c-cd-orange: #FF7A2E; // 橙渐变终档
  203. $flat-teal: $flat-teal; // 青绿主色
  204. $flat-teal-deep: $flat-teal-deep; // 青绿深档
  205. $flat-green: $flat-green; // 绿浅档
  206. $flat-green-deep: $flat-green-deep; // 绿深档
  207. $c-cd-pink: #F093FB; // 粉紫渐变起
  208. $c-cd-red: #F5576C; // 红粉渐变终
  209. $c-cd-danger-bg: $status-danger-tint-5; // 警示浅红底
  210. .container {
  211. padding: $uni-space-page;
  212. background: $flat-bg;
  213. min-height: 100vh;
  214. }
  215. .loading-container {
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. padding: 200rpx 0;
  220. }
  221. .loading-text {
  222. font-size: calc(28rpx * var(--font-scale, 1));
  223. color: $flat-muted;
  224. }
  225. /* 儿童信息卡片 */
  226. .child-info-card {
  227. display: flex;
  228. align-items: flex-start;
  229. background: $app-surface;
  230. border-radius: 24rpx;
  231. padding: 24rpx;
  232. margin-bottom: 32rpx;
  233. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  234. }
  235. .child-info-avatar {
  236. width: 72rpx;
  237. height: 72rpx;
  238. border-radius: 50%;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. flex-shrink: 0;
  243. margin-right: 16rpx;
  244. }
  245. .child-avatar-text {
  246. font-size: calc(32rpx * var(--font-scale, 1));
  247. font-weight: 600;
  248. color: $app-surface;
  249. }
  250. .child-avatar-color-0 { background: linear-gradient(135deg, $dim-body, $c-cd-orange); }
  251. .child-avatar-color-1 { background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep); }
  252. .child-avatar-color-2 { background: linear-gradient(135deg, $flat-teal, $flat-teal-deep); }
  253. .child-avatar-color-3 { background: linear-gradient(135deg, $brand-primary, $brand-primary-light); }
  254. .child-avatar-color-4 { background: linear-gradient(135deg, $flat-green, $flat-green-deep); }
  255. .child-avatar-color-5 { background: linear-gradient(135deg, $c-cd-pink, $c-cd-red); }
  256. .child-info-body {
  257. flex: 1;
  258. min-width: 0;
  259. }
  260. .child-info-name {
  261. font-size: calc(36rpx * var(--font-scale, 1));
  262. font-weight: 700;
  263. color: $flat-ink;
  264. display: block;
  265. }
  266. .child-info-stats {
  267. display: flex;
  268. flex-wrap: wrap;
  269. gap: 12rpx;
  270. margin-top: 12rpx;
  271. }
  272. .stat-item {
  273. font-size: calc(24rpx * var(--font-scale, 1));
  274. font-weight: 500;
  275. }
  276. .stat-points { color: $dim-body; }
  277. .stat-dan { color: $accent-indigo; }
  278. .stat-streak { color: $brand-primary; }
  279. .child-info-progress {
  280. margin-top: 16rpx;
  281. }
  282. .progress-label {
  283. font-size: calc(22rpx * var(--font-scale, 1));
  284. color: $flat-muted-2;
  285. display: block;
  286. margin-bottom: 8rpx;
  287. }
  288. .progress-bar-bg {
  289. height: 10rpx;
  290. background: $flat-card;
  291. border-radius: 999rpx;
  292. overflow: hidden;
  293. }
  294. .progress-bar-fill {
  295. height: 100%;
  296. background: linear-gradient(90deg, $flat-teal, $flat-teal-deep);
  297. border-radius: 999rpx;
  298. transition: width 0.3s ease;
  299. }
  300. /* 区块标题 */
  301. .section-title {
  302. font-size: calc(30rpx * var(--font-scale, 1));
  303. font-weight: 600;
  304. color: $flat-ink;
  305. margin-bottom: 20rpx;
  306. }
  307. /* 操作区 */
  308. .action-section {
  309. margin-bottom: 40rpx;
  310. }
  311. .action-grid {
  312. display: flex;
  313. flex-wrap: wrap;
  314. }
  315. .action-btn {
  316. width: 50%;
  317. box-sizing: border-box;
  318. background: $app-surface;
  319. border-radius: 24rpx;
  320. padding: 24rpx 16rpx;
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  325. position: relative;
  326. border: 8rpx solid $flat-bg;
  327. }
  328. .action-btn-icon {
  329. width: 72rpx;
  330. height: 72rpx;
  331. border-radius: 24rpx;
  332. display: flex;
  333. align-items: center;
  334. justify-content: center;
  335. font-size: calc(36rpx * var(--font-scale, 1));
  336. margin-bottom: 12rpx;
  337. }
  338. .create-icon { background: rgba(255, 140, 66, 0.15); }
  339. .wish-icon { background: rgba(255, 107, 107, 0.15); }
  340. .growth-icon { background: rgba(78, 205, 196, 0.15); }
  341. .stats-icon { background: rgba(255, 217, 61, 0.15); }
  342. .action-btn-label {
  343. font-size: calc(24rpx * var(--font-scale, 1));
  344. color: $flat-muted-2;
  345. font-weight: 500;
  346. }
  347. .action-btn-badge {
  348. position: absolute;
  349. top: 12rpx;
  350. right: 12rpx;
  351. background: $brand-primary;
  352. color: $app-surface;
  353. font-size: calc(20rpx * var(--font-scale, 1));
  354. min-width: 32rpx;
  355. height: 32rpx;
  356. line-height: 32rpx;
  357. text-align: center;
  358. border-radius: 16rpx;
  359. padding: 0 8rpx;
  360. }
  361. /* 今日任务 */
  362. .tasks-section {
  363. margin-bottom: 40rpx;
  364. }
  365. .tasks-card {
  366. background: $app-surface;
  367. border-radius: 24rpx;
  368. padding: 8rpx 24rpx;
  369. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  370. }
  371. .task-item {
  372. display: flex;
  373. align-items: center;
  374. padding: 20rpx 0;
  375. border-bottom: 1rpx solid $flat-line;
  376. }
  377. .task-item:last-child {
  378. border-bottom: none;
  379. }
  380. .task-status-icon {
  381. font-size: calc(32rpx * var(--font-scale, 1));
  382. margin-right: 16rpx;
  383. }
  384. .task-info {
  385. flex: 1;
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: center;
  389. }
  390. .task-title {
  391. font-size: calc(28rpx * var(--font-scale, 1));
  392. color: $flat-ink;
  393. }
  394. .task-points {
  395. font-size: calc(24rpx * var(--font-scale, 1));
  396. color: $dim-body;
  397. font-weight: 600;
  398. }
  399. .empty-card {
  400. background: $app-surface;
  401. border-radius: 24rpx;
  402. padding: 48rpx;
  403. display: flex;
  404. flex-direction: column;
  405. align-items: center;
  406. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  407. }
  408. .empty-icon {
  409. font-size: calc(48rpx * var(--font-scale, 1));
  410. margin-bottom: 12rpx;
  411. }
  412. .empty-text {
  413. font-size: calc(28rpx * var(--font-scale, 1));
  414. color: $flat-muted;
  415. }
  416. /* 待处理 */
  417. .pending-section {
  418. margin-bottom: 48rpx;
  419. }
  420. .pending-card {
  421. background: $app-surface;
  422. border-radius: 24rpx;
  423. padding: 8rpx 24rpx;
  424. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  425. }
  426. .pending-item {
  427. display: flex;
  428. align-items: center;
  429. padding: 20rpx 0;
  430. border-bottom: 1rpx solid $flat-line;
  431. }
  432. .pending-item:last-child {
  433. border-bottom: none;
  434. }
  435. .pending-icon {
  436. font-size: calc(32rpx * var(--font-scale, 1));
  437. margin-right: 16rpx;
  438. }
  439. .pending-desc {
  440. flex: 1;
  441. font-size: calc(28rpx * var(--font-scale, 1));
  442. color: $flat-ink;
  443. }
  444. .pending-tag {
  445. font-size: calc(22rpx * var(--font-scale, 1));
  446. padding: 4rpx 14rpx;
  447. border-radius: 24rpx;
  448. font-weight: 500;
  449. }
  450. .tag-review {
  451. background: $flat-card;
  452. color: $dim-body;
  453. }
  454. .tag-wish {
  455. background: $c-cd-danger-bg;
  456. color: $brand-primary;
  457. }
  458. </style>