nutrition-profile.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <template>
  2. <view class="nutrition-profile">
  3. <view class="nav-bar">
  4. <text class="nav-back" @click="goBack">‹ 返回</text>
  5. <text class="nav-title">营养档案</text>
  6. <view class="nav-placeholder"></view>
  7. </view>
  8. <view class="profile-header" v-if="childName">
  9. <view class="child-info">
  10. <text class="child-name">{{ childName }}</text>
  11. <text class="child-age" v-if="childAge">{{ childAge }}岁</text>
  12. </view>
  13. </view>
  14. <view class="score-section" v-if="scores">
  15. <view class="main-score-ring">
  16. <view class="score-ring-outer">
  17. <view class="score-ring-inner">
  18. <text class="score-value">{{ scores.overall || '--' }}</text>
  19. <text class="score-label">综合评分</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="score-items">
  24. <view class="score-item">
  25. <text class="score-num">{{ scores.gutHealth || '--' }}</text>
  26. <text class="score-name">肠道健康</text>
  27. </view>
  28. <view class="score-item">
  29. <text class="score-num">{{ scores.nutrition || '--' }}</text>
  30. <text class="score-name">营养状况</text>
  31. </view>
  32. <view class="score-item">
  33. <text class="score-num">{{ scores.chronicDisease || '--' }}</text>
  34. <text class="score-name">慢病控制</text>
  35. </view>
  36. <view class="score-item">
  37. <text class="score-num">{{ scores.gutBalance || '--' }}</text>
  38. <text class="score-name">菌群平衡</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="empty-state" v-if="!scores && !loading">
  43. <text class="empty-icon">📋</text>
  44. <text class="empty-title">暂无健康报告</text>
  45. <text class="empty-desc">完成首次健康检测后,这里将展示您的营养档案</text>
  46. <view class="empty-btn" @click="goToAssessment">
  47. <text class="empty-btn-text">预约健康检测</text>
  48. </view>
  49. </view>
  50. <view class="section" v-if="abnormalIndicators && abnormalIndicators.length > 0">
  51. <view class="section-title-wrap">
  52. <text class="section-title">⚠️ 需关注指标</text>
  53. <text class="section-count">{{ abnormalIndicators.length }}项</text>
  54. </view>
  55. <view class="indicator-list">
  56. <view class="indicator-item" v-for="item in abnormalIndicators" :key="item.id">
  57. <view class="indicator-left">
  58. <text class="indicator-emoji">{{ getStatusEmoji(item.status) }}</text>
  59. <view class="indicator-info">
  60. <text class="indicator-name">{{ item.indicatorName }}</text>
  61. <text class="indicator-value">{{ item.indicatorValue }}{{ item.unit }} · {{ item.status }}</text>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="section-more" @click="goToIndicators">
  67. <text class="section-more-text">查看全部指标 →</text>
  68. </view>
  69. </view>
  70. <view class="section" v-if="scoreTrend && scoreTrend.length > 1">
  71. <view class="section-title-wrap">
  72. <text class="section-title">📊 变化趋势</text>
  73. </view>
  74. <view class="trend-chart">
  75. <canvas canvas-id="trendCanvas" id="trendCanvas" class="trend-canvas" @touchstart.prevent></canvas>
  76. </view>
  77. <view class="trend-legend">
  78. <view class="legend-item">
  79. <view class="legend-color" style="background:#F97316"></view>
  80. <text class="legend-text">综合评分</text>
  81. </view>
  82. <view class="legend-item">
  83. <view class="legend-color" style="background:#10B981"></view>
  84. <text class="legend-text">肠道健康</text>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="section" v-if="deficiencyRecords && deficiencyRecords.length > 0">
  89. <view class="section-title-wrap">
  90. <text class="section-title">🔬 营养缺乏分析</text>
  91. <text class="section-count">{{ deficiencyRecords.length }}项</text>
  92. </view>
  93. <view class="deficiency-list">
  94. <view class="deficiency-item" v-for="record in deficiencyRecords" :key="record.nutrient">
  95. <view class="deficiency-info">
  96. <text class="deficiency-name">{{ record.nutrient }}</text>
  97. <text class="deficiency-level">{{ getDeficiencyLabel(record) }}</text>
  98. </view>
  99. <view class="deficiency-bar">
  100. <view class="deficiency-fill" :style="{ width: (record.severity * 100) + '%', background: getSeverityColor(record.severity) }"></view>
  101. </view>
  102. <view class="deficiency-foods" v-if="record.foodSuggestions">
  103. <text>推荐食物:{{ record.foodSuggestions }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <view class="section" v-if="latestReports && latestReports.length > 0">
  109. <view class="section-title-wrap">
  110. <text class="section-title">📋 历史报告</text>
  111. </view>
  112. <view class="report-list">
  113. <view class="report-item" v-for="r in latestReports" :key="r.id" @click="goToReport(r.id)">
  114. <view class="report-item-left">
  115. <text class="report-item-type">{{ getReportTypeName(r.reportType) }}</text>
  116. <text class="report-item-date">{{ formatDate(r.reportDate) }}</text>
  117. </view>
  118. <view class="report-item-score">
  119. <text class="report-score-val">{{ r.overallScore || '--' }}</text>
  120. <text class="report-score-label">分</text>
  121. </view>
  122. </view>
  123. </view>
  124. </view>
  125. <view class="bottom-spacer"></view>
  126. <view class="fab" @click="goToAIRecommend" v-if="scores">
  127. <text class="fab-icon">🥗</text>
  128. <text class="fab-text">获取营养方案</text>
  129. </view>
  130. </view>
  131. </template>
  132. <script>
  133. import { getChildNutritionProfile, getDeficiencyAnalysis } from '@/utils/api.js'
  134. export default {
  135. data() {
  136. return {
  137. childId: null,
  138. childName: '',
  139. childAge: '',
  140. childGender: '',
  141. scores: null,
  142. abnormalIndicators: [],
  143. scoreTrend: [],
  144. deficiencyRecords: [],
  145. latestReports: [],
  146. loading: false
  147. }
  148. },
  149. onLoad: function(options) {
  150. this.childId = options.childId ? parseInt(options.childId) : null
  151. if (!this.childId) {
  152. var savedChildId = uni.getStorageSync('currentChildId')
  153. if (savedChildId) this.childId = parseInt(savedChildId)
  154. }
  155. if (this.childId) {
  156. this.loadProfile()
  157. }
  158. },
  159. onReady: function() {
  160. if (this.scoreTrend && this.scoreTrend.length > 1) {
  161. this.drawTrendChart()
  162. }
  163. },
  164. methods: {
  165. loadProfile: function() {
  166. var self = this
  167. self.loading = true
  168. uni.showLoading({ title: '加载中...' })
  169. getChildNutritionProfile(self.childId).then(function(res) {
  170. uni.hideLoading()
  171. self.loading = false
  172. if (res.code === 200 && res.data) {
  173. var d = res.data
  174. self.childName = d.childName || ''
  175. self.childAge = d.childAge || ''
  176. self.childGender = d.childGender || ''
  177. self.scores = d.scores
  178. self.abnormalIndicators = d.abnormalIndicators || []
  179. self.scoreTrend = d.scoreTrend || []
  180. self.latestReports = d.latestReports || []
  181. if (d.nutritionProfile) {
  182. self.nutritionProfile = d.nutritionProfile
  183. }
  184. }
  185. }).catch(function(e) {
  186. uni.hideLoading()
  187. self.loading = false
  188. console.log('加载营养档案失败', e)
  189. })
  190. getDeficiencyAnalysis(self.childId).then(function(res) {
  191. if (res.code === 200 && res.data) {
  192. self.deficiencyRecords = res.data
  193. }
  194. }).catch(function(e) {
  195. console.log('加载缺乏分析失败', e)
  196. })
  197. },
  198. drawTrendChart: function() {
  199. var ctx = uni.createCanvasContext('trendCanvas', this)
  200. var trend = this.scoreTrend
  201. if (!trend || trend.length < 2) return
  202. var cw = 690
  203. var ch = 300
  204. var padding = 40
  205. var xStep = (cw - padding * 2) / (trend.length - 1)
  206. var yMin = 0
  207. var yMax = 100
  208. ctx.setStrokeStyle('#F0F0F0')
  209. ctx.setLineWidth(1)
  210. for (var i = 0; i <= 4; i++) {
  211. var y = padding + (ch - padding * 2) * (i / 4)
  212. ctx.beginPath()
  213. ctx.moveTo(padding, y)
  214. ctx.lineTo(cw - padding, y)
  215. ctx.stroke()
  216. }
  217. var drawLine = function(key, color) {
  218. ctx.setStrokeStyle(color)
  219. ctx.setLineWidth(3)
  220. ctx.beginPath()
  221. for (var j = 0; j < trend.length; j++) {
  222. var val = trend[j][key] || 0
  223. var x = padding + j * xStep
  224. var y = padding + (ch - padding * 2) * (1 - (val - yMin) / (yMax - yMin))
  225. if (j === 0) {
  226. ctx.moveTo(x, y)
  227. } else {
  228. ctx.lineTo(x, y)
  229. }
  230. }
  231. ctx.stroke()
  232. ctx.draw(true)
  233. }
  234. drawLine('overall', '#F97316')
  235. drawLine('gutHealth', '#10B981')
  236. },
  237. getStatusEmoji: function(status) {
  238. if (status === '偏低') return '🔴'
  239. if (status === '偏高') return '🔴'
  240. if (status === '注意') return '🟡'
  241. return '🟢'
  242. },
  243. getDeficiencyLabel: function(record) {
  244. if (record.deficiencyType === 'deficiency') {
  245. if (record.severity >= 0.7) return '严重缺乏'
  246. if (record.severity >= 0.3) return '缺乏'
  247. return '轻度不足'
  248. }
  249. if (record.deficiencyType === 'excess') return '偏高'
  250. if (record.deficiencyType === 'borderline') return '边界值'
  251. return '未分类'
  252. },
  253. getSeverityColor: function(severity) {
  254. if (severity >= 0.7) return '#EF4444'
  255. if (severity >= 0.3) return '#F59E0B'
  256. return '#10B981'
  257. },
  258. getReportTypeName: function(type) {
  259. if (type === 'gut_flora') return '肠道检测'
  260. if (type === 'physical_exam') return '体检报告'
  261. if (type === 'blood') return '血液检测'
  262. return type || '健康报告'
  263. },
  264. formatDate: function(dateStr) {
  265. if (!dateStr) return ''
  266. try {
  267. var d = new Date(dateStr)
  268. var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
  269. var day = ('' + d.getDate()).padStart(2, '0')
  270. return m + '-' + day
  271. } catch (e) {
  272. return dateStr
  273. }
  274. },
  275. goBack: function() {
  276. uni.navigateBack()
  277. },
  278. goToReport: function(id) {
  279. uni.navigateTo({ url: '/pages/body/health-report?reportId=' + id + '&childId=' + this.childId })
  280. },
  281. goToIndicators: function() {
  282. uni.navigateTo({ url: '/pages/body/health-report?childId=' + this.childId })
  283. },
  284. goToAssessment: function() {
  285. uni.navigateTo({ url: '/pages/assessment/apply' })
  286. },
  287. goToAIRecommend: function() {
  288. uni.navigateTo({ url: '/pages/meal/recommend?childId=' + this.childId })
  289. }
  290. }
  291. }
  292. </script>
  293. <style scoped>
  294. .nutrition-profile {
  295. min-height: 100vh;
  296. background: #FFF7ED;
  297. padding-bottom: 40rpx;
  298. }
  299. .nav-bar {
  300. position: sticky;
  301. top: 0;
  302. background: #fff;
  303. display: flex;
  304. flex-direction: row;
  305. align-items: center;
  306. justify-content: space-between;
  307. padding: 20rpx 30rpx;
  308. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  309. z-index: 100;
  310. }
  311. .nav-back {
  312. font-size: 32rpx;
  313. color: #F97316;
  314. }
  315. .nav-title {
  316. font-size: 32rpx;
  317. font-weight: bold;
  318. color: #333;
  319. }
  320. .nav-placeholder {
  321. width: 80rpx;
  322. }
  323. .profile-header {
  324. padding: 40rpx 30rpx 20rpx;
  325. }
  326. .child-info {
  327. display: flex;
  328. flex-direction: column;
  329. }
  330. .child-name {
  331. font-size: 40rpx;
  332. font-weight: bold;
  333. color: #1F2937;
  334. }
  335. .child-age {
  336. font-size: 26rpx;
  337. color: #6B7280;
  338. margin-top: 8rpx;
  339. }
  340. .score-section {
  341. margin: 0 20rpx;
  342. background: white;
  343. border-radius: 24rpx;
  344. padding: 30rpx;
  345. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
  346. }
  347. .main-score-ring {
  348. display: flex;
  349. justify-content: center;
  350. align-items: center;
  351. margin-bottom: 30rpx;
  352. }
  353. .score-ring-outer {
  354. width: 200rpx;
  355. height: 200rpx;
  356. border-radius: 100rpx;
  357. border: 12rpx solid #F97316;
  358. display: flex;
  359. align-items: center;
  360. justify-content: center;
  361. }
  362. .score-ring-inner {
  363. display: flex;
  364. flex-direction: column;
  365. align-items: center;
  366. }
  367. .score-value {
  368. font-size: 56rpx;
  369. font-weight: bold;
  370. color: #F97316;
  371. }
  372. .score-label {
  373. font-size: 24rpx;
  374. color: #9CA3AF;
  375. }
  376. .score-items {
  377. display: flex;
  378. flex-direction: row;
  379. justify-content: space-around;
  380. flex-wrap: wrap;
  381. }
  382. .score-item {
  383. display: flex;
  384. flex-direction: column;
  385. align-items: center;
  386. width: 25%;
  387. }
  388. .score-num {
  389. font-size: 32rpx;
  390. font-weight: bold;
  391. color: #374151;
  392. }
  393. .score-name {
  394. font-size: 22rpx;
  395. color: #9CA3AF;
  396. margin-top: 4rpx;
  397. }
  398. .empty-state {
  399. display: flex;
  400. flex-direction: column;
  401. align-items: center;
  402. padding: 80rpx 30rpx;
  403. }
  404. .empty-icon {
  405. font-size: 80rpx;
  406. }
  407. .empty-title {
  408. font-size: 36rpx;
  409. font-weight: bold;
  410. color: #374151;
  411. margin-top: 20rpx;
  412. }
  413. .empty-desc {
  414. font-size: 28rpx;
  415. color: #9CA3AF;
  416. text-align: center;
  417. margin: 16rpx 0 30rpx;
  418. }
  419. .empty-btn {
  420. background: #F97316;
  421. border-radius: 40rpx;
  422. padding: 20rpx 60rpx;
  423. }
  424. .empty-btn-text {
  425. color: white;
  426. font-size: 28rpx;
  427. }
  428. .section {
  429. background: white;
  430. border-radius: 24rpx;
  431. margin: 20rpx;
  432. padding: 30rpx;
  433. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
  434. }
  435. .section-title-wrap {
  436. display: flex;
  437. flex-direction: row;
  438. align-items: center;
  439. justify-content: space-between;
  440. margin-bottom: 20rpx;
  441. }
  442. .section-title {
  443. font-size: 32rpx;
  444. font-weight: bold;
  445. color: #374151;
  446. }
  447. .section-count {
  448. font-size: 24rpx;
  449. color: #9CA3AF;
  450. }
  451. .indicator-list {
  452. display: flex;
  453. flex-direction: column;
  454. }
  455. .indicator-item {
  456. display: flex;
  457. flex-direction: row;
  458. align-items: center;
  459. justify-content: space-between;
  460. padding: 12rpx 0;
  461. border-bottom: 1rpx solid #F3F4F6;
  462. }
  463. .indicator-item:last-child {
  464. border-bottom: none;
  465. }
  466. .indicator-left {
  467. display: flex;
  468. flex-direction: row;
  469. align-items: center;
  470. }
  471. .indicator-emoji {
  472. font-size: 28rpx;
  473. margin-right: 16rpx;
  474. }
  475. .indicator-info {
  476. display: flex;
  477. flex-direction: column;
  478. }
  479. .indicator-name {
  480. font-size: 28rpx;
  481. color: #374151;
  482. font-weight: 500;
  483. }
  484. .indicator-value {
  485. font-size: 24rpx;
  486. color: #9CA3AF;
  487. margin-top: 4rpx;
  488. }
  489. .section-more {
  490. text-align: center;
  491. padding-top: 20rpx;
  492. }
  493. .section-more-text {
  494. color: #F97316;
  495. font-size: 26rpx;
  496. }
  497. .trend-canvas {
  498. width: 100%;
  499. height: 300rpx;
  500. }
  501. .trend-legend {
  502. display: flex;
  503. flex-direction: row;
  504. justify-content: center;
  505. margin-top: 16rpx;
  506. }
  507. .legend-item {
  508. display: flex;
  509. flex-direction: row;
  510. align-items: center;
  511. margin-left: 30rpx;
  512. }
  513. .legend-item:first-child {
  514. margin-left: 0;
  515. }
  516. .legend-color {
  517. width: 20rpx;
  518. height: 20rpx;
  519. border-radius: 4rpx;
  520. margin-right: 8rpx;
  521. }
  522. .legend-text {
  523. font-size: 24rpx;
  524. color: #6B7280;
  525. }
  526. .deficiency-list {
  527. display: flex;
  528. flex-direction: column;
  529. }
  530. .deficiency-item {
  531. display: flex;
  532. flex-direction: column;
  533. padding: 16rpx 0;
  534. border-bottom: 1rpx solid #F3F4F6;
  535. }
  536. .deficiency-item:last-child {
  537. border-bottom: none;
  538. }
  539. .deficiency-info {
  540. display: flex;
  541. flex-direction: row;
  542. justify-content: space-between;
  543. align-items: center;
  544. margin-bottom: 10rpx;
  545. }
  546. .deficiency-name {
  547. font-size: 28rpx;
  548. color: #374151;
  549. font-weight: 500;
  550. }
  551. .deficiency-level {
  552. font-size: 24rpx;
  553. color: #9CA3AF;
  554. }
  555. .deficiency-bar {
  556. height: 12rpx;
  557. background: #F3F4F6;
  558. border-radius: 6rpx;
  559. overflow: hidden;
  560. }
  561. .deficiency-fill {
  562. height: 100%;
  563. border-radius: 6rpx;
  564. }
  565. .deficiency-foods {
  566. font-size: 22rpx;
  567. color: #6B7280;
  568. margin-top: 8rpx;
  569. }
  570. .report-list {
  571. display: flex;
  572. flex-direction: column;
  573. }
  574. .report-item {
  575. display: flex;
  576. flex-direction: row;
  577. align-items: center;
  578. justify-content: space-between;
  579. padding: 16rpx 0;
  580. border-bottom: 1rpx solid #F3F4F6;
  581. }
  582. .report-item:last-child {
  583. border-bottom: none;
  584. }
  585. .report-item:active {
  586. opacity: 0.7;
  587. }
  588. .report-item-left {
  589. display: flex;
  590. flex-direction: column;
  591. }
  592. .report-item-type {
  593. font-size: 28rpx;
  594. color: #374151;
  595. font-weight: 500;
  596. }
  597. .report-item-date {
  598. font-size: 22rpx;
  599. color: #9CA3AF;
  600. margin-top: 4rpx;
  601. }
  602. .report-item-score {
  603. display: flex;
  604. flex-direction: row;
  605. align-items: baseline;
  606. }
  607. .report-score-val {
  608. font-size: 36rpx;
  609. font-weight: bold;
  610. color: #F97316;
  611. }
  612. .report-score-label {
  613. font-size: 20rpx;
  614. color: #9CA3AF;
  615. margin-left: 4rpx;
  616. }
  617. .fab {
  618. position: fixed;
  619. bottom: 40rpx;
  620. left: 50%;
  621. transform: translateX(-50%);
  622. background: linear-gradient(135deg, #F97316, #FB923C);
  623. color: white;
  624. display: flex;
  625. flex-direction: row;
  626. align-items: center;
  627. padding: 20rpx 40rpx;
  628. border-radius: 50rpx;
  629. box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.4);
  630. z-index: 200;
  631. }
  632. .fab-icon {
  633. font-size: 36rpx;
  634. margin-right: 12rpx;
  635. }
  636. .fab-text {
  637. font-size: 30rpx;
  638. font-weight: 600;
  639. }
  640. .bottom-spacer {
  641. height: 130rpx;
  642. }
  643. </style>