| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <template>
- <view class="page" :style="{ '--font-scale': fontScale }">
- <!-- 成员切换 -->
- <picker :range="memberNames" @change="onMemberChange">
- <view class="member-picker">{{ currentMemberName }} ▾</view>
- </picker>
- <!-- 分类 Tab -->
- <scroll-view scroll-x class="cat-scroll">
- <view class="cat-tab" :class="activeCategory === '' ? 'cat-active' : ''" @tap="onCatTap('')">全部</view>
- <view
- class="cat-tab"
- :class="activeCategory === c.name ? 'cat-active' : ''"
- v-for="c in categories"
- :key="getCatKey(c)"
- @tap="onCatTap(c.name)"
- >{{ c.name }}({{ c.total }})</view>
- </scroll-view>
- <!-- 指标列表 -->
- <view class="item-list" v-if="items.length > 0">
- <view class="ql-item" v-for="item in items" :key="getItemKey(item)" @tap="goTimeline(item)">
- <view class="ql-name-row">
- <text class="ql-name">{{ item.name }}</text>
- <view class="ql-trend-row">
- <indicator-trend-arrow
- :subject-id="currentMemberId"
- :definition-id="item.definitionId"
- :trend="item"
- :latest-text="item._latestText || ''"
- :show-latest="false"
- />
- <text :class="'ql-trend ' + item._cssClass">{{ item._trendLabel }}</text>
- </view>
- </view>
- <view class="ql-value-row">
- <text class="ql-value">{{ item.value }}{{ item.unit || '' }}</text>
- <text class="ql-ref">参考: {{ item.refRange || '--' }}</text>
- <text class="ql-status" :class="item._statusClass">{{ item.status || '' }}</text>
- </view>
- <IndicatorChangeRow
- :previous="item._previous"
- :current="item._current"
- :change="item._change"
- size="compact"
- />
- <text class="ql-date">{{ item._dateText }}</text>
- </view>
- </view>
- <view class="empty-tip" v-else>暂无数据</view>
- <!-- 分页 -->
- <view class="pager" v-if="totalPages > 1">
- <view class="pager-btn" :class="page <= 1 ? 'pager-disabled' : ''" @tap="onPrevPage">上一页</view>
- <text class="pager-info">{{ page }} / {{ totalPages }}</text>
- <view class="pager-btn" :class="page >= totalPages ? 'pager-disabled' : ''" @tap="onNextPage">下一页</view>
- </view>
- <!-- 五维/七维评分小节 -->
- <view class="dim-section" v-if="dimensionScores.length > 0">
- <view class="section-title">维度评分趋势</view>
- <view class="dim-list">
- <view class="dim-row" v-for="d in dimensionScores" :key="getDimKey(d)">
- <text class="dim-name">{{ d.name }}</text>
- <text class="dim-score">{{ d.score }}</text>
- <text :class="'dim-trend ' + d._cssClass">{{ d._arrow }}</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getIndicatorQuickLookup } from '@/utils/api'
- import { getFamilyMemberList } from '@/utils/api'
- import { resolveChange } from '@/utils/indicator-change'
- import IndicatorChangeRow from '@/pages/health/components/IndicatorChangeRow.vue'
- import IndicatorTrendArrow from '@/pages/health/components/IndicatorTrendArrow.vue'
- import fontScaleMixin from '@/mixins/font-scale.js'
- export default {
- mixins: [fontScaleMixin],
- components: { IndicatorChangeRow, IndicatorTrendArrow },
- data: function() { return { members: [], currentMemberId: null, categories: [], activeCategory: '', items: [], dimensionScores: [], page: 1, pageSize: 30, totalPages: 1, _onLoadFired: false, _loading: false } },
- computed: {
- memberNames: function() { return this.members.map(function(m) { return m.name || m.nickname || '' }) },
- currentMemberName: function() {
- var self = this
- var m = this.members.find(function(x) { return x.id === self.currentMemberId })
- return (m && (m.name || m.nickname)) || '选择成员'
- },
- categoriesComputed: function() {
- var self = this
- return this.categories || []
- }
- },
- methods: {
- onLoad: function() { this.loadMembers(); this._onLoadFired = true },
- onShow: function() { if (this._onLoadFired) { this._onLoadFired = false } else if (this.currentMemberId) { this.reload() } },
- /** 跳时间轴页:整页传参口径一致(subjectId + definitionId + reportType) */
- goTimeline: function(item) {
- if (!item || item.definitionId === null || item.definitionId === undefined) return
- var url = '/pages/health/indicator-timeline?subjectId=' + this.currentMemberId +
- '&definitionId=' + item.definitionId
- if (item.sourceType) { url += '&reportType=' + encodeURIComponent(item.sourceType) }
- uni.navigateTo({ url: url })
- },
- loadMembers: function() {
- var self = this
- getFamilyMemberList({ visibleOnly: true }).then(function(res) {
- var arr = (res.data && res.data.list) || (res.data instanceof Array ? res.data : [])
- self.members = arr
- if (!self.currentMemberId && arr.length > 0) { self.currentMemberId = arr[0].id; self.reload() }
- })
- },
- reload: function() { this.page = 1; this.loadData() },
- loadData: function() {
- var self = this
- if (!this.currentMemberId || this._loading) return
- this._loading = true
- getIndicatorQuickLookup({ subjectId: this.currentMemberId, category: this.activeCategory || undefined, page: this.page, pageSize: this.pageSize }).then(function(res) {
- self._loading = false
- var data = res.data || {}
- // 预计算展示字段,避免小程序 :class 中调用方法(微信模板编译器不支持带参方法调用)
- var list = data.items || []
- list.forEach(function(it) {
- // 变化样式:只消费后端 trendCode,前端不按 delta 正负自判改善/恶化;
- // change 缺失时中性兜底「暂无对比」,不写死 first_record(§6.6 红线)
- var ch = it.change || null
- var st = ch
- ? resolveChange(ch.trendCode || 'flat', ch.movement, ch.trendLabel)
- : { trendLabel: '暂无对比', cssClass: 'flat', arrow: '', colorClass: 'gray-text', showArrow: false }
- it._cssClass = st.colorClass
- it._arrow = st.arrow
- it._trendLabel = st.trendLabel
- it._latestText = (it.numericValue !== undefined && it.numericValue !== null)
- ? String(it.numericValue)
- : (it.value || '')
- it._statusClass = 'status-' + (it._cssClass || 'normal')
- it._dateText = it.latestReportDate ? String(it.latestReportDate).slice(0, 10) : '--'
- // IndicatorChangeRow 入参(预计算,避免模板内联对象字面量)
- it._previous = it.previous || null
- it._change = ch
- it._current = {
- value: it.value,
- numericValue: it.numericValue,
- unit: it.unit,
- reportDate: it.latestReportDate
- }
- })
- self.categories = data.categories || []
- self.items = list
- self.dimensionScores = data.dimensionScores || []
- var total = data.total !== undefined ? data.total : self.items.length
- self.totalPages = Math.max(1, Math.ceil(total / self.pageSize))
- }).catch(function() { self._loading = false })
- },
- onCatTap: function(name) { this.activeCategory = name; this.reload() },
- onPrevPage: function() { if (this.page > 1) { this.page--; this.loadData() } },
- onNextPage: function() { if (this.page < this.totalPages) { this.page++; this.loadData() } },
- formatDate: function(s) { if (!s) return '--'; return String(s).slice(0, 10) },
- getCatKey: function(c) { return c.name },
- getItemKey: function(item) { return item.definitionId },
- getItemId: function(item) { return item.definitionId },
- getDimKey: function(d) { return d.name }
- }
- }
- </script>
- <style scoped lang="scss">
- .member-picker { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-body; }
- .cat-scroll { height: 40rpx; line-height: 40rpx; overflow-x: scroll; }
- .cat-tab { float: left; margin-right: 20rpx; padding: 0 12rpx; height: 32rpx; line-height: 32rpx; font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; }
- .cat-tab.cat-active { color: $brand-primary; border-bottom: 2rpx solid $brand-primary; }
- .item-list { padding: 20rpx; }
- .ql-item { margin-bottom: 20rpx; }
- .ql-name-row { display: flex; justify-content: space-between; margin-bottom: 8rpx; }
- .ql-name { font-size: calc(26rpx * var(--font-scale, 1)); }
- .ql-trend { font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-body; }
- .ql-trend-row { display: flex; flex-direction: row; align-items: center; }
- .ql-trend-row .it-anchor { display: inline-flex; align-items: center; }
- .ql-value-row { display: flex; justify-content: space-between; margin-bottom: 8rpx; }
- .ql-value { font-size: calc(24rpx * var(--font-scale, 1)); }
- .ql-ref { font-size: calc(16rpx * var(--font-scale, 1)); color: $facade-text-muted; }
- .ql-status { font-size: calc(20rpx * var(--font-scale, 1)); }
- .ql-date { font-size: calc(16rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-top: 4rpx; }
- .pager { height: 40rpx; line-height: 40rpx; padding: 0 20rpx; font-size: calc(20rpx * var(--font-scale, 1)); }
- .pager-btn { float: left; margin-right: 10rpx; padding: 0 12rpx; height: 32rpx; line-height: 32rpx; font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-muted; }
- .pager-btn.pager-disabled { color: $facade-text-ghost; }
- .pager-info { float: left; margin: 0 20rpx; }
- .dim-section { padding: 20rpx; }
- .section-title { font-size: calc(26rpx * var(--font-scale, 1)); margin-bottom: 12rpx; }
- .dim-list { display: flex; flex-wrap: wrap; }
- .dim-row { margin-bottom: 12rpx; }
- .dim-name { font-size: calc(22rpx * var(--font-scale, 1)); width: 60rpx; }
- .dim-score { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-body; }
- .dim-trend { font-size: calc(18rpx * var(--font-scale, 1)); color: $facade-text-muted; }
- </style>
|