parent-index.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. <template>
  2. <view class="container">
  3. <!-- 加载状态 -->
  4. <BaseLoading :loading="loading" text="正在加载..." />
  5. <template v-if="!loading">
  6. <!-- ===== a) 顶部 Banner ===== -->
  7. <PageBanner theme="home"
  8. tagline="家庭健康成长俱乐部"
  9. quote="给全家的一站式幸福提案" />
  10. <!-- ===== b) 孩子卡片 ===== -->
  11. <view class="children-row animate-fade-in animate-stagger-2">
  12. <template v-if="children.length > 0">
  13. <scroll-view
  14. class="children-scroll"
  15. scroll-x
  16. :scroll-with-animation="true"
  17. :enhanced="true"
  18. :show-scrollbar="false"
  19. >
  20. <PlayfulCard
  21. v-for="child in children"
  22. :key="child.id"
  23. variant="flat"
  24. shadow="sm"
  25. :clickable="true"
  26. class="child-card"
  27. :class="{ 'child-card-single': children.length === 1 }"
  28. @click="goToChildDetail(child)"
  29. >
  30. <view class="child-card-inner">
  31. <view class="child-avatar" :class="'child-avatar-color-' + (child.id % 6)">
  32. <text class="child-avatar-text">{{ child.nickname ? child.nickname[0] : '?' }}</text>
  33. </view>
  34. <view class="child-card-body">
  35. <text class="child-card-name">{{ child.nickname }}</text>
  36. <view class="child-card-stats">
  37. <text class="child-card-points">⭐ {{ child.totalPoints || 0 }}</text>
  38. <text class="child-card-dan" v-if="child.danLevel">DAN{{ child.danLevel }}</text>
  39. </view>
  40. <view class="child-card-badges">
  41. <BaseBadge variant="primary" size="xs" v-if="child.pendingReviewCount > 0">待审 {{ child.pendingReviewCount }}</BaseBadge>
  42. <BaseBadge variant="error" size="xs" v-if="child.pendingWishCount > 0">心愿 {{ child.pendingWishCount }}</BaseBadge>
  43. </view>
  44. </view>
  45. <view class="child-card-arrow">›</view>
  46. </view>
  47. </PlayfulCard>
  48. </scroll-view>
  49. <view class="scroll-hint" v-if="children.length > 1">
  50. <text class="scroll-hint-text">← 左右滑动查看更多 →</text>
  51. </view>
  52. </template>
  53. <PlayfulCard
  54. v-else
  55. variant="flat"
  56. :clickable="true"
  57. @click="goToAddChild"
  58. class="empty-children-card"
  59. padding="28rpx"
  60. >
  61. <view class="empty-children-inner">
  62. <view class="empty-children-icon">👶</view>
  63. <view class="empty-children-text">
  64. <text class="empty-children-title">还没有添加孩子</text>
  65. <text class="empty-children-hint">点击添加孩子,开始成长之旅</text>
  66. </view>
  67. <view class="empty-children-arrow">›</view>
  68. </view>
  69. </PlayfulCard>
  70. </view>
  71. <!-- 五行能量沙盘(浠艾福 — 全家庭版) -->
  72. <view class="animate-fade-in animate-stagger-3">
  73. <wuxing-sandbox mode="live"
  74. :scores="energyScores"
  75. :overall-score="energyOverall"
  76. :members="energyMembers"
  77. :dimensions="energyDimensions"
  78. :total-energy="totalEnergy"
  79. :total-health-index="totalHealthIndex"
  80. @point-click="goToDomain" />
  81. </view>
  82. <!-- 会员Banner(浠艾福俱乐部) -->
  83. <view class="membership-wrapper animate-fade-in animate-stagger-4">
  84. <view class="membership-banner" @click="goToMembership">
  85. <view class="banner-content">
  86. <text class="banner-icon">👑</text>
  87. <view class="banner-text">
  88. <text class="banner-title">{{ membershipText }}</text>
  89. <text class="banner-subtitle">点击查看会员权益</text>
  90. </view>
  91. <text class="banner-arrow">›</text>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- ===== c) 成长数据 ===== -->
  96. <view class="stats-section animate-fade-in animate-stagger-5">
  97. <view class="section-title">成长数据</view>
  98. <view class="stats-grid">
  99. <PlayfulCard variant="flat" shadow="sm" :clickable="true" @click="goToCompletionStats" class="stat-card" padding="0">
  100. <view class="stat-card-content">
  101. <view class="stat-header">
  102. <view class="stat-icon-wrap stat-icon-orange">
  103. <text class="stat-icon-symbol">📋</text>
  104. </view>
  105. <view class="stat-body">
  106. <text class="stat-value accent-color">{{ taskCompletionRate }}%</text>
  107. <text class="stat-label">任务完成</text>
  108. </view>
  109. </view>
  110. <view class="stat-progress">
  111. <view class="progress-bar">
  112. <view class="progress-fill" :style="{ width: taskCompletionRate + '%' }"></view>
  113. </view>
  114. </view>
  115. <text class="stat-more">查看分析 ›</text>
  116. </view>
  117. </PlayfulCard>
  118. <PlayfulCard variant="flat" shadow="sm" class="stat-card" padding="0">
  119. <view class="stat-card-content">
  120. <view class="stat-header">
  121. <view class="stat-icon-wrap stat-icon-gold">
  122. <text class="stat-icon-symbol">⭐</text>
  123. </view>
  124. <view class="stat-body">
  125. <text class="stat-value gold-color">{{ (selectedChild && selectedChild.totalPoints) || 0 }}</text>
  126. <text class="stat-label">成长积分</text>
  127. </view>
  128. </view>
  129. <text class="stat-encourage">太棒了!</text>
  130. </view>
  131. </PlayfulCard>
  132. <PlayfulCard variant="flat" shadow="sm" class="stat-card" padding="0">
  133. <view class="stat-card-content">
  134. <view class="stat-header">
  135. <view class="stat-icon-wrap stat-icon-red">
  136. <text class="stat-icon-symbol">🔥</text>
  137. </view>
  138. <view class="stat-body">
  139. <text class="stat-value red-color">{{ (selectedChild && selectedChild.streakDays) || 0 }}</text>
  140. <text class="stat-label">连续天数</text>
  141. </view>
  142. </view>
  143. <text class="stat-encourage" v-if="selectedChild && selectedChild.streakDays > 0">加油保持!</text>
  144. <text class="stat-encourage muted" v-else>开始坚持吧</text>
  145. </view>
  146. </PlayfulCard>
  147. <PlayfulCard variant="flat" shadow="sm" class="stat-card" padding="0">
  148. <view class="stat-card-content">
  149. <view class="stat-header">
  150. <view class="stat-icon-wrap stat-icon-teal">
  151. <text class="stat-icon-symbol">✨</text>
  152. </view>
  153. <view class="stat-body">
  154. <text class="stat-value teal-color">{{ habitCount }}</text>
  155. <text class="stat-label">习惯打卡</text>
  156. </view>
  157. </view>
  158. <text class="stat-encourage">坚持就是胜利</text>
  159. </view>
  160. </PlayfulCard>
  161. </view>
  162. </view>
  163. <!-- ===== d) 今日重点 ===== -->
  164. <view class="today-section animate-fade-in animate-stagger-6">
  165. <view class="section-title">今日重点</view>
  166. <PlayfulCard variant="flat" class="today-card">
  167. <template slot="header">
  168. <view class="today-header">
  169. <text class="today-label">今日待完成</text>
  170. <text class="today-count">{{ pendingTasks.length }}项任务</text>
  171. </view>
  172. </template>
  173. <view class="task-list" v-if="pendingTasks.length > 0">
  174. <view class="task-item" v-for="task in pendingTasks.slice(0, 3)" :key="task.id">
  175. <view class="task-dot" :class="'dot-color-' + (task.id % 5)"></view>
  176. <text class="task-title">{{ task.title }}</text>
  177. </view>
  178. </view>
  179. <BaseEmpty v-else icon="🎉" title="今日任务已完成" description="太棒了!" :compact="true" />
  180. <view slot="actions" class="task-view-all" @click="goToTaskList">
  181. <text>查看全部</text>
  182. <text class="arrow">→</text>
  183. </view>
  184. </PlayfulCard>
  185. </view>
  186. <!-- ===== e) 成长里程碑 ===== -->
  187. <view class="milestone-section animate-fade-in animate-stagger-7">
  188. <view class="section-title">成长里程碑</view>
  189. <PlayfulCard variant="flat" class="milestone-card">
  190. <view class="milestone-item" v-if="selectedChild && selectedChild.streakDays >= 7">
  191. <view class="milestone-icon-wrap milestone-star">
  192. <text class="milestone-icon">🌟</text>
  193. </view>
  194. <text class="milestone-text">连续7天打卡</text>
  195. </view>
  196. <view class="milestone-item" v-if="selectedChild && selectedChild.streakDays >= 30">
  197. <view class="milestone-icon-wrap milestone-trophy">
  198. <text class="milestone-icon">🏆</text>
  199. </view>
  200. <text class="milestone-text">坚持一个月啦!</text>
  201. </view>
  202. <view class="milestone-item" v-if="(selectedChild && selectedChild.totalPoints) >= 1000">
  203. <view class="milestone-icon-wrap milestone-sparkle">
  204. <text class="milestone-icon">💫</text>
  205. </view>
  206. <text class="milestone-text">积分突破1000</text>
  207. </view>
  208. <BaseEmpty v-if="!hasMilestones" icon="🌱" title="开始养成好习惯" description="见证成长" :compact="true" />
  209. </PlayfulCard>
  210. </view>
  211. <!-- ===== f) 待处理事项 ===== -->
  212. <view class="pending-section animate-fade-in animate-stagger-8">
  213. <view class="section-title">📋 待处理事项</view>
  214. <view class="pending-grid">
  215. <view class="pending-card" @click="goToReview">
  216. <view class="pending-icon pending-icon--blue">
  217. <text class="pending-emoji">📝</text>
  218. </view>
  219. <view class="pending-info">
  220. <text class="pending-count accent-color">{{ pendingReviewTasks.length }}</text>
  221. <text class="pending-label">待审核任务</text>
  222. </view>
  223. </view>
  224. <view class="pending-card" @click="goToWishApprove">
  225. <view class="pending-icon pending-icon--pink">
  226. <text class="pending-emoji">💝</text>
  227. </view>
  228. <view class="pending-info">
  229. <text class="pending-count pink-color">{{ pendingReviewWishes.length }}</text>
  230. <text class="pending-label">待审批心愿</text>
  231. </view>
  232. </view>
  233. <view class="pending-card" @click="goToAssessmentReport">
  234. <view class="pending-icon pending-icon--green">
  235. <text class="pending-emoji">📊</text>
  236. </view>
  237. <view class="pending-info">
  238. <text class="pending-count teal-color">{{ hasNewReport ? '有新' : '暂无' }}</text>
  239. <text class="pending-label">最新测评报告</text>
  240. </view>
  241. </view>
  242. <view class="pending-card" @click="goToActivities">
  243. <view class="pending-icon pending-icon--orange">
  244. <text class="pending-emoji">🎉</text>
  245. </view>
  246. <view class="pending-info">
  247. <text class="pending-count orange-color">{{ hotActivityCount > 0 ? hotActivityCount : '暂无' }}</text>
  248. <text class="pending-label">活动推荐</text>
  249. </view>
  250. </view>
  251. </view>
  252. </view>
  253. <!-- ===== g) 成长建议 ===== -->
  254. <view class="advice-section animate-fade-in animate-stagger-9" v-if="growthAdvice.length > 0">
  255. <view class="section-title">💡 成长建议</view>
  256. <PlayfulCard variant="flat" class="advice-card" v-for="advice in growthAdvice" :key="advice.id" padding="0">
  257. <view class="advice-content">
  258. <view class="advice-icon-wrap">
  259. <text class="advice-icon">💡</text>
  260. </view>
  261. <view class="advice-text-wrap">
  262. <text class="advice-title">{{ advice.title }}</text>
  263. <text class="advice-desc">{{ advice.summary || advice.description }}</text>
  264. </view>
  265. <text class="advice-arrow">›</text>
  266. </view>
  267. </PlayfulCard>
  268. </view>
  269. <!-- ===== h) 待审核任务 ===== -->
  270. <view class="review-section animate-fade-in animate-stagger-10" v-if="pendingReviewTasks.length > 0">
  271. <view class="section-title">待审核任务</view>
  272. <PlayfulCard
  273. variant="flat"
  274. shadow="sm"
  275. class="review-card"
  276. v-for="task in pendingReviewTasks"
  277. :key="task.id"
  278. padding="0"
  279. >
  280. <view class="review-card-content">
  281. <view class="review-info">
  282. <text class="task-name">{{ task.title }}</text>
  283. <text class="task-child" v-if="task.childName">提供者: {{ task.childName }}</text>
  284. </view>
  285. <view class="review-actions">
  286. <PlayfulButton variant="success" size="xs" @click="approveTask(task.id)">通过</PlayfulButton>
  287. <PlayfulButton variant="error" size="xs" @click="rejectTask(task.id)">拒绝</PlayfulButton>
  288. </view>
  289. </view>
  290. </PlayfulCard>
  291. </view>
  292. <!-- ===== g) 快捷操作 ===== -->
  293. <view class="quick-section animate-fade-in animate-stagger-9">
  294. <view class="section-title">快捷操作</view>
  295. <PlayfulCard variant="flat" class="quick-card">
  296. <view class="quick-actions">
  297. <view class="action-item" @click="addTask">
  298. <view class="action-icon act-add">
  299. <text class="action-icon-text">➕</text>
  300. </view>
  301. <text class="action-label">添加任务</text>
  302. </view>
  303. <view class="action-item" @click="goToReview">
  304. <view class="action-icon act-review">
  305. <text class="action-icon-text">📋</text>
  306. </view>
  307. <text class="action-label">审核任务</text>
  308. </view>
  309. <view class="action-item" @click="manageChildren">
  310. <view class="action-icon act-child">
  311. <text class="action-icon-text">👨‍👩‍👧</text>
  312. </view>
  313. <text class="action-label">孩子管理</text>
  314. </view>
  315. <view class="action-item" @click="goToRewards">
  316. <view class="action-icon act-reward">
  317. <text class="action-icon-text">🎁</text>
  318. </view>
  319. <text class="action-label">奖励中心</text>
  320. </view>
  321. <view class="action-item" @click="inviteFriend">
  322. <view class="action-icon act-invite">
  323. <text class="action-icon-text">📤</text>
  324. </view>
  325. <text class="action-label">邀请家人</text>
  326. </view>
  327. </view>
  328. </PlayfulCard>
  329. </view>
  330. </template>
  331. </view>
  332. </template>
  333. <script>
  334. import { getFamilyMembers, getChildren, getPendingReviewTasks, getPendingWishes, approveTask, rejectTask, getChildCompletionStats, getParentDashboard, getFamilyEnergySandbox, getEnergyOverview } from '../../utils/api.js'
  335. import PageBanner from '../../components/PageBanner.vue'
  336. import WuxingSandbox from '../../components/wuxing-sandbox.vue'
  337. import PlayfulCard from '../../components/PlayfulCard.vue'
  338. import PlayfulButton from '../../components/PlayfulButton.vue'
  339. import BaseBadge from '../../components/BaseBadge.vue'
  340. import BaseEmpty from '../../components/BaseEmpty.vue'
  341. import BaseLoading from '../../components/BaseLoading.vue'
  342. export default {
  343. components: { PageBanner, WuxingSandbox, PlayfulCard, PlayfulButton, BaseBadge, BaseEmpty, BaseLoading },
  344. data() {
  345. return {
  346. nickname: '',
  347. familyMembers: [],
  348. children: [],
  349. selectedChild: null,
  350. pendingReviewTasks: [],
  351. pendingReviewWishes: [],
  352. pendingWishesCount: 0,
  353. pendingTasks: [],
  354. hotActivityCount: 0,
  355. hasNewReport: false,
  356. growthAdvice: [],
  357. taskCompletionRate: 0,
  358. habitCount: 0,
  359. membershipText: '开通家庭会员 畅享全部权益',
  360. loading: true,
  361. currentChildId: '',
  362. _initialLoadDone: false,
  363. _familyId: null,
  364. energyData: null,
  365. energyDimensions: [],
  366. totalEnergy: 0,
  367. totalHealthIndex: 0
  368. }
  369. },
  370. computed: {
  371. energyScores() {
  372. var d = this.energyData
  373. if (!d) return { body: 0, mind: 0, wisdom: 0, action: 0, wealth: 0 }
  374. return { body: d.bodyScore, mind: d.mindScore, wisdom: d.wisdomScore, action: d.actionScore, wealth: d.wealthScore }
  375. },
  376. energyOverall() {
  377. return this.energyData ? this.energyData.overallScore : 0
  378. },
  379. energyMembers() {
  380. return this.energyData ? this.energyData.members : []
  381. },
  382. greetingText() {
  383. const hour = new Date().getHours()
  384. if (hour < 6) return '夜深了'
  385. if (hour < 9) return '早上好'
  386. if (hour < 12) return '上午好'
  387. if (hour < 14) return '中午好'
  388. if (hour < 18) return '下午好'
  389. if (hour < 22) return '晚上好'
  390. return '夜深了'
  391. },
  392. hasMilestones() {
  393. const c = this.selectedChild
  394. if (!c) return false
  395. return (c.streakDays >= 7) || (c.streakDays >= 30) || (c.totalPoints >= 1000)
  396. }
  397. },
  398. // 使用 mounted 而非 onLoad,因为本组件作为条件渲染子组件(v-if),
  399. // page 生命周期钩子(onLoad/onShow)可能在组件挂载前已触发完毕
  400. mounted() {
  401. if (!uni.getStorageSync('token')) {
  402. uni.reLaunch({ url: '/pages/login/login' })
  403. return
  404. }
  405. this.loadData()
  406. },
  407. onShow() {
  408. // 首次 onShow 紧接 mounted 之后,跳过避免双重加载
  409. if (!this._initialLoadDone) {
  410. this._initialLoadDone = true
  411. return
  412. }
  413. const currentRole = uni.getStorageSync('currentRole') || 'parent'
  414. if (currentRole === 'child') {
  415. uni.reLaunch({ url: '/pages/index/child-index' })
  416. return
  417. }
  418. if (uni.getStorageSync('token')) {
  419. this.loadData()
  420. }
  421. },
  422. methods: {
  423. async loadData() {
  424. this.loading = true
  425. try {
  426. const userInfo = uni.getStorageSync('userInfo')
  427. this.nickname = (userInfo && userInfo.nickname) ? userInfo.nickname : ''
  428. // 优先使用仪表盘接口(包含孩子列表 + 统计数据)
  429. let dashboardLoaded = false
  430. try {
  431. const dashRes = await getParentDashboard()
  432. const dashData = dashRes.data || {}
  433. const dashChildren = dashData.children || []
  434. // 过滤:仅保留孩子角色成员,排除家长/本人
  435. var currentUserId = uni.getStorageSync('userId')
  436. var filteredChildren = dashChildren.filter(function(c) {
  437. return c && c.id && c.id !== currentUserId && (c.role === 'child' || c.memberType === 'child' || !c.role)
  438. })
  439. if (filteredChildren.length > 0) {
  440. this.children = filteredChildren
  441. this.selectedChild = filteredChildren[0]
  442. this.taskCompletionRate = dashData.avgCompletionRate || 0
  443. this.habitCount = dashData.totalHabitCount || 0
  444. // 从仪表盘获取 familyId
  445. if (dashData.familyId) {
  446. this._familyId = dashData.familyId
  447. }
  448. dashboardLoaded = true
  449. }
  450. } catch (e) {
  451. console.log('获取仪表盘数据失败,降级到单独接口', e)
  452. }
  453. // 降级:使用原有单独接口
  454. if (!dashboardLoaded) {
  455. try {
  456. const currentUserId = uni.getStorageSync('userId')
  457. const membersRes = await getFamilyMembers()
  458. const data = membersRes.data || {}
  459. const parents = (data.parents || []).filter(function(p) { return p && p.id && p.id !== currentUserId }).map(function(p) { return { ...p, role: 'parent' } })
  460. const children = (data.children || []).filter(function(c) { return c && c.id }).map(function(c) { return { ...c, role: 'child' } })
  461. this.familyMembers = [].concat(parents, children)
  462. if (children.length > 0) {
  463. this.selectedChild = children[0]
  464. }
  465. // 保存 familyId 用于后续请求
  466. if (data.familyId) {
  467. this._familyId = data.familyId
  468. }
  469. } catch (e) {
  470. console.log('获取家庭成员失败', e)
  471. }
  472. if (this.children.length === 0) {
  473. const childrenRes = await getChildren()
  474. const rawChildren = childrenRes.data || []
  475. this.children = rawChildren
  476. if (this.children.length > 0 && !this.selectedChild) {
  477. this.selectedChild = this.children[0]
  478. }
  479. }
  480. }
  481. const reviewRes = await getPendingReviewTasks()
  482. const allReviewTasks = reviewRes.data || []
  483. this.pendingReviewTasks = allReviewTasks.slice(0, 3)
  484. try {
  485. const wishRes = await getPendingWishes(this._familyId)
  486. this.pendingReviewWishes = wishRes.data || []
  487. } catch (e) {
  488. console.log('获取待处理心愿失败', e)
  489. this.pendingReviewWishes = []
  490. }
  491. const reviewMap = {}
  492. const wishMap = {}
  493. for (let i = 0; i < allReviewTasks.length; i++) {
  494. const task = allReviewTasks[i]
  495. const cid = task.childId || task.assigneeId
  496. if (cid) {
  497. reviewMap[cid] = (reviewMap[cid] || 0) + 1
  498. }
  499. }
  500. for (let j = 0; j < (this.pendingReviewWishes || []).length; j++) {
  501. const wish = this.pendingReviewWishes[j]
  502. const cid = wish.childId
  503. if (cid) {
  504. wishMap[cid] = (wishMap[cid] || 0) + 1
  505. }
  506. }
  507. this.children = this.children.map(function(c) {
  508. return {
  509. ...c,
  510. pendingReviewCount: reviewMap[c.id] || 0,
  511. pendingWishCount: wishMap[c.id] || 0
  512. }
  513. })
  514. // 如果仪表盘未加载到数据,降级到单独统计接口
  515. if (!dashboardLoaded && this.children.length > 0) {
  516. const targetChild = this.selectedChild || this.children[0]
  517. try {
  518. const statsRes = await getChildCompletionStats({ childId: targetChild.id })
  519. if (statsRes && statsRes.data) {
  520. this.taskCompletionRate = statsRes.data.completionRate || 0
  521. this.habitCount = statsRes.data.completedTasks || 0
  522. }
  523. } catch (e) {
  524. console.log('获取完成率失败', e)
  525. this.taskCompletionRate = 0
  526. }
  527. }
  528. // 待完成任务 - 使用真实统计中的pendingTasks
  529. this.pendingTasks = []
  530. if (this.children.length > 0) {
  531. const targetChild = this.selectedChild || this.children[0]
  532. try {
  533. const r2 = await getChildCompletionStats({ childId: targetChild.id })
  534. if (r2 && r2.data && r2.data.pendingTasks > 0) {
  535. for (let k = 0; k < Math.min(r2.data.pendingTasks, 3); k++) {
  536. this.pendingTasks.push({ id: 100 + k, title: '待完成任务 ' + (k + 1) })
  537. }
  538. }
  539. } catch (e) {
  540. this.pendingTasks = []
  541. }
  542. }
  543. // 加载家庭能量沙盘数据(五维 + 所有成员)
  544. try {
  545. const energyRes = await getFamilyEnergySandbox()
  546. this.energyData = energyRes.data || null
  547. } catch (e) {
  548. console.log('获取能量沙盘数据失败', e)
  549. this.energyData = null
  550. }
  551. // 加载五维能量概览(账本模式)
  552. var overviewChildId = this.currentChildId
  553. if (overviewChildId) {
  554. try {
  555. var overviewRes = await getEnergyOverview(overviewChildId)
  556. if (overviewRes && overviewRes.data) {
  557. this.energyDimensions = overviewRes.data.dimensions || []
  558. this.totalEnergy = overviewRes.data.totalEnergy || 0
  559. this.totalHealthIndex = overviewRes.data.totalHealthIndex || 0
  560. }
  561. } catch (e) {
  562. console.log('获取能量概览失败', e)
  563. }
  564. }
  565. } catch (e) {
  566. console.error('加载数据失败', e)
  567. } finally {
  568. this.loading = false
  569. }
  570. },
  571. async approveTask(taskId) {
  572. try {
  573. await approveTask(taskId)
  574. uni.showToast({ title: '已通过', icon: 'success' })
  575. this.loadData()
  576. } catch (e) {
  577. uni.showToast({ title: '操作失败', icon: 'none' })
  578. }
  579. },
  580. async rejectTask(taskId) {
  581. try {
  582. await rejectTask(taskId)
  583. uni.showToast({ title: '已拒绝', icon: 'success' })
  584. this.loadData()
  585. } catch (e) {
  586. uni.showToast({ title: '操作失败', icon: 'none' })
  587. }
  588. },
  589. goToCompletionStats() {
  590. if (this.children.length === 1) {
  591. uni.navigateTo({ url: '/pages/stats/completion-rate?childId=' + this.children[0].id })
  592. } else {
  593. uni.navigateTo({ url: '/pages/stats/completion-rate?familyView=1' })
  594. }
  595. },
  596. goToDomain(code) {
  597. // 跳转到能量详情页(T10 创建)
  598. var childId = this.currentChildId
  599. if (!childId || !code) return
  600. uni.navigateTo({
  601. url: '/pages/energy/detail?childId=' + childId + '&code=' + code
  602. })
  603. },
  604. goToMembership() {
  605. uni.showToast({ title: '即将上线', icon: 'none' })
  606. },
  607. goToChildDetail(child) {
  608. uni.navigateTo({ url: '/pages/parent/child-detail?childId=' + child.id + '&childName=' + encodeURIComponent(child.nickname || '') })
  609. },
  610. addTask() { uni.navigateTo({ url: '/pages/tasks/create-task' }) },
  611. goToReview() { uni.navigateTo({ url: '/pages/tasks/review' }) },
  612. goToWishApprove() { uni.navigateTo({ url: '/pages/wishes/approve' }) },
  613. goToAssessmentReport() { uni.navigateTo({ url: '/pages/assessment/report' }) },
  614. goToActivities() { uni.switchTab({ url: '/pages/discover/index' }) },
  615. goToRewards() { uni.switchTab({ url: '/pages/rewards/rewards' }) },
  616. goToTaskList() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  617. manageChildren() { uni.navigateTo({ url: '/pages/profile/children' }) },
  618. inviteFriend() { uni.navigateTo({ url: '/pages/parent/invite/index' }) },
  619. goToAddChild() { uni.navigateTo({ url: '/pages/profile/create-child' }) }
  620. }
  621. }
  622. </script>
  623. <style scoped>
  624. /* ========================================
  625. Flat Card Design System — 家长端暖橙扁平
  626. ======================================== */
  627. .container {
  628. padding: 32rpx;
  629. background: var(--bg, #F5F9FC);
  630. min-height: 100vh;
  631. }
  632. /* ========================================
  633. 区块标题
  634. ======================================== */
  635. .section-title {
  636. font-size: 32rpx;
  637. font-weight: 700;
  638. color: var(--text, #1E293B);
  639. margin-bottom: var(--space-md);
  640. }
  641. /* ========================================
  642. b) 孩子卡片
  643. ======================================== */
  644. .children-row {
  645. margin-bottom: 48rpx;
  646. }
  647. .children-scroll {
  648. display: flex;
  649. flex-direction: row;
  650. white-space: nowrap;
  651. overflow: hidden;
  652. }
  653. .child-card {
  654. display: inline-flex !important;
  655. margin-right: 16rpx;
  656. min-width: 320rpx;
  657. width: auto;
  658. }
  659. .child-card-single {
  660. width: 100%;
  661. margin-right: 0;
  662. }
  663. .child-card-inner {
  664. display: flex;
  665. align-items: center;
  666. width: 100%;
  667. }
  668. .child-avatar {
  669. width: 80rpx;
  670. height: 80rpx;
  671. border-radius: var(--radius-full, 50%);
  672. display: flex;
  673. align-items: center;
  674. justify-content: center;
  675. flex-shrink: 0;
  676. }
  677. .child-avatar-color-0 { background: linear-gradient(135deg, var(--color-primary, #5B9BD5), var(--color-primary-dark, #3A7CC4)); }
  678. .child-avatar-color-1 { background: linear-gradient(135deg, var(--color-accent, #0EA5E9), #6366F1); }
  679. .child-avatar-color-2 { background: linear-gradient(135deg, #10B981, #059669); }
  680. .child-avatar-color-3 { background: linear-gradient(135deg, #EC4899, #E11D48); }
  681. .child-avatar-color-4 { background: linear-gradient(135deg, #84CC16, #65A30D); }
  682. .child-avatar-color-5 { background: linear-gradient(135deg, #8B5CF6, #6D28D9); }
  683. .child-avatar-text {
  684. color: #FFFFFF;
  685. font-size: 36rpx;
  686. font-weight: 600;
  687. }
  688. .child-card-body {
  689. flex: 1;
  690. margin-left: 16rpx;
  691. min-width: 0;
  692. }
  693. .child-card-name {
  694. font-size: 30rpx;
  695. font-weight: 600;
  696. color: var(--text, #1E293B);
  697. display: block;
  698. line-height: 1.3;
  699. }
  700. .child-card-stats {
  701. display: flex;
  702. align-items: center;
  703. margin-top: 6rpx;
  704. gap: 16rpx;
  705. }
  706. .child-card-points {
  707. font-size: 24rpx;
  708. color: var(--color-primary, #5B9BD5);
  709. font-weight: 600;
  710. }
  711. .child-card-dan {
  712. font-size: 22rpx;
  713. color: var(--color-accent, #0EA5E9);
  714. font-weight: 500;
  715. }
  716. .child-card-badges {
  717. display: flex;
  718. gap: 8rpx;
  719. margin-top: 8rpx;
  720. flex-wrap: wrap;
  721. }
  722. .child-card-arrow {
  723. font-size: 36rpx;
  724. color: var(--muted, #94A3B8);
  725. margin-left: 8rpx;
  726. flex-shrink: 0;
  727. }
  728. .scroll-hint {
  729. text-align: center;
  730. margin-top: 12rpx;
  731. }
  732. .scroll-hint-text {
  733. font-size: 22rpx;
  734. color: var(--muted, #94A3B8);
  735. }
  736. /* Empty children */
  737. .empty-children-card {
  738. margin-top: 24rpx;
  739. }
  740. .empty-children-inner {
  741. display: flex;
  742. align-items: center;
  743. }
  744. .empty-children-icon {
  745. font-size: 56rpx;
  746. margin-right: 16rpx;
  747. }
  748. .empty-children-text {
  749. flex: 1;
  750. }
  751. .empty-children-title {
  752. font-size: 28rpx;
  753. font-weight: 600;
  754. color: var(--text, #1E293B);
  755. display: block;
  756. }
  757. .empty-children-hint {
  758. font-size: 24rpx;
  759. color: var(--muted, #94A3B8);
  760. margin-top: 6rpx;
  761. display: block;
  762. }
  763. .empty-children-arrow {
  764. font-size: 36rpx;
  765. color: var(--muted, #94A3B8);
  766. }
  767. /* ========================================
  768. WuxingSandbox & Membership Wrappers
  769. ======================================== */
  770. .membership-wrapper {
  771. margin-bottom: 48rpx;
  772. }
  773. /* 浠艾福俱乐部 - 会员Banner */
  774. .membership-banner {
  775. padding: 30rpx 32rpx;
  776. background: linear-gradient(135deg, #FFD700, #FFA500);
  777. border-radius: var(--radius-md, 20rpx);
  778. box-shadow: var(--shadow-md);
  779. }
  780. .banner-content {
  781. display: flex;
  782. align-items: center;
  783. }
  784. .banner-icon {
  785. font-size: 60rpx;
  786. margin-right: 20rpx;
  787. }
  788. .banner-text {
  789. flex: 1;
  790. }
  791. .banner-title {
  792. font-size: 30rpx;
  793. font-weight: bold;
  794. color: #8B4513;
  795. display: block;
  796. }
  797. .banner-subtitle {
  798. font-size: 24rpx;
  799. color: #A0522D;
  800. margin-top: 6rpx;
  801. display: block;
  802. }
  803. .banner-arrow {
  804. font-size: 40rpx;
  805. color: #8B4513;
  806. }
  807. /* ========================================
  808. c) 成长数据
  809. ======================================== */
  810. .stats-section {
  811. margin-bottom: 48rpx;
  812. }
  813. .stats-grid {
  814. display: flex;
  815. flex-wrap: wrap;
  816. gap: 16rpx;
  817. }
  818. .stat-card {
  819. width: calc(50% - 8rpx);
  820. box-sizing: border-box;
  821. }
  822. .stat-card-content {
  823. padding: 24rpx;
  824. }
  825. .stat-header {
  826. display: flex;
  827. align-items: center;
  828. margin-bottom: 14rpx;
  829. }
  830. .stat-icon-wrap {
  831. width: 56rpx;
  832. height: 56rpx;
  833. border-radius: var(--radius-sm, 12rpx);
  834. display: flex;
  835. align-items: center;
  836. justify-content: center;
  837. margin-right: 14rpx;
  838. flex-shrink: 0;
  839. }
  840. .stat-icon-symbol {
  841. font-size: 28rpx;
  842. }
  843. .stat-icon-orange { background: rgba(91, 155, 213, 0.12); }
  844. .stat-icon-gold { background: rgba(245, 158, 11, 0.15); }
  845. .stat-icon-red { background: rgba(239, 68, 68, 0.12); }
  846. .stat-icon-teal { background: rgba(16, 185, 129, 0.12); }
  847. .stat-body {
  848. flex: 1;
  849. min-width: 0;
  850. }
  851. .stat-value {
  852. font-size: 40rpx;
  853. font-weight: 800;
  854. display: block;
  855. line-height: 1.1;
  856. }
  857. .stat-label {
  858. font-size: 22rpx;
  859. color: var(--text-secondary, #64748B);
  860. display: block;
  861. margin-top: 4rpx;
  862. }
  863. .accent-color { color: var(--color-primary, #5B9BD5); }
  864. .gold-color { color: #F59E0B; }
  865. .red-color { color: var(--color-error, #EF4444); }
  866. .teal-color { color: #10B981; }
  867. .stat-progress {
  868. margin-bottom: 10rpx;
  869. }
  870. .progress-bar {
  871. height: 8rpx;
  872. background: var(--border-light, #E2E8F0);
  873. border-radius: 999rpx;
  874. overflow: hidden;
  875. }
  876. .progress-fill {
  877. height: 100%;
  878. background: linear-gradient(90deg, var(--color-primary, #5B9BD5), #F59E0B);
  879. border-radius: 999rpx;
  880. transition: width 0.3s ease;
  881. }
  882. .stat-more {
  883. font-size: 22rpx;
  884. color: var(--color-accent, #0EA5E9);
  885. font-weight: 500;
  886. display: block;
  887. }
  888. .stat-encourage {
  889. font-size: 22rpx;
  890. color: #10B981;
  891. font-weight: 500;
  892. margin-top: 10rpx;
  893. display: block;
  894. }
  895. .stat-encourage.muted {
  896. color: var(--muted, #94A3B8);
  897. }
  898. /* ========================================
  899. d) 今日重点
  900. ======================================== */
  901. .today-section {
  902. margin-bottom: 48rpx;
  903. }
  904. .today-card .today-header {
  905. display: flex;
  906. justify-content: space-between;
  907. align-items: center;
  908. }
  909. .today-label {
  910. font-size: 28rpx;
  911. font-weight: 600;
  912. color: var(--text, #1E293B);
  913. }
  914. .today-count {
  915. font-size: 24rpx;
  916. color: var(--color-primary, #5B9BD5);
  917. font-weight: 600;
  918. }
  919. .task-list {
  920. margin-bottom: 8rpx;
  921. }
  922. .task-item {
  923. display: flex;
  924. align-items: center;
  925. padding: 18rpx 0;
  926. border-bottom: 1rpx solid var(--border-light, #E2E8F0);
  927. }
  928. .task-item:last-child {
  929. border-bottom: none;
  930. }
  931. .task-dot {
  932. width: 14rpx;
  933. height: 14rpx;
  934. border-radius: 50%;
  935. margin-right: 16rpx;
  936. flex-shrink: 0;
  937. }
  938. .dot-color-0 { background: var(--color-primary, #5B9BD5); }
  939. .dot-color-1 { background: #10B981; }
  940. .dot-color-2 { background: var(--color-accent, #0EA5E9); }
  941. .dot-color-3 { background: #F59E0B; }
  942. .dot-color-4 { background: var(--color-error, #EF4444); }
  943. .task-title {
  944. font-size: 28rpx;
  945. color: var(--text, #1E293B);
  946. }
  947. .task-view-all {
  948. display: flex;
  949. justify-content: flex-end;
  950. align-items: center;
  951. color: var(--text-secondary, #64748B);
  952. font-size: 24rpx;
  953. padding-top: 16rpx;
  954. border-top: 1rpx solid var(--border-light, #E2E8F0);
  955. }
  956. .task-view-all .arrow {
  957. margin-left: 8rpx;
  958. }
  959. /* ========================================
  960. e) 成长里程碑
  961. ======================================== */
  962. .milestone-section {
  963. margin-bottom: 48rpx;
  964. }
  965. .milestone-card {
  966. padding: 24rpx !important;
  967. }
  968. .milestone-item {
  969. display: flex;
  970. align-items: center;
  971. padding: 16rpx 0;
  972. border-bottom: 1rpx solid var(--border-light, #E2E8F0);
  973. }
  974. .milestone-item:last-child {
  975. border-bottom: none;
  976. }
  977. .milestone-icon-wrap {
  978. width: 56rpx;
  979. height: 56rpx;
  980. border-radius: var(--radius-sm, 12rpx);
  981. display: flex;
  982. align-items: center;
  983. justify-content: center;
  984. margin-right: 16rpx;
  985. flex-shrink: 0;
  986. }
  987. .milestone-icon {
  988. font-size: 28rpx;
  989. }
  990. .milestone-star { background: rgba(245, 158, 11, 0.15); }
  991. .milestone-trophy { background: rgba(91, 155, 213, 0.12); }
  992. .milestone-sparkle { background: rgba(16, 185, 129, 0.12); }
  993. .milestone-text {
  994. font-size: 28rpx;
  995. color: var(--text, #1E293B);
  996. }
  997. /* ========================================
  998. f) 待处理事项
  999. ======================================== */
  1000. .pending-section { margin-bottom: 48rpx; }
  1001. .pending-grid { display: flex; flex-wrap: wrap; gap: 16rpx; }
  1002. .pending-card {
  1003. width: calc(50% - 8rpx);
  1004. background: #fff;
  1005. border-radius: 20rpx;
  1006. padding: 24rpx;
  1007. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  1008. display: flex;
  1009. align-items: center;
  1010. }
  1011. .pending-card:active { opacity: 0.8; }
  1012. .pending-icon {
  1013. width: 72rpx; height: 72rpx;
  1014. border-radius: 16rpx;
  1015. display: flex; align-items: center; justify-content: center;
  1016. margin-right: 16rpx; flex-shrink: 0;
  1017. }
  1018. .pending-icon--blue { background: rgba(91,155,213,0.12); }
  1019. .pending-icon--pink { background: rgba(236,72,153,0.12); }
  1020. .pending-icon--green { background: rgba(16,185,129,0.12); }
  1021. .pending-icon--orange { background: rgba(249,115,22,0.12); }
  1022. .pending-emoji { font-size: 32rpx; }
  1023. .pending-info { flex: 1; min-width: 0; }
  1024. .pending-count { font-size: 36rpx; font-weight: 800; display: block; }
  1025. .pending-label { font-size: 22rpx; color: #666; margin-top: 4rpx; display: block; }
  1026. .pink-color { color: #EC4899; }
  1027. .orange-color { color: #F97316; }
  1028. /* ========================================
  1029. g) 成长建议
  1030. ======================================== */
  1031. .advice-section { margin-bottom: 48rpx; }
  1032. .advice-card { margin-bottom: 12rpx; }
  1033. .advice-content {
  1034. display: flex; align-items: center; padding: 24rpx;
  1035. }
  1036. .advice-icon-wrap {
  1037. width: 56rpx; height: 56rpx;
  1038. border-radius: 14rpx;
  1039. background: rgba(91,155,213,0.1);
  1040. display: flex; align-items: center; justify-content: center;
  1041. margin-right: 16rpx; flex-shrink: 0;
  1042. }
  1043. .advice-icon { font-size: 28rpx; }
  1044. .advice-text-wrap { flex: 1; min-width: 0; }
  1045. .advice-title { font-size: 28rpx; font-weight: 600; color: #333; display: block; }
  1046. .advice-desc { font-size: 24rpx; color: #999; margin-top: 4rpx; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  1047. .advice-arrow { font-size: 36rpx; color: #ccc; margin-left: 12rpx; }
  1048. /* ========================================
  1049. h) 待审核任务
  1050. ======================================== */
  1051. .review-section {
  1052. margin-bottom: 48rpx;
  1053. }
  1054. .review-card {
  1055. margin-bottom: 16rpx;
  1056. }
  1057. .review-card:last-child {
  1058. margin-bottom: 0;
  1059. }
  1060. .review-card-content {
  1061. display: flex;
  1062. justify-content: space-between;
  1063. align-items: center;
  1064. padding: 24rpx;
  1065. }
  1066. .review-info {
  1067. flex: 1;
  1068. min-width: 0;
  1069. }
  1070. .review-info .task-name {
  1071. font-size: 28rpx;
  1072. color: var(--text, #1E293B);
  1073. display: block;
  1074. margin-bottom: 4rpx;
  1075. }
  1076. .review-info .task-child {
  1077. font-size: 22rpx;
  1078. color: var(--muted, #94A3B8);
  1079. }
  1080. .review-actions {
  1081. display: flex;
  1082. gap: 12rpx;
  1083. flex-shrink: 0;
  1084. margin-left: 16rpx;
  1085. }
  1086. /* ========================================
  1087. g) 快捷操作
  1088. ======================================== */
  1089. .quick-section {
  1090. margin-bottom: 48rpx;
  1091. }
  1092. .quick-card {
  1093. padding: 16rpx 12rpx !important;
  1094. }
  1095. .quick-actions {
  1096. display: flex;
  1097. flex-wrap: wrap;
  1098. }
  1099. .action-item {
  1100. display: flex;
  1101. flex-direction: column;
  1102. align-items: center;
  1103. width: 20%;
  1104. margin-bottom: 12rpx;
  1105. transition: transform 0.15s ease;
  1106. }
  1107. .action-item:active {
  1108. transform: scale(0.92);
  1109. }
  1110. .action-icon {
  1111. width: 80rpx;
  1112. height: 80rpx;
  1113. border-radius: var(--radius-sm, 12rpx);
  1114. display: flex;
  1115. align-items: center;
  1116. justify-content: center;
  1117. margin-bottom: 10rpx;
  1118. }
  1119. .action-icon-text {
  1120. font-size: 32rpx;
  1121. }
  1122. .act-add { background: rgba(91, 155, 213, 0.12); }
  1123. .act-review { background: rgba(16, 185, 129, 0.12); }
  1124. .act-child { background: rgba(14, 165, 233, 0.12); }
  1125. .act-reward { background: rgba(245, 158, 11, 0.15); }
  1126. .act-invite { background: rgba(139, 92, 246, 0.12); }
  1127. .action-label {
  1128. font-size: 22rpx;
  1129. color: var(--text-secondary, #64748B);
  1130. font-weight: 500;
  1131. text-align: center;
  1132. }
  1133. </style>