IndicatorChangeRow.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="indicator-change-row">
  3. <block v-if="isDegrade || isIncomparable">
  4. <text class="change-degrade gray-text">{{ resolved.trendLabel }}</text>
  5. </block>
  6. <block v-else>
  7. <text class="change-compare-label gray-text-subtle">较{{ prevDateText }}{{ prevDateStar }}:</text>
  8. <text class="change-values">{{ prevValue }} → {{ currValue }}{{ unitText }}{{ valueStar }}</text>
  9. <text v-if="showArrow" class="change-arrow" :class="colorClass">{{ arrow }}</text>
  10. <text class="change-delta" :class="colorClass">{{ deltaText }}</text>
  11. <text class="change-trend" :class="colorClass">{{ trendLabel }}</text>
  12. </block>
  13. <view v-if="showSkipHint && skipGaps > 0" class="skip-row">
  14. <text class="skip-text">ⓘ {{ skipHintText }}</text>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import { resolveChange, formatDelta } from '@/utils/indicator-change.js'
  20. export default {
  21. name: 'IndicatorChangeRow',
  22. props: {
  23. /** 上一期 { reportDate, dateSource, value, numericValue, unit, status } | null */
  24. previous: { type: Object, default: null },
  25. /** 本期 { value, numericValue, unit } */
  26. current: { type: Object, required: true },
  27. /** { delta, deltaPct, movement, trendLabel, trendCode, skipGaps, unitMismatch, comparable } | null */
  28. change: { type: Object, default: null },
  29. /** 'normal' 报告详情/时间轴 | 'compact' 列表窄位(省略单位) */
  30. size: { type: String, default: 'normal' },
  31. /** 是否显示跨期跳比提示行 */
  32. showSkipHint: { type: Boolean, default: true },
  33. /** 跳比提示的具体缺失日期列表(可选,不传则显示「中间 N 期未检测该项」) */
  34. skipDates: { type: Array, default: function() { return [] } }
  35. },
  36. computed: {
  37. /**
  38. * 【单一事实来源】消费后端 trendCode,优先使用后端下发的 trendLabel。
  39. * 兼容老数据:无 trendCode 时按 previous 有无走 first_record 兜底,
  40. * 前端不按 delta 正负自行推导改善/恶化。
  41. */
  42. resolved: function() {
  43. var ch = this.change
  44. var code = ch && ch.trendCode
  45. if (code) {
  46. return resolveChange(code, ch.movement, ch.trendLabel)
  47. }
  48. // 老数据兜底:无 trendCode 时,previous 为空 → 首次记录
  49. if (!this.previous) return resolveChange('first_record', 'none')
  50. return resolveChange('flat', 'flat')
  51. },
  52. /** 降级态:首次记录 / 历史整理中 */
  53. isDegrade: function() {
  54. var ch = this.change
  55. return ch && (ch.trendCode === 'first_record' || ch.trendCode === 'pending_backfill')
  56. },
  57. /** 不可比态:非数值 / 单位不可比(trendCode 仍走前端,文案由后端下发) */
  58. isIncomparable: function() {
  59. var ch = this.change
  60. return ch && ch.comparable === false && !this.isDegrade
  61. },
  62. colorClass: function() {
  63. return this.resolved && this.resolved.colorClass || 'gray-text'
  64. },
  65. showArrow: function() {
  66. return this.resolved && this.resolved.showArrow === true
  67. },
  68. arrow: function() {
  69. return this.resolved ? this.resolved.arrow : ''
  70. },
  71. trendLabel: function() {
  72. return this.resolved ? this.resolved.trendLabel : ''
  73. },
  74. /** 上一期日期文案 + 上传日 * 标记 */
  75. prevDateText: function() {
  76. var pd = this.previous && this.previous.reportDate
  77. var cd = this.current && this.current.reportDate
  78. if (!pd) return '未知日期'
  79. if (!cd) return pd
  80. var sameYear = String(pd).slice(0, 4) === String(cd).slice(0, 4)
  81. return sameYear ? String(pd).slice(5) : pd
  82. },
  83. prevDateStar: function() {
  84. var ds = this.previous && this.previous.dateSource
  85. return (ds && ds !== 'real' && ds !== 'unknown') ? '*' : ''
  86. },
  87. prevValue: function() {
  88. if (!this.previous) return '--'
  89. return this.previous.value != null ? this.previous.value : '--'
  90. },
  91. currValue: function() {
  92. if (!this.current) return '--'
  93. return this.current.value != null ? this.current.value : '--'
  94. },
  95. unitText: function() {
  96. if (this.size === 'compact') return ''
  97. return this.current && this.current.unit ? ' ' + this.current.unit : ''
  98. },
  99. /** 单位不一致 → 值后加 * */
  100. valueStar: function() {
  101. var ch = this.change
  102. return ch && ch.unitMismatch ? '*' : ''
  103. },
  104. /** Δ 展示文本(PRD §6.4:unitMismatch 时百分比显示 —) */
  105. deltaText: function() {
  106. var ch = this.change
  107. if (!ch || ch.delta == null) return '--'
  108. return formatDelta(ch.delta, ch.deltaPct, ch.unitMismatch)
  109. },
  110. skipGaps: function() {
  111. var ch = this.change
  112. return ch && ch.skipGaps ? ch.skipGaps : 0
  113. },
  114. skipHintText: function() {
  115. if (this.skipDates && this.skipDates.length > 0) {
  116. return this.skipDates.join('、') + ' 多次未检测该项,对比的是更早期'
  117. }
  118. return '中间 ' + this.skipGaps + ' 期未检测该项'
  119. }
  120. }
  121. }
  122. </script>
  123. <style scoped lang="scss">
  124. .indicator-change-row {
  125. padding: 8rpx 0;
  126. font-size: calc(22rpx * var(--font-scale, 1));
  127. line-height: 1.6;
  128. }
  129. .change-compare-label { color: $app-text-subtle; }
  130. .gray-text-subtle { color: $app-text-subtle; }
  131. .change-values { color: $facade-text-strong; }
  132. .change-delta { font-weight: 600; }
  133. .change-trend { font-weight: 500; }
  134. /* 变化着色:改善=绿 / 恶化=橙红 / 中性=灰(双通道解耦,颜色=变化性质) */
  135. .green-text { color: $status-success-strong-2; }
  136. .red-text { color: $status-danger-deep; }
  137. .gray-text { color: $app-text-subtle; }
  138. /* 第三行:跨期跳比提示 */
  139. .skip-row { display: block; padding-top: 4rpx; }
  140. .skip-text {
  141. font-size: calc(20rpx * var(--font-scale, 1));
  142. color: $mat-orange-base;
  143. }
  144. </style>