health-dimensions.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <view class="hd-container">
  3. <view class="hd-header">
  4. <text class="hd-title">健康维度全景</text>
  5. <text class="hd-subtitle" v-if="memberName">{{ memberName }}的健康档案</text>
  6. </view>
  7. <view class="hd-health-index" v-if="healthData && healthData.healthIndex">
  8. <view class="index-circle">
  9. <text class="index-value">{{ healthData.healthIndex }}</text>
  10. <text class="index-label">健康指数</text>
  11. </view>
  12. </view>
  13. <view class="radar-section" v-if="healthData && healthData.dimensions">
  14. <view class="radar-title">七维健康雷达</view>
  15. <view class="radar-wrap">
  16. <view class="radar-center">
  17. <view class="radar-grid">
  18. <view class="grid-ring ring-3"></view>
  19. <view class="grid-ring ring-2"></view>
  20. <view class="grid-ring ring-1"></view>
  21. </view>
  22. <view class="radar-spokes">
  23. <view
  24. class="spoke-item"
  25. v-for="(dim, idx) in healthData.dimensions"
  26. :key="dim.dimension"
  27. :style="spokeStyles[idx]"
  28. >
  29. <view class="spoke-dot" :class="'level-' + dim.level"></view>
  30. <view class="spoke-label">{{ dim.label }}</view>
  31. <view class="spoke-score">{{ dim.score || '--' }}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="dimension-list" v-if="healthData && healthData.dimensions">
  38. <view
  39. class="dim-card"
  40. v-for="dim in healthData.dimensions"
  41. :key="dim.dimension"
  42. @click="goDimDetail(dim)"
  43. >
  44. <view class="dim-header">
  45. <text class="dim-label">{{ dim.label }}</text>
  46. <text class="dim-score" :class="'score-' + dim.level">{{ dim.score || '--' }}分</text>
  47. </view>
  48. <view class="dim-bar-wrap">
  49. <view class="dim-bar-bg">
  50. <view
  51. class="dim-bar-fill"
  52. :class="'fill-' + dim.level"
  53. :style="{ width: (dim.score || 0) + '%' }"
  54. ></view>
  55. </view>
  56. <text class="dim-norms" v-if="dim.normMin && dim.normMax">
  57. 正常范围 {{ dim.normMin }}-{{ dim.normMax }}
  58. </text>
  59. </view>
  60. <view class="dim-footer">
  61. <text class="dim-level-tag" :class="'tag-' + dim.level">{{ getLevelText(dim.level) }}</text>
  62. <text class="dim-source" v-if="dim.trend">{{ dim.trend === 'up' ? '↑ 上升' : dim.trend === 'down' ? '↓ 下降' : '→ 稳定' }}</text>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="hd-empty" v-if="!healthData && !loading">
  67. <text class="empty-tip">暂无维度数据</text>
  68. <text class="empty-sub">上传健康报告或填写问卷后可查看</text>
  69. </view>
  70. <view class="loading-wrap" v-if="loading">
  71. <text class="loading-text">加载中...</text>
  72. </view>
  73. <view class="fab-upload" @click="showUploadModal">
  74. <text class="fab-icon">+</text>
  75. </view>
  76. <view class="modal-mask" v-if="showModal" @click="showModal = false">
  77. <view class="modal-content" @click.stop>
  78. <view class="modal-header">
  79. <text class="modal-title">录入维度评分</text>
  80. <text class="modal-close" @click="showModal = false">×</text>
  81. </view>
  82. <view class="modal-body">
  83. <view class="form-item">
  84. <text class="form-label">选择维度</text>
  85. <picker
  86. mode="selector"
  87. :range="dimensionOptions"
  88. range-key="label"
  89. @change="onDimensionChange"
  90. >
  91. <view class="picker-value">
  92. {{ selectedDimension.label || '请选择' }}
  93. </view>
  94. </picker>
  95. </view>
  96. <view class="form-item">
  97. <text class="form-label">评分 (0-100)</text>
  98. <input
  99. class="form-input"
  100. type="number"
  101. v-model="uploadForm.score"
  102. placeholder="请输入评分"
  103. min="0"
  104. max="100"
  105. />
  106. </view>
  107. <view class="form-item">
  108. <text class="form-label">数据来源</text>
  109. <picker
  110. mode="selector"
  111. :range="sourceOptions"
  112. @change="onSourceChange"
  113. >
  114. <view class="picker-value">
  115. {{ selectedSource.label || '请选择' }}
  116. </view>
  117. </picker>
  118. </view>
  119. </view>
  120. <view class="modal-footer">
  121. <view class="btn-cancel" @click="showModal = false">取消</view>
  122. <view class="btn-confirm" @click="submitUpload">确认提交</view>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. </template>
  128. <script>
  129. import { getDimensionOverview, uploadDimensionScore } from '../../utils/api.js'
  130. export default {
  131. data() {
  132. return {
  133. memberId: null,
  134. memberName: '',
  135. healthData: null,
  136. loading: false,
  137. showModal: false,
  138. selectedDimension: {},
  139. selectedSource: {},
  140. uploadForm: {
  141. memberId: null,
  142. dimension: '',
  143. score: '',
  144. dataSource: ''
  145. },
  146. dimensionOptions: [
  147. { code: 'growth', label: '生长发育' },
  148. { code: 'sleep', label: '睡眠质量' },
  149. { code: 'vision', label: '视力健康' },
  150. { code: 'immunity', label: '免疫力' },
  151. { code: 'nutrition', label: '营养均衡' },
  152. { code: 'gut', label: '肠胃健康' },
  153. { code: 'exercise', label: '运动活力' }
  154. ],
  155. sourceOptions: [
  156. { code: 'MANUAL', label: '手动录入' },
  157. { code: 'REPORT', label: '健康报告' },
  158. { code: 'PHOTO', label: '照片' },
  159. { code: 'VOICE', label: '语音' }
  160. ]
  161. }
  162. },
  163. computed: {
  164. spokeStyles: function() {
  165. if (!this.healthData || !this.healthData.dimensions) return []
  166. var cache = []
  167. var dims = this.healthData.dimensions
  168. for (var i = 0; i < dims.length; i++) {
  169. var angle = i * 51.4 - 90
  170. var radius = 85
  171. var normalizedScore = (dims[i].score || 0) / 100
  172. var translateY = -radius * normalizedScore
  173. cache.push({
  174. transform: 'rotate(' + angle + 'deg) translateY(' + translateY + 'px)',
  175. '-webkit-transform': 'rotate(' + angle + 'deg) translateY(' + translateY + 'px)'
  176. })
  177. }
  178. return cache
  179. }
  180. },
  181. onLoad: function(options) {
  182. var childId = options.childId || uni.getStorageSync('currentChildId')
  183. var childName = options.name || ''
  184. this.memberId = Number(childId)
  185. this.memberName = childName
  186. this.uploadForm.memberId = this.memberId
  187. if (this.memberId) {
  188. this.loadDimensionData()
  189. }
  190. },
  191. onShow: function() {
  192. if (this.memberId) {
  193. this.loadDimensionData()
  194. }
  195. },
  196. methods: {
  197. loadDimensionData: function() {
  198. var self = this
  199. self.loading = true
  200. getDimensionOverview({ memberId: this.memberId }).then(function(res) {
  201. self.loading = false
  202. if (res.code === 200 && res.data) {
  203. self.healthData = res.data
  204. }
  205. }).catch(function(e) {
  206. self.loading = false
  207. console.log('获取维度数据失败', e)
  208. })
  209. },
  210. getLevelText: function(level) {
  211. var map = {
  212. 'excellent': '优秀',
  213. 'good': '良好',
  214. 'fair': '一般',
  215. 'poor': '较差',
  216. 'none': '暂无数据'
  217. }
  218. return map[level] || ''
  219. },
  220. goDimDetail: function(dim) {
  221. if (!dim || !dim.dimension) return
  222. var childId = this.memberId || uni.getStorageSync('currentChildId') || ''
  223. uni.navigateTo({
  224. url: '/pages/body/dimension-detail?dimension=' + dim.dimension + '&childId=' + childId
  225. })
  226. },
  227. showUploadModal: function() {
  228. this.showModal = true
  229. this.selectedDimension = {}
  230. this.selectedSource = {}
  231. this.uploadForm.dimension = ''
  232. this.uploadForm.score = ''
  233. this.uploadForm.dataSource = ''
  234. },
  235. onDimensionChange: function(e) {
  236. var idx = e.detail.value
  237. this.selectedDimension = this.dimensionOptions[idx]
  238. this.uploadForm.dimension = this.selectedDimension.code
  239. },
  240. onSourceChange: function(e) {
  241. var idx = e.detail.value
  242. this.selectedSource = this.sourceOptions[idx]
  243. this.uploadForm.dataSource = this.selectedSource.code
  244. },
  245. submitUpload: function() {
  246. if (!this.uploadForm.dimension) {
  247. uni.showToast({ title: '请选择维度', icon: 'none' })
  248. return
  249. }
  250. if (!this.uploadForm.score || this.uploadForm.score < 0 || this.uploadForm.score > 100) {
  251. uni.showToast({ title: '评分需在0-100之间', icon: 'none' })
  252. return
  253. }
  254. if (!this.uploadForm.dataSource) {
  255. uni.showToast({ title: '请选择数据来源', icon: 'none' })
  256. return
  257. }
  258. var self = this
  259. var payload = {
  260. memberId: this.memberId,
  261. dimension: this.uploadForm.dimension,
  262. score: Number(this.uploadForm.score),
  263. sourceType: this.uploadForm.dataSource
  264. }
  265. uploadDimensionScore(payload).then(function(res) {
  266. if (res.code === 200) {
  267. uni.showToast({ title: '提交成功', icon: 'success' })
  268. self.showModal = false
  269. self.loadDimensionData()
  270. }
  271. }).catch(function(e) {
  272. console.log('提交失败', e)
  273. })
  274. }
  275. }
  276. }
  277. </script>
  278. <style scoped>
  279. .hd-container {
  280. min-height: 100vh;
  281. background: #f5f5f5;
  282. padding-bottom: 120rpx;
  283. }
  284. .hd-header {
  285. background: linear-gradient(135deg, #FF8C42, #FF6B35);
  286. padding: 40rpx 30rpx 30rpx;
  287. color: #fff;
  288. }
  289. .hd-title {
  290. font-size: 40rpx;
  291. font-weight: bold;
  292. display: block;
  293. }
  294. .hd-subtitle {
  295. font-size: 26rpx;
  296. opacity: 0.9;
  297. display: block;
  298. margin-top: 8rpx;
  299. }
  300. .hd-health-index {
  301. display: flex;
  302. justify-content: center;
  303. padding: 30rpx;
  304. background: #fff;
  305. }
  306. .index-circle {
  307. width: 160rpx;
  308. height: 160rpx;
  309. border-radius: 50%;
  310. background: linear-gradient(135deg, #FF8C42, #FF6B35);
  311. display: flex;
  312. flex-direction: column;
  313. align-items: center;
  314. justify-content: center;
  315. color: #fff;
  316. }
  317. .index-value {
  318. font-size: 48rpx;
  319. font-weight: bold;
  320. line-height: 1;
  321. }
  322. .index-label {
  323. font-size: 22rpx;
  324. opacity: 0.9;
  325. margin-top: 8rpx;
  326. }
  327. .radar-section {
  328. background: #fff;
  329. margin-top: 20rpx;
  330. padding: 30rpx;
  331. }
  332. .radar-title {
  333. font-size: 32rpx;
  334. font-weight: bold;
  335. color: #333;
  336. margin-bottom: 30rpx;
  337. text-align: center;
  338. }
  339. .radar-wrap {
  340. display: flex;
  341. justify-content: center;
  342. }
  343. .radar-center {
  344. width: 440rpx;
  345. height: 440rpx;
  346. position: relative;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. }
  351. .radar-grid {
  352. position: absolute;
  353. width: 100%;
  354. height: 100%;
  355. }
  356. .grid-ring {
  357. position: absolute;
  358. border-radius: 50%;
  359. border: 1px solid #ddd;
  360. left: 50%;
  361. top: 50%;
  362. transform: translate(-50%, -50%);
  363. }
  364. .ring-1 { width: 33%; height: 33%; }
  365. .ring-2 { width: 66%; height: 66%; }
  366. .ring-3 { width: 100%; height: 100%; }
  367. .radar-spokes {
  368. position: absolute;
  369. width: 100%;
  370. height: 100%;
  371. display: flex;
  372. align-items: center;
  373. justify-content: center;
  374. }
  375. .spoke-item {
  376. position: absolute;
  377. display: flex;
  378. flex-direction: column;
  379. align-items: center;
  380. transform-origin: center center;
  381. width: 80rpx;
  382. margin-left: -40rpx;
  383. top: 10rpx;
  384. }
  385. .spoke-dot {
  386. width: 20rpx;
  387. height: 20rpx;
  388. border-radius: 50%;
  389. background: #FF8C42;
  390. margin-bottom: 6rpx;
  391. }
  392. .spoke-dot.level-excellent { background: #10B981; }
  393. .spoke-dot.level-good { background: #3B82F6; }
  394. .spoke-dot.level-fair { background: #F59E0B; }
  395. .spoke-dot.level-poor { background: #EF4444; }
  396. .spoke-dot.level-none { background: #ddd; }
  397. .spoke-label {
  398. font-size: 22rpx;
  399. color: #333;
  400. white-space: nowrap;
  401. }
  402. .spoke-score {
  403. font-size: 20rpx;
  404. color: #666;
  405. margin-top: 2rpx;
  406. }
  407. .dimension-list {
  408. padding: 20rpx 30rpx;
  409. }
  410. .dim-card {
  411. background: #fff;
  412. border-radius: 16rpx;
  413. padding: 24rpx;
  414. margin-bottom: 20rpx;
  415. }
  416. .dim-header {
  417. display: flex;
  418. justify-content: space-between;
  419. align-items: center;
  420. margin-bottom: 16rpx;
  421. }
  422. .dim-label {
  423. font-size: 30rpx;
  424. font-weight: bold;
  425. color: #333;
  426. }
  427. .dim-score {
  428. font-size: 36rpx;
  429. font-weight: bold;
  430. color: #FF8C42;
  431. }
  432. .dim-score.score-excellent { color: #10B981; }
  433. .dim-score.score-good { color: #3B82F6; }
  434. .dim-score.score-fair { color: #F59E0B; }
  435. .dim-score.score-poor { color: #EF4444; }
  436. .dim-bar-wrap {
  437. margin-bottom: 12rpx;
  438. }
  439. .dim-bar-bg {
  440. height: 16rpx;
  441. background: #f0f0f0;
  442. border-radius: 8rpx;
  443. overflow: hidden;
  444. margin-bottom: 6rpx;
  445. }
  446. .dim-bar-fill {
  447. height: 100%;
  448. border-radius: 8rpx;
  449. background: #FF8C42;
  450. transition: width 0.3s;
  451. }
  452. .dim-bar-fill.fill-excellent { background: #10B981; }
  453. .dim-bar-fill.fill-good { background: #3B82F6; }
  454. .dim-bar-fill.fill-fair { background: #F59E0B; }
  455. .dim-bar-fill.fill-poor { background: #EF4444; }
  456. .dim-norms {
  457. font-size: 22rpx;
  458. color: #999;
  459. }
  460. .dim-footer {
  461. display: flex;
  462. justify-content: space-between;
  463. align-items: center;
  464. }
  465. .dim-level-tag {
  466. font-size: 22rpx;
  467. padding: 4rpx 16rpx;
  468. border-radius: 20rpx;
  469. background: #f0f0f0;
  470. color: #666;
  471. }
  472. .dim-level-tag.tag-excellent { background: #D1FAE5; color: #10B981; }
  473. .dim-level-tag.tag-good { background: #DBEAFE; color: #3B82F6; }
  474. .dim-level-tag.tag-fair { background: #FEF3C7; color: #F59E0B; }
  475. .dim-level-tag.tag-poor { background: #FEE2E2; color: #EF4444; }
  476. .dim-source {
  477. font-size: 22rpx;
  478. color: #999;
  479. }
  480. .hd-empty {
  481. padding: 100rpx 30rpx;
  482. text-align: center;
  483. }
  484. .empty-tip {
  485. font-size: 30rpx;
  486. color: #999;
  487. display: block;
  488. margin-bottom: 16rpx;
  489. }
  490. .empty-sub {
  491. font-size: 24rpx;
  492. color: #ccc;
  493. display: block;
  494. }
  495. .loading-wrap {
  496. padding: 80rpx 30rpx;
  497. text-align: center;
  498. }
  499. .loading-text {
  500. font-size: 28rpx;
  501. color: #999;
  502. }
  503. .fab-upload {
  504. position: fixed;
  505. right: 40rpx;
  506. bottom: 60rpx;
  507. width: 100rpx;
  508. height: 100rpx;
  509. border-radius: 50%;
  510. background: linear-gradient(135deg, #FF8C42, #FF6B35);
  511. display: flex;
  512. align-items: center;
  513. justify-content: center;
  514. box-shadow: 0 8rpx 24rpx rgba(255, 140, 66, 0.4);
  515. }
  516. .fab-icon {
  517. font-size: 48rpx;
  518. color: #fff;
  519. font-weight: bold;
  520. line-height: 1;
  521. }
  522. .modal-mask {
  523. position: fixed;
  524. top: 0;
  525. left: 0;
  526. right: 0;
  527. bottom: 0;
  528. background: rgba(0,0,0,0.5);
  529. z-index: 999;
  530. display: flex;
  531. align-items: flex-end;
  532. justify-content: center;
  533. }
  534. .modal-content {
  535. width: 100%;
  536. background: #fff;
  537. border-radius: 24rpx 24rpx 0 0;
  538. padding-bottom: 60rpx;
  539. }
  540. .modal-header {
  541. display: flex;
  542. justify-content: space-between;
  543. align-items: center;
  544. padding: 30rpx;
  545. border-bottom: 1px solid #f0f0f0;
  546. }
  547. .modal-title {
  548. font-size: 32rpx;
  549. font-weight: bold;
  550. color: #333;
  551. }
  552. .modal-close {
  553. font-size: 48rpx;
  554. color: #999;
  555. line-height: 1;
  556. }
  557. .modal-body {
  558. padding: 30rpx;
  559. }
  560. .form-item {
  561. margin-bottom: 30rpx;
  562. }
  563. .form-label {
  564. font-size: 28rpx;
  565. color: #666;
  566. display: block;
  567. margin-bottom: 12rpx;
  568. }
  569. .picker-value {
  570. height: 80rpx;
  571. line-height: 80rpx;
  572. border: 1px solid #e0e0e0;
  573. border-radius: 12rpx;
  574. padding: 0 20rpx;
  575. font-size: 28rpx;
  576. color: #333;
  577. }
  578. .form-input {
  579. height: 80rpx;
  580. border: 1px solid #e0e0e0;
  581. border-radius: 12rpx;
  582. padding: 0 20rpx;
  583. font-size: 28rpx;
  584. }
  585. .modal-footer {
  586. display: flex;
  587. padding: 0 30rpx;
  588. gap: 20rpx;
  589. }
  590. .btn-cancel {
  591. flex: 1;
  592. height: 88rpx;
  593. line-height: 88rpx;
  594. text-align: center;
  595. background: #f0f0f0;
  596. border-radius: 44rpx;
  597. font-size: 30rpx;
  598. color: #666;
  599. }
  600. .btn-confirm {
  601. flex: 1;
  602. height: 88rpx;
  603. line-height: 88rpx;
  604. text-align: center;
  605. background: linear-gradient(135deg, #FF8C42, #FF6B35);
  606. border-radius: 44rpx;
  607. font-size: 30rpx;
  608. color: #fff;
  609. }
  610. </style>