child-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <view class="container">
  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-' + (childId % 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 }}分</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. export default {
  107. data() {
  108. return {
  109. loading: true,
  110. childId: '',
  111. childName: '',
  112. childInfo: {},
  113. todayTasks: [],
  114. pendingReviewTasks: [],
  115. pendingWishes: []
  116. }
  117. },
  118. computed: {
  119. completedCount() {
  120. return this.todayTasks.filter(t => t.status === 'completed').length
  121. },
  122. taskProgressPercent() {
  123. if (this.todayTasks.length === 0) return 0
  124. return Math.round((this.completedCount / this.todayTasks.length) * 100)
  125. },
  126. pendingWishCount() {
  127. return this.pendingWishes.length
  128. }
  129. },
  130. onLoad(options) {
  131. this.childId = options.childId || ''
  132. this.childName = options.childName ? decodeURIComponent(options.childName) : '孩子'
  133. this.loadChildData()
  134. },
  135. methods: {
  136. async loadChildData() {
  137. this.loading = true
  138. try {
  139. // 获取孩子信息
  140. const childrenRes = await getChildren()
  141. const children = childrenRes.data || []
  142. const matched = children.find(c => String(c.id) === String(this.childId))
  143. if (matched) {
  144. this.childInfo = matched
  145. if (!this.childName || this.childName === '孩子') {
  146. this.childName = matched.nickname || matched.name || '孩子'
  147. }
  148. }
  149. // 并行加载今日任务和待处理
  150. const [tasksRes, reviewRes, wishRes] = await Promise.all([
  151. getTodayTasks(this.childId),
  152. getPendingReviewTasks(),
  153. getPendingWishes()
  154. ])
  155. this.todayTasks = tasksRes.data || []
  156. // 过滤属于该孩子的待审核任务
  157. const allReviewTasks = reviewRes.data || []
  158. this.pendingReviewTasks = allReviewTasks.filter(t => {
  159. return String(t.childId || t.assigneeId) === String(this.childId)
  160. }).slice(0, 5)
  161. // 过滤属于该孩子的待处理心愿
  162. const allWishes = wishRes.data || []
  163. this.pendingWishes = allWishes.filter(w => String(w.childId) === String(this.childId)).slice(0, 5)
  164. } catch (e) {
  165. console.error('加载孩子详情失败', e)
  166. uni.showToast({ title: '加载失败', icon: 'none' })
  167. } finally {
  168. this.loading = false
  169. }
  170. },
  171. goToCreateTask() {
  172. uni.navigateTo({
  173. url: '/pages/tasks/create-task?childId=' + this.childId
  174. })
  175. },
  176. goToWishReview() {
  177. uni.navigateTo({
  178. url: '/pages/parent/wishes/index?childId=' + this.childId
  179. })
  180. },
  181. goToGrowth() {
  182. uni.navigateTo({
  183. url: '/pages/growth/index?childId=' + this.childId
  184. })
  185. },
  186. goToCompletionStats() {
  187. uni.navigateTo({
  188. url: '/pages/stats/completion-rate?childId=' + this.childId
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. .container {
  196. padding: 30rpx;
  197. background: #FFF9F0;
  198. min-height: 100vh;
  199. }
  200. .loading-container {
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. padding: 200rpx 0;
  205. }
  206. .loading-text {
  207. font-size: 28rpx;
  208. color: #B2BEC3;
  209. }
  210. /* 孩子信息卡片 */
  211. .child-info-card {
  212. display: flex;
  213. align-items: flex-start;
  214. background: #FFFFFF;
  215. border-radius: 24rpx;
  216. padding: 24rpx;
  217. margin-bottom: 32rpx;
  218. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  219. }
  220. .child-info-avatar {
  221. width: 72rpx;
  222. height: 72rpx;
  223. border-radius: 50%;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. flex-shrink: 0;
  228. margin-right: 16rpx;
  229. }
  230. .child-avatar-text {
  231. font-size: 32rpx;
  232. font-weight: 600;
  233. color: #FFFFFF;
  234. }
  235. .child-avatar-color-0 { background: linear-gradient(135deg, #FF8C42, #FF7A2E); }
  236. .child-avatar-color-1 { background: linear-gradient(135deg, #667eea, #764ba2); }
  237. .child-avatar-color-2 { background: linear-gradient(135deg, #4ECDC4, #44B09E); }
  238. .child-avatar-color-3 { background: linear-gradient(135deg, #F97316, #FB923C); }
  239. .child-avatar-color-4 { background: linear-gradient(135deg, #A8E063, #56AB2F); }
  240. .child-avatar-color-5 { background: linear-gradient(135deg, #F093FB, #F5576C); }
  241. .child-info-body {
  242. flex: 1;
  243. min-width: 0;
  244. }
  245. .child-info-name {
  246. font-size: 36rpx;
  247. font-weight: 700;
  248. color: #2D3436;
  249. display: block;
  250. }
  251. .child-info-stats {
  252. display: flex;
  253. flex-wrap: wrap;
  254. gap: 12rpx;
  255. margin-top: 12rpx;
  256. }
  257. .stat-item {
  258. font-size: 24rpx;
  259. font-weight: 500;
  260. }
  261. .stat-points { color: #FF8C42; }
  262. .stat-dan { color: #667eea; }
  263. .stat-streak { color: #F97316; }
  264. .child-info-progress {
  265. margin-top: 16rpx;
  266. }
  267. .progress-label {
  268. font-size: 22rpx;
  269. color: #636E72;
  270. display: block;
  271. margin-bottom: 8rpx;
  272. }
  273. .progress-bar-bg {
  274. height: 10rpx;
  275. background: #FFF5EB;
  276. border-radius: 9999rpx;
  277. overflow: hidden;
  278. }
  279. .progress-bar-fill {
  280. height: 100%;
  281. background: linear-gradient(90deg, #4ECDC4, #44B09E);
  282. border-radius: 9999rpx;
  283. transition: width 0.3s ease;
  284. }
  285. /* 区块标题 */
  286. .section-title {
  287. font-size: 30rpx;
  288. font-weight: 600;
  289. color: #2D3436;
  290. margin-bottom: 20rpx;
  291. }
  292. /* 操作区 */
  293. .action-section {
  294. margin-bottom: 40rpx;
  295. }
  296. .action-grid {
  297. display: flex;
  298. flex-wrap: wrap;
  299. }
  300. .action-btn {
  301. width: 50%;
  302. box-sizing: border-box;
  303. background: #FFFFFF;
  304. border-radius: 20rpx;
  305. padding: 24rpx 16rpx;
  306. display: flex;
  307. flex-direction: column;
  308. align-items: center;
  309. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  310. position: relative;
  311. border: 8rpx solid #FFF9F0;
  312. }
  313. .action-btn-icon {
  314. width: 72rpx;
  315. height: 72rpx;
  316. border-radius: 20rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. font-size: 36rpx;
  321. margin-bottom: 12rpx;
  322. }
  323. .create-icon { background: rgba(255, 140, 66, 0.15); }
  324. .wish-icon { background: rgba(255, 107, 107, 0.15); }
  325. .growth-icon { background: rgba(78, 205, 196, 0.15); }
  326. .stats-icon { background: rgba(255, 217, 61, 0.15); }
  327. .action-btn-label {
  328. font-size: 24rpx;
  329. color: #636E72;
  330. font-weight: 500;
  331. }
  332. .action-btn-badge {
  333. position: absolute;
  334. top: 12rpx;
  335. right: 12rpx;
  336. background: #F97316;
  337. color: #FFFFFF;
  338. font-size: 20rpx;
  339. min-width: 32rpx;
  340. height: 32rpx;
  341. line-height: 32rpx;
  342. text-align: center;
  343. border-radius: 16rpx;
  344. padding: 0 8rpx;
  345. }
  346. /* 今日任务 */
  347. .tasks-section {
  348. margin-bottom: 40rpx;
  349. }
  350. .tasks-card {
  351. background: #FFFFFF;
  352. border-radius: 20rpx;
  353. padding: 8rpx 24rpx;
  354. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  355. }
  356. .task-item {
  357. display: flex;
  358. align-items: center;
  359. padding: 20rpx 0;
  360. border-bottom: 1rpx solid #F5F0EB;
  361. }
  362. .task-item:last-child {
  363. border-bottom: none;
  364. }
  365. .task-status-icon {
  366. font-size: 32rpx;
  367. margin-right: 16rpx;
  368. }
  369. .task-info {
  370. flex: 1;
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. }
  375. .task-title {
  376. font-size: 28rpx;
  377. color: #2D3436;
  378. }
  379. .task-points {
  380. font-size: 24rpx;
  381. color: #FF8C42;
  382. font-weight: 600;
  383. }
  384. .empty-card {
  385. background: #FFFFFF;
  386. border-radius: 20rpx;
  387. padding: 48rpx;
  388. display: flex;
  389. flex-direction: column;
  390. align-items: center;
  391. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  392. }
  393. .empty-icon {
  394. font-size: 48rpx;
  395. margin-bottom: 12rpx;
  396. }
  397. .empty-text {
  398. font-size: 28rpx;
  399. color: #B2BEC3;
  400. }
  401. /* 待处理 */
  402. .pending-section {
  403. margin-bottom: 48rpx;
  404. }
  405. .pending-card {
  406. background: #FFFFFF;
  407. border-radius: 20rpx;
  408. padding: 8rpx 24rpx;
  409. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  410. }
  411. .pending-item {
  412. display: flex;
  413. align-items: center;
  414. padding: 20rpx 0;
  415. border-bottom: 1rpx solid #F5F0EB;
  416. }
  417. .pending-item:last-child {
  418. border-bottom: none;
  419. }
  420. .pending-icon {
  421. font-size: 32rpx;
  422. margin-right: 16rpx;
  423. }
  424. .pending-desc {
  425. flex: 1;
  426. font-size: 28rpx;
  427. color: #2D3436;
  428. }
  429. .pending-tag {
  430. font-size: 22rpx;
  431. padding: 4rpx 14rpx;
  432. border-radius: 20rpx;
  433. font-weight: 500;
  434. }
  435. .tag-review {
  436. background: #FFF5EB;
  437. color: #FF8C42;
  438. }
  439. .tag-wish {
  440. background: #FFF0F0;
  441. color: #F97316;
  442. }
  443. </style>