| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <template>
- <view v-if="rowVisible" class="change-row" :class="sizeClass">
- <!-- 第一行:较 MM-DD + 旧值 → 新值 + Δ (Δ%) + 趋势词 -->
- <view class="change-main">
- <text class="change-date">{{ compareDate }}</text>
- <text class="change-body">{{ displayLine }}</text>
- </view>
- <!-- 第二行:趋势词/降级文案(单独一行,方便颜色语义) -->
- <view class="change-trend" :class="trendClass">{{ trendLabel }}</view>
- <!-- 第三行:跨期跳比提示(橙色 20rpx) -->
- <view class="change-skip" v-if="showSkipHint && skipHintText">
- <text class="skip-prefix">ⓘ</text><text class="skip-text">{{ skipHintText }}</text>
- </view>
- </view>
- </template>
- <script>
- import { resolveChange, formatDelta, formatCompareDate } from '@/utils/indicator-change'
- /**
- * IndicatorChangeRow —— 「较 MM-DD:旧值 → 新值 ↑ Δ (Δ%) 趋势词」行
- * 跨页面复用(报告详情、时间轴、速查、菌群、身维度卡片)
- *
- * 渲染分支(design §6.2):
- * change == null || previous == null → 「首次记录 · 暂无对比」(灰)
- * change.comparable == false → 「无法比较」(灰)
- * change.unitMismatch == true → Δ 正常显示,百分比位置显示「—」,值后加 *
- * 其余 → 「较 MM-DD:{旧值} → {新值} {箭头} {Δ} ({Δ%}) {趋势词}」
- * change.skipGaps > 0 && showSkipHint → 第三行「ⓘ {skipDates 或 '中间 N 期未检测该项'}」(橙 20rpx)
- */
- export default {
- name: 'IndicatorChangeRow',
- props: {
- /** 上一期 { reportDate, dateSource, value, numericValue, unit, status } | null */
- previous: { type: Object, default: null },
- /** 本期 { value, numericValue, unit, reportDate } */
- current: { type: Object, default: null },
- /** { delta, deltaPct, movement, trendLabel, trendCode, skipGaps, unitMismatch, comparable } | null */
- change: { type: Object, default: null },
- /** 'normal' 报告详情/时间轴 | 'compact' 列表窄位(省略单位) */
- size: { type: String, default: 'normal' },
- /** 是否显示跨期跳比提示行 */
- showSkipHint: { type: Boolean, default: true },
- /** 跳比提示的具体缺失日期列表(可选,不传则显示「中间 N 期未检测该项」) */
- skipDates: { type: Array, default: function() { return [] } }
- },
- computed: {
- rowVisible: function() {
- return !!this.change || !!this.previous || !!this.current
- },
- sizeClass: function() {
- return this.size === 'compact' ? 'change-row-compact' : 'change-row-normal'
- },
- /** 上一期数据:优先取 previous prop(report-detail/quick-lookup 是兄弟字段),回退 change.previous(trend 接口嵌套) */
- prevData: function() {
- if (this.previous) return this.previous
- return (this.change && this.change.previous) || null
- },
- trendInfo: function() {
- var ch = this.change
- if (!ch || ch.trendCode === 'first_record' || ch.trendCode === 'pending_backfill' || !ch.comparable) {
- var tc = (ch && ch.trendCode) || 'first_record'
- return resolveChange(tc, ch && ch.movement, ch && ch.trendLabel)
- }
- return resolveChange(ch.trendCode, ch.movement, ch.trendLabel)
- },
- trendLabel: function() {
- return this.trendInfo.trendLabel
- },
- trendClass: function() {
- if (this.trendInfo.cssClass === 'impr') return 'trend-impr'
- if (this.trendInfo.cssClass === 'worst') return 'trend-worst'
- return 'trend-flat'
- },
- arrow: function() {
- return this.trendInfo.arrow
- },
- /** 比较日期文案,"较 MM-DD"(带 * 若 dateSource 非 real/unknown) */
- compareDate: function() {
- var prev = this.prevData
- if (!prev) return ''
- var currDate = this.current && this.current.reportDate ? this.current.reportDate : ''
- var dateSource = prev.dateSource ? prev.dateSource : ''
- return '较 ' + formatCompareDate(prev.reportDate, currDate, dateSource)
- },
- /** 主体展示文本:{旧值} → {新值} {箭头} {Δ} ({Δ%}) */
- displayLine: function() {
- var ch = this.change
- var prev = this.prevData
- if (!ch || !prev) return ''
- var oldVal = prev.value !== undefined && prev.value !== null && prev.value !== '' ? prev.value : '--'
- var newVal = this.current && (this.current.numericValue !== undefined && this.current.numericValue !== null)
- ? this.current.numericValue : (this.current.value || '--')
- var unit = this.size !== 'compact' && this.current && this.current.unit ? (' ' + this.current.unit) : ''
- var deltaText = formatDelta(ch.delta, ch.deltaPct, ch.unitMismatch)
- var unitMark = ch.unitMismatch ? ' *' : ''
- return oldVal + ' → ' + newVal + unit + unitMark + ' ' + (this.arrow || '') + ' ' + deltaText
- },
- /** 跳比提示文案 */
- skipHintText: function() {
- var ch = this.change
- if (!ch || ch.skipGaps <= 0) return ''
- var prevDate = this.prevData && this.prevData.reportDate ? this.prevData.reportDate : ''
- if (this.skipDates && this.skipDates.length > 0) {
- return this.skipDates.join('、') + ' 两期未检测该项,对比的是 ' + prevDate
- }
- return '中间 ' + ch.skipGaps + ' 期未检测该项,对比的是 ' + prevDate
- }
- },
- methods: {}
- }
- </script>
- <style scoped lang="scss">
- .change-row {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- margin-top: 8rpx;
- }
- .change-row-compact { margin-top: 4rpx; }
- .change-main {
- display: flex;
- flex-direction: row;
- align-items: baseline;
- }
- .change-date {
- font-size: 20rpx;
- color: #64748B;
- margin-right: 10rpx;
- }
- .change-body {
- font-size: 24rpx;
- line-height: 34rpx;
- }
- .change-trend {
- font-size: 20rpx;
- margin-top: 2rpx;
- }
- .trend-impr { color: #16A34A; }
- .trend-worst { color: #EA580C; }
- .trend-flat { color: #94A3B8; }
- .change-skip {
- font-size: 20rpx;
- margin-top: 4rpx;
- color: #EA580C;
- line-height: 28rpx;
- }
- .skip-prefix { color: #EA580C; margin-right: 4rpx; }
- .skip-text { color: #EA580C; }
- </style>
|