nutrition-profile.vue 17 KB

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