| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- <template>
- <view class="nutrition-profile">
- <view class="nav-bar">
- <text class="nav-back" @click="goBack">‹ 返回</text>
- <text class="nav-title">营养档案</text>
- <view class="nav-placeholder"></view>
- </view>
- <view class="profile-header" v-if="childName">
- <view class="child-info">
- <text class="child-name">{{ childName }}</text>
- <text class="child-age" v-if="childAge">{{ childAge }}岁</text>
- </view>
- </view>
- <view class="score-section" v-if="scores">
- <view class="main-score-ring">
- <view class="score-ring-outer">
- <view class="score-ring-inner">
- <text class="score-value">{{ scores.overall || '--' }}</text>
- <text class="score-label">综合评分</text>
- </view>
- </view>
- </view>
- <view class="score-items">
- <view class="score-item">
- <text class="score-num">{{ scores.gutHealth || '--' }}</text>
- <text class="score-name">肠道健康</text>
- </view>
- <view class="score-item">
- <text class="score-num">{{ scores.nutrition || '--' }}</text>
- <text class="score-name">营养状况</text>
- </view>
- <view class="score-item">
- <text class="score-num">{{ scores.chronicDisease || '--' }}</text>
- <text class="score-name">慢病控制</text>
- </view>
- <view class="score-item">
- <text class="score-num">{{ scores.gutBalance || '--' }}</text>
- <text class="score-name">菌群平衡</text>
- </view>
- </view>
- </view>
- <view class="empty-state" v-if="!scores && !loading">
- <text class="empty-icon">📋</text>
- <text class="empty-title">暂无健康报告</text>
- <text class="empty-desc">完成首次健康检测后,这里将展示您的营养档案</text>
- <view class="empty-btn" @click="goToAssessment">
- <text class="empty-btn-text">预约健康检测</text>
- </view>
- </view>
- <view class="section" v-if="abnormalIndicators && abnormalIndicators.length > 0">
- <view class="section-title-wrap">
- <text class="section-title">⚠️ 需关注指标</text>
- <text class="section-count">{{ abnormalIndicators.length }}项</text>
- </view>
- <view class="indicator-list">
- <view class="indicator-item" v-for="item in abnormalIndicators" :key="item.id">
- <view class="indicator-left">
- <text class="indicator-emoji">{{ getStatusEmoji(item.status) }}</text>
- <view class="indicator-info">
- <text class="indicator-name">{{ item.indicatorName }}</text>
- <text class="indicator-value">{{ item.indicatorValue }}{{ item.unit }} · {{ item.status }}</text>
- </view>
- </view>
- </view>
- </view>
- <view class="section-more" @click="goToIndicators">
- <text class="section-more-text">查看全部指标 →</text>
- </view>
- </view>
- <view class="section" v-if="scoreTrend && scoreTrend.length > 1">
- <view class="section-title-wrap">
- <text class="section-title">📊 变化趋势</text>
- </view>
- <view class="trend-chart">
- <canvas canvas-id="trendCanvas" id="trendCanvas" class="trend-canvas" @touchstart.prevent></canvas>
- </view>
- <view class="trend-legend">
- <view class="legend-item">
- <view class="legend-color" style="background:#F97316"></view>
- <text class="legend-text">综合评分</text>
- </view>
- <view class="legend-item">
- <view class="legend-color" style="background:#10B981"></view>
- <text class="legend-text">肠道健康</text>
- </view>
- </view>
- </view>
- <view class="section" v-if="deficiencyRecords && deficiencyRecords.length > 0">
- <view class="section-title-wrap">
- <text class="section-title">🔬 营养缺乏分析</text>
- <text class="section-count">{{ deficiencyRecords.length }}项</text>
- </view>
- <view class="deficiency-list">
- <view class="deficiency-item" v-for="record in deficiencyRecords" :key="record.nutrient">
- <view class="deficiency-info">
- <text class="deficiency-name">{{ record.nutrient }}</text>
- <text class="deficiency-level">{{ getDeficiencyLabel(record) }}</text>
- </view>
- <view class="deficiency-bar">
- <view class="deficiency-fill" :style="{ width: (record.severity * 100) + '%', background: getSeverityColor(record.severity) }"></view>
- </view>
- <view class="deficiency-foods" v-if="record.foodSuggestions">
- <text>推荐食物:{{ record.foodSuggestions }}</text>
- </view>
- </view>
- </view>
- </view>
- <view class="section" v-if="latestReports && latestReports.length > 0">
- <view class="section-title-wrap">
- <text class="section-title">📋 历史报告</text>
- </view>
- <view class="report-list">
- <view class="report-item" v-for="r in latestReports" :key="r.id" @click="goToReport(r.id)">
- <view class="report-item-left">
- <text class="report-item-type">{{ getReportTypeName(r.reportType) }}</text>
- <text class="report-item-date">{{ formatDate(r.reportDate) }}</text>
- </view>
- <view class="report-item-score">
- <text class="report-score-val">{{ r.overallScore || '--' }}</text>
- <text class="report-score-label">分</text>
- </view>
- </view>
- </view>
- </view>
- <view class="bottom-spacer"></view>
- <view class="fab" @click="goToAIRecommend" v-if="scores">
- <text class="fab-icon">🥗</text>
- <text class="fab-text">获取营养方案</text>
- </view>
- </view>
- </template>
- <script>
- import { getChildNutritionProfile, getDeficiencyAnalysis } from '@/utils/api.js'
- export default {
- data() {
- return {
- childId: null,
- childName: '',
- childAge: '',
- childGender: '',
- scores: null,
- abnormalIndicators: [],
- scoreTrend: [],
- deficiencyRecords: [],
- latestReports: [],
- loading: false
- }
- },
- onLoad: function(options) {
- this.childId = options.childId ? parseInt(options.childId) : null
- if (!this.childId) {
- var savedChildId = uni.getStorageSync('currentChildId')
- if (savedChildId) this.childId = parseInt(savedChildId)
- }
- if (this.childId) {
- this.loadProfile()
- }
- },
- onReady: function() {
- if (this.scoreTrend && this.scoreTrend.length > 1) {
- this.drawTrendChart()
- }
- },
- methods: {
- loadProfile: function() {
- var self = this
- self.loading = true
- uni.showLoading({ title: '加载中...' })
- getChildNutritionProfile(self.childId).then(function(res) {
- uni.hideLoading()
- self.loading = false
- if (res.code === 200 && res.data) {
- var d = res.data
- self.childName = d.childName || ''
- self.childAge = d.childAge || ''
- self.childGender = d.childGender || ''
- self.scores = d.scores
- self.abnormalIndicators = d.abnormalIndicators || []
- self.scoreTrend = d.scoreTrend || []
- self.latestReports = d.latestReports || []
- if (d.nutritionProfile) {
- self.nutritionProfile = d.nutritionProfile
- }
- }
- }).catch(function(e) {
- uni.hideLoading()
- self.loading = false
- console.log('加载营养档案失败', e)
- })
- getDeficiencyAnalysis(self.childId).then(function(res) {
- if (res.code === 200 && res.data) {
- self.deficiencyRecords = res.data
- }
- }).catch(function(e) {
- console.log('加载缺乏分析失败', e)
- })
- },
- drawTrendChart: function() {
- var ctx = uni.createCanvasContext('trendCanvas', this)
- var trend = this.scoreTrend
- if (!trend || trend.length < 2) return
- var cw = 690
- var ch = 300
- var padding = 40
- var xStep = (cw - padding * 2) / (trend.length - 1)
- var yMin = 0
- var yMax = 100
- ctx.setStrokeStyle('#F0F0F0')
- ctx.setLineWidth(1)
- for (var i = 0; i <= 4; i++) {
- var y = padding + (ch - padding * 2) * (i / 4)
- ctx.beginPath()
- ctx.moveTo(padding, y)
- ctx.lineTo(cw - padding, y)
- ctx.stroke()
- }
- var drawLine = function(key, color) {
- ctx.setStrokeStyle(color)
- ctx.setLineWidth(3)
- ctx.beginPath()
- for (var j = 0; j < trend.length; j++) {
- var val = trend[j][key] || 0
- var x = padding + j * xStep
- var y = padding + (ch - padding * 2) * (1 - (val - yMin) / (yMax - yMin))
- if (j === 0) {
- ctx.moveTo(x, y)
- } else {
- ctx.lineTo(x, y)
- }
- }
- ctx.stroke()
- ctx.draw(true)
- }
- drawLine('overall', '#F97316')
- drawLine('gutHealth', '#10B981')
- },
- getStatusEmoji: function(status) {
- if (status === '偏低') return '🔴'
- if (status === '偏高') return '🔴'
- if (status === '注意') return '🟡'
- return '🟢'
- },
- getDeficiencyLabel: function(record) {
- if (record.deficiencyType === 'deficiency') {
- if (record.severity >= 0.7) return '严重缺乏'
- if (record.severity >= 0.3) return '缺乏'
- return '轻度不足'
- }
- if (record.deficiencyType === 'excess') return '偏高'
- if (record.deficiencyType === 'borderline') return '边界值'
- return '未分类'
- },
- getSeverityColor: function(severity) {
- if (severity >= 0.7) return '#EF4444'
- if (severity >= 0.3) return '#F59E0B'
- return '#10B981'
- },
- getReportTypeName: function(type) {
- if (type === 'gut_flora') return '肠道检测'
- if (type === 'physical_exam') return '体检报告'
- if (type === 'blood') return '血液检测'
- return type || '健康报告'
- },
- formatDate: function(dateStr) {
- if (!dateStr) return ''
- try {
- var d = new Date(dateStr)
- var m = ('' + (d.getMonth() + 1)).padStart(2, '0')
- var day = ('' + d.getDate()).padStart(2, '0')
- return m + '-' + day
- } catch (e) {
- return dateStr
- }
- },
- goBack: function() {
- uni.navigateBack()
- },
- goToReport: function(id) {
- uni.navigateTo({ url: '/pages/body/health-report?reportId=' + id + '&childId=' + this.childId })
- },
- goToIndicators: function() {
- uni.navigateTo({ url: '/pages/body/health-report?childId=' + this.childId })
- },
- goToAssessment: function() {
- uni.navigateTo({ url: '/pages/assessment/apply' })
- },
- goToAIRecommend: function() {
- uni.navigateTo({ url: '/pages/meal/recommend?childId=' + this.childId })
- }
- }
- }
- </script>
- <style scoped>
- .nutrition-profile {
- min-height: 100vh;
- background: #FFF7ED;
- padding-bottom: 40rpx;
- }
- .nav-bar {
- position: sticky;
- top: 0;
- background: #fff;
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- padding: 20rpx 30rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
- z-index: 100;
- }
- .nav-back {
- font-size: 32rpx;
- color: #F97316;
- }
- .nav-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
- .nav-placeholder {
- width: 80rpx;
- }
- .profile-header {
- padding: 40rpx 30rpx 20rpx;
- }
- .child-info {
- display: flex;
- flex-direction: column;
- }
- .child-name {
- font-size: 40rpx;
- font-weight: bold;
- color: #1F2937;
- }
- .child-age {
- font-size: 26rpx;
- color: #6B7280;
- margin-top: 8rpx;
- }
- .score-section {
- margin: 0 20rpx;
- background: white;
- border-radius: 24rpx;
- padding: 30rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
- }
- .main-score-ring {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-bottom: 30rpx;
- }
- .score-ring-outer {
- width: 200rpx;
- height: 200rpx;
- border-radius: 100rpx;
- border: 12rpx solid #F97316;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .score-ring-inner {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .score-value {
- font-size: 56rpx;
- font-weight: bold;
- color: #F97316;
- }
- .score-label {
- font-size: 24rpx;
- color: #9CA3AF;
- }
- .score-items {
- display: flex;
- flex-direction: row;
- justify-content: space-around;
- flex-wrap: wrap;
- }
- .score-item {
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 25%;
- }
- .score-num {
- font-size: 32rpx;
- font-weight: bold;
- color: #374151;
- }
- .score-name {
- font-size: 22rpx;
- color: #9CA3AF;
- margin-top: 4rpx;
- }
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 80rpx 30rpx;
- }
- .empty-icon {
- font-size: 80rpx;
- }
- .empty-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #374151;
- margin-top: 20rpx;
- }
- .empty-desc {
- font-size: 28rpx;
- color: #9CA3AF;
- text-align: center;
- margin: 16rpx 0 30rpx;
- }
- .empty-btn {
- background: #F97316;
- border-radius: 40rpx;
- padding: 20rpx 60rpx;
- }
- .empty-btn-text {
- color: white;
- font-size: 28rpx;
- }
- .section {
- background: white;
- border-radius: 24rpx;
- margin: 20rpx;
- padding: 30rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05);
- }
- .section-title-wrap {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #374151;
- }
- .section-count {
- font-size: 24rpx;
- color: #9CA3AF;
- }
- .indicator-list {
- display: flex;
- flex-direction: column;
- }
- .indicator-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- padding: 12rpx 0;
- border-bottom: 1rpx solid #F3F4F6;
- }
- .indicator-item:last-child {
- border-bottom: none;
- }
- .indicator-left {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .indicator-emoji {
- font-size: 28rpx;
- margin-right: 16rpx;
- }
- .indicator-info {
- display: flex;
- flex-direction: column;
- }
- .indicator-name {
- font-size: 28rpx;
- color: #374151;
- font-weight: 500;
- }
- .indicator-value {
- font-size: 24rpx;
- color: #9CA3AF;
- margin-top: 4rpx;
- }
- .section-more {
- text-align: center;
- padding-top: 20rpx;
- }
- .section-more-text {
- color: #F97316;
- font-size: 26rpx;
- }
- .trend-canvas {
- width: 100%;
- height: 300rpx;
- }
- .trend-legend {
- display: flex;
- flex-direction: row;
- justify-content: center;
- margin-top: 16rpx;
- }
- .legend-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- margin-left: 30rpx;
- }
- .legend-item:first-child {
- margin-left: 0;
- }
- .legend-color {
- width: 20rpx;
- height: 20rpx;
- border-radius: 4rpx;
- margin-right: 8rpx;
- }
- .legend-text {
- font-size: 24rpx;
- color: #6B7280;
- }
- .deficiency-list {
- display: flex;
- flex-direction: column;
- }
- .deficiency-item {
- display: flex;
- flex-direction: column;
- padding: 16rpx 0;
- border-bottom: 1rpx solid #F3F4F6;
- }
- .deficiency-item:last-child {
- border-bottom: none;
- }
- .deficiency-info {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 10rpx;
- }
- .deficiency-name {
- font-size: 28rpx;
- color: #374151;
- font-weight: 500;
- }
- .deficiency-level {
- font-size: 24rpx;
- color: #9CA3AF;
- }
- .deficiency-bar {
- height: 12rpx;
- background: #F3F4F6;
- border-radius: 6rpx;
- overflow: hidden;
- }
- .deficiency-fill {
- height: 100%;
- border-radius: 6rpx;
- }
- .deficiency-foods {
- font-size: 22rpx;
- color: #6B7280;
- margin-top: 8rpx;
- }
- .report-list {
- display: flex;
- flex-direction: column;
- }
- .report-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- padding: 16rpx 0;
- border-bottom: 1rpx solid #F3F4F6;
- }
- .report-item:last-child {
- border-bottom: none;
- }
- .report-item:active {
- opacity: 0.7;
- }
- .report-item-left {
- display: flex;
- flex-direction: column;
- }
- .report-item-type {
- font-size: 28rpx;
- color: #374151;
- font-weight: 500;
- }
- .report-item-date {
- font-size: 22rpx;
- color: #9CA3AF;
- margin-top: 4rpx;
- }
- .report-item-score {
- display: flex;
- flex-direction: row;
- align-items: baseline;
- }
- .report-score-val {
- font-size: 36rpx;
- font-weight: bold;
- color: #F97316;
- }
- .report-score-label {
- font-size: 20rpx;
- color: #9CA3AF;
- margin-left: 4rpx;
- }
- .fab {
- position: fixed;
- bottom: 40rpx;
- left: 50%;
- transform: translateX(-50%);
- background: linear-gradient(135deg, #F97316, #FB923C);
- color: white;
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 20rpx 40rpx;
- border-radius: 50rpx;
- box-shadow: 0 8rpx 24rpx rgba(249, 115, 22, 0.4);
- z-index: 200;
- }
- .fab-icon {
- font-size: 36rpx;
- margin-right: 12rpx;
- }
- .fab-text {
- font-size: 30rpx;
- font-weight: 600;
- }
- .bottom-spacer {
- height: 130rpx;
- }
- </style>
|