child-detail.vue 12 KB

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