child-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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-' + (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 }}分</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. memberId: '',
  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.memberId = options.memberId || ''
  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.memberId))
  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.memberId),
  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.memberId || t.assigneeId) === String(this.memberId)
  160. }).slice(0, 5)
  161. // 过滤属于该孩子的待处理心愿
  162. const allWishes = wishRes.data || []
  163. this.pendingWishes = allWishes.filter(w => String(w.memberId) === String(this.memberId)).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?memberId=' + this.memberId
  174. })
  175. },
  176. goToWishReview() {
  177. uni.navigateTo({
  178. url: '/pages/parent/wishes/index?memberId=' + this.memberId
  179. })
  180. },
  181. goToGrowth() {
  182. uni.switchTab({ url: '/pages/growth-main/index' })
  183. },
  184. goToCompletionStats() {
  185. uni.navigateTo({
  186. url: '/pages/stats/completion-rate?memberId=' + this.memberId
  187. })
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped>
  193. .container {
  194. padding: 30rpx;
  195. background: #FFF9F0;
  196. min-height: 100vh;
  197. }
  198. .loading-container {
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. padding: 200rpx 0;
  203. }
  204. .loading-text {
  205. font-size: 28rpx;
  206. color: #B2BEC3;
  207. }
  208. /* 孩子信息卡片 */
  209. .child-info-card {
  210. display: flex;
  211. align-items: flex-start;
  212. background: #FFFFFF;
  213. border-radius: 24rpx;
  214. padding: 24rpx;
  215. margin-bottom: 32rpx;
  216. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  217. }
  218. .child-info-avatar {
  219. width: 72rpx;
  220. height: 72rpx;
  221. border-radius: 50%;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. flex-shrink: 0;
  226. margin-right: 16rpx;
  227. }
  228. .child-avatar-text {
  229. font-size: 32rpx;
  230. font-weight: 600;
  231. color: #FFFFFF;
  232. }
  233. .child-avatar-color-0 { background: linear-gradient(135deg, #FF8C42, #FF7A2E); }
  234. .child-avatar-color-1 { background: linear-gradient(135deg, #667eea, #764ba2); }
  235. .child-avatar-color-2 { background: linear-gradient(135deg, #4ECDC4, #44B09E); }
  236. .child-avatar-color-3 { background: linear-gradient(135deg, #F97316, #FB923C); }
  237. .child-avatar-color-4 { background: linear-gradient(135deg, #A8E063, #56AB2F); }
  238. .child-avatar-color-5 { background: linear-gradient(135deg, #F093FB, #F5576C); }
  239. .child-info-body {
  240. flex: 1;
  241. min-width: 0;
  242. }
  243. .child-info-name {
  244. font-size: 36rpx;
  245. font-weight: 700;
  246. color: #2D3436;
  247. display: block;
  248. }
  249. .child-info-stats {
  250. display: flex;
  251. flex-wrap: wrap;
  252. gap: 12rpx;
  253. margin-top: 12rpx;
  254. }
  255. .stat-item {
  256. font-size: 24rpx;
  257. font-weight: 500;
  258. }
  259. .stat-points { color: #FF8C42; }
  260. .stat-dan { color: #667eea; }
  261. .stat-streak { color: #F97316; }
  262. .child-info-progress {
  263. margin-top: 16rpx;
  264. }
  265. .progress-label {
  266. font-size: 22rpx;
  267. color: #636E72;
  268. display: block;
  269. margin-bottom: 8rpx;
  270. }
  271. .progress-bar-bg {
  272. height: 10rpx;
  273. background: #FFF5EB;
  274. border-radius: 9999rpx;
  275. overflow: hidden;
  276. }
  277. .progress-bar-fill {
  278. height: 100%;
  279. background: linear-gradient(90deg, #4ECDC4, #44B09E);
  280. border-radius: 9999rpx;
  281. transition: width 0.3s ease;
  282. }
  283. /* 区块标题 */
  284. .section-title {
  285. font-size: 30rpx;
  286. font-weight: 600;
  287. color: #2D3436;
  288. margin-bottom: 20rpx;
  289. }
  290. /* 操作区 */
  291. .action-section {
  292. margin-bottom: 40rpx;
  293. }
  294. .action-grid {
  295. display: flex;
  296. flex-wrap: wrap;
  297. }
  298. .action-btn {
  299. width: 50%;
  300. box-sizing: border-box;
  301. background: #FFFFFF;
  302. border-radius: 20rpx;
  303. padding: 24rpx 16rpx;
  304. display: flex;
  305. flex-direction: column;
  306. align-items: center;
  307. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  308. position: relative;
  309. border: 8rpx solid #FFF9F0;
  310. }
  311. .action-btn-icon {
  312. width: 72rpx;
  313. height: 72rpx;
  314. border-radius: 20rpx;
  315. display: flex;
  316. align-items: center;
  317. justify-content: center;
  318. font-size: 36rpx;
  319. margin-bottom: 12rpx;
  320. }
  321. .create-icon { background: rgba(255, 140, 66, 0.15); }
  322. .wish-icon { background: rgba(255, 107, 107, 0.15); }
  323. .growth-icon { background: rgba(78, 205, 196, 0.15); }
  324. .stats-icon { background: rgba(255, 217, 61, 0.15); }
  325. .action-btn-label {
  326. font-size: 24rpx;
  327. color: #636E72;
  328. font-weight: 500;
  329. }
  330. .action-btn-badge {
  331. position: absolute;
  332. top: 12rpx;
  333. right: 12rpx;
  334. background: #F97316;
  335. color: #FFFFFF;
  336. font-size: 20rpx;
  337. min-width: 32rpx;
  338. height: 32rpx;
  339. line-height: 32rpx;
  340. text-align: center;
  341. border-radius: 16rpx;
  342. padding: 0 8rpx;
  343. }
  344. /* 今日任务 */
  345. .tasks-section {
  346. margin-bottom: 40rpx;
  347. }
  348. .tasks-card {
  349. background: #FFFFFF;
  350. border-radius: 20rpx;
  351. padding: 8rpx 24rpx;
  352. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  353. }
  354. .task-item {
  355. display: flex;
  356. align-items: center;
  357. padding: 20rpx 0;
  358. border-bottom: 1rpx solid #F5F0EB;
  359. }
  360. .task-item:last-child {
  361. border-bottom: none;
  362. }
  363. .task-status-icon {
  364. font-size: 32rpx;
  365. margin-right: 16rpx;
  366. }
  367. .task-info {
  368. flex: 1;
  369. display: flex;
  370. justify-content: space-between;
  371. align-items: center;
  372. }
  373. .task-title {
  374. font-size: 28rpx;
  375. color: #2D3436;
  376. }
  377. .task-points {
  378. font-size: 24rpx;
  379. color: #FF8C42;
  380. font-weight: 600;
  381. }
  382. .empty-card {
  383. background: #FFFFFF;
  384. border-radius: 20rpx;
  385. padding: 48rpx;
  386. display: flex;
  387. flex-direction: column;
  388. align-items: center;
  389. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  390. }
  391. .empty-icon {
  392. font-size: 48rpx;
  393. margin-bottom: 12rpx;
  394. }
  395. .empty-text {
  396. font-size: 28rpx;
  397. color: #B2BEC3;
  398. }
  399. /* 待处理 */
  400. .pending-section {
  401. margin-bottom: 48rpx;
  402. }
  403. .pending-card {
  404. background: #FFFFFF;
  405. border-radius: 20rpx;
  406. padding: 8rpx 24rpx;
  407. box-shadow: 0 4px 20px rgba(255, 140, 66, 0.08);
  408. }
  409. .pending-item {
  410. display: flex;
  411. align-items: center;
  412. padding: 20rpx 0;
  413. border-bottom: 1rpx solid #F5F0EB;
  414. }
  415. .pending-item:last-child {
  416. border-bottom: none;
  417. }
  418. .pending-icon {
  419. font-size: 32rpx;
  420. margin-right: 16rpx;
  421. }
  422. .pending-desc {
  423. flex: 1;
  424. font-size: 28rpx;
  425. color: #2D3436;
  426. }
  427. .pending-tag {
  428. font-size: 22rpx;
  429. padding: 4rpx 14rpx;
  430. border-radius: 20rpx;
  431. font-weight: 500;
  432. }
  433. .tag-review {
  434. background: #FFF5EB;
  435. color: #FF8C42;
  436. }
  437. .tag-wish {
  438. background: #FFF0F0;
  439. color: #F97316;
  440. }
  441. </style>