IndicatorChangeRow.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view v-if="rowVisible" class="change-row" :class="sizeClass">
  3. <!-- 第一行:较 MM-DD + 旧值 → 新值 + Δ (Δ%) + 趋势词 -->
  4. <view class="change-main">
  5. <text class="change-date">{{ compareDate }}</text>
  6. <text class="change-body">{{ displayLine }}</text>
  7. </view>
  8. <!-- 第二行:趋势词/降级文案(单独一行,方便颜色语义) -->
  9. <view class="change-trend" :class="trendClass">{{ trendLabel }}</view>
  10. <!-- 第三行:跨期跳比提示(橙色 20rpx) -->
  11. <view class="change-skip" v-if="showSkipHint && skipHintText">
  12. <text class="skip-prefix">ⓘ</text><text class="skip-text">{{ skipHintText }}</text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { resolveChange, formatDelta, formatCompareDate } from '@/utils/indicator-change'
  18. /**
  19. * IndicatorChangeRow —— 「较 MM-DD:旧值 → 新值 ↑ Δ (Δ%) 趋势词」行
  20. * 跨页面复用(报告详情、时间轴、速查、菌群、身维度卡片)
  21. *
  22. * 渲染分支(design §6.2):
  23. * change == null || previous == null → 「首次记录 · 暂无对比」(灰)
  24. * change.comparable == false → 「无法比较」(灰)
  25. * change.unitMismatch == true → Δ 正常显示,百分比位置显示「—」,值后加 *
  26. * 其余 → 「较 MM-DD:{旧值} → {新值} {箭头} {Δ} ({Δ%}) {趋势词}」
  27. * change.skipGaps > 0 && showSkipHint → 第三行「ⓘ {skipDates 或 '中间 N 期未检测该项'}」(橙 20rpx)
  28. */
  29. export default {
  30. name: 'IndicatorChangeRow',
  31. props: {
  32. /** 上一期 { reportDate, dateSource, value, numericValue, unit, status } | null */
  33. previous: { type: Object, default: null },
  34. /** 本期 { value, numericValue, unit, reportDate } */
  35. current: { type: Object, default: null },
  36. /** { delta, deltaPct, movement, trendLabel, trendCode, skipGaps, unitMismatch, comparable } | null */
  37. change: { type: Object, default: null },
  38. /** 'normal' 报告详情/时间轴 | 'compact' 列表窄位(省略单位) */
  39. size: { type: String, default: 'normal' },
  40. /** 是否显示跨期跳比提示行 */
  41. showSkipHint: { type: Boolean, default: true },
  42. /** 跳比提示的具体缺失日期列表(可选,不传则显示「中间 N 期未检测该项」) */
  43. skipDates: { type: Array, default: function() { return [] } }
  44. },
  45. computed: {
  46. rowVisible: function() {
  47. return !!this.change || !!this.previous || !!this.current
  48. },
  49. sizeClass: function() {
  50. return this.size === 'compact' ? 'change-row-compact' : 'change-row-normal'
  51. },
  52. /** 上一期数据:优先取 previous prop(report-detail/quick-lookup 是兄弟字段),回退 change.previous(trend 接口嵌套) */
  53. prevData: function() {
  54. if (this.previous) return this.previous
  55. return (this.change && this.change.previous) || null
  56. },
  57. trendInfo: function() {
  58. var ch = this.change
  59. if (!ch || ch.trendCode === 'first_record' || ch.trendCode === 'pending_backfill' || !ch.comparable) {
  60. var tc = (ch && ch.trendCode) || 'first_record'
  61. return resolveChange(tc, ch && ch.movement, ch && ch.trendLabel)
  62. }
  63. return resolveChange(ch.trendCode, ch.movement, ch.trendLabel)
  64. },
  65. trendLabel: function() {
  66. return this.trendInfo.trendLabel
  67. },
  68. trendClass: function() {
  69. if (this.trendInfo.cssClass === 'impr') return 'trend-impr'
  70. if (this.trendInfo.cssClass === 'worst') return 'trend-worst'
  71. return 'trend-flat'
  72. },
  73. arrow: function() {
  74. return this.trendInfo.arrow
  75. },
  76. /** 比较日期文案,"较 MM-DD"(带 * 若 dateSource 非 real/unknown) */
  77. compareDate: function() {
  78. var prev = this.prevData
  79. if (!prev) return ''
  80. var currDate = this.current && this.current.reportDate ? this.current.reportDate : ''
  81. var dateSource = prev.dateSource ? prev.dateSource : ''
  82. return '较 ' + formatCompareDate(prev.reportDate, currDate, dateSource)
  83. },
  84. /** 主体展示文本:{旧值} → {新值} {箭头} {Δ} ({Δ%}) */
  85. displayLine: function() {
  86. var ch = this.change
  87. var prev = this.prevData
  88. if (!ch || !prev) return ''
  89. var oldVal = prev.value !== undefined && prev.value !== null && prev.value !== '' ? prev.value : '--'
  90. var newVal = this.current && (this.current.numericValue !== undefined && this.current.numericValue !== null)
  91. ? this.current.numericValue : (this.current.value || '--')
  92. var unit = this.size !== 'compact' && this.current && this.current.unit ? (' ' + this.current.unit) : ''
  93. var deltaText = formatDelta(ch.delta, ch.deltaPct, ch.unitMismatch)
  94. var unitMark = ch.unitMismatch ? ' *' : ''
  95. return oldVal + ' → ' + newVal + unit + unitMark + ' ' + (this.arrow || '') + ' ' + deltaText
  96. },
  97. /** 跳比提示文案 */
  98. skipHintText: function() {
  99. var ch = this.change
  100. if (!ch || ch.skipGaps <= 0) return ''
  101. var prevDate = this.prevData && this.prevData.reportDate ? this.prevData.reportDate : ''
  102. if (this.skipDates && this.skipDates.length > 0) {
  103. return this.skipDates.join('、') + ' 两期未检测该项,对比的是 ' + prevDate
  104. }
  105. return '中间 ' + ch.skipGaps + ' 期未检测该项,对比的是 ' + prevDate
  106. }
  107. },
  108. methods: {}
  109. }
  110. </script>
  111. <style scoped lang="scss">
  112. .change-row {
  113. display: flex;
  114. flex-direction: column;
  115. align-items: flex-start;
  116. margin-top: 8rpx;
  117. }
  118. .change-row-compact { margin-top: 4rpx; }
  119. .change-main {
  120. display: flex;
  121. flex-direction: row;
  122. align-items: baseline;
  123. }
  124. .change-date {
  125. font-size: 20rpx;
  126. color: #64748B;
  127. margin-right: 10rpx;
  128. }
  129. .change-body {
  130. font-size: 24rpx;
  131. line-height: 34rpx;
  132. }
  133. .change-trend {
  134. font-size: 20rpx;
  135. margin-top: 2rpx;
  136. }
  137. .trend-impr { color: #16A34A; }
  138. .trend-worst { color: #EA580C; }
  139. .trend-flat { color: #94A3B8; }
  140. .change-skip {
  141. font-size: 20rpx;
  142. margin-top: 4rpx;
  143. color: #EA580C;
  144. line-height: 28rpx;
  145. }
  146. .skip-prefix { color: #EA580C; margin-right: 4rpx; }
  147. .skip-text { color: #EA580C; }
  148. </style>