child-detail.vue 12 KB

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