IndicatorChangeRow.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view v-if="rowVisible" class="change-row" :class="sizeClass">
  3. <!-- 第一行:较 MM-DD + 旧值 → 新值 + Δ (Δ%) + 趋势词(无对照/不可比时整行隐藏) -->
  4. <view class="change-main" v-if="displayLine">
  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. /**
  58. * 趋势展示(design §6.2 五档 + §6.6 单一事实来源)
  59. * change == null → 中性兜底(灰,无箭头)
  60. * change.comparable == false → 档 D 不可比(灰,无箭头)
  61. * · 后端 trendLabel 优先:非数值「有变化/无变化」、B1「首次记录 · 暂无对比」、
  62. * B2「历史数据整理中,暂无法对比」均不被覆盖;后端未下发时兜底「无法比较」
  63. * 其余 → resolveChange(trendCode, movement, trendLabel)
  64. */
  65. trendInfo: function() {
  66. var ch = this.change
  67. if (!ch) return resolveChange('first_record', 'none', '')
  68. if (ch.comparable === false) {
  69. return {
  70. trendLabel: ch.trendLabel || '无法比较',
  71. cssClass: 'degrade',
  72. arrow: '',
  73. colorClass: 'gray-text',
  74. showArrow: false
  75. }
  76. }
  77. return resolveChange(ch.trendCode || 'flat', ch.movement, ch.trendLabel)
  78. },
  79. trendLabel: function() {
  80. return this.trendInfo.trendLabel
  81. },
  82. trendClass: function() {
  83. if (this.trendInfo.cssClass === 'impr') return 'trend-impr'
  84. if (this.trendInfo.cssClass === 'worst') return 'trend-worst'
  85. return 'trend-flat'
  86. },
  87. arrow: function() {
  88. return this.trendInfo.arrow
  89. },
  90. /** 比较日期文案,"较 MM-DD"(带 * 若 dateSource 非 real/unknown) */
  91. compareDate: function() {
  92. var prev = this.prevData
  93. if (!prev) return ''
  94. var currDate = this.current && this.current.reportDate ? this.current.reportDate : ''
  95. var dateSource = prev.dateSource ? prev.dateSource : ''
  96. return '较 ' + formatCompareDate(prev.reportDate, currDate, dateSource)
  97. },
  98. /** 主体展示文本:{旧值} → {新值} {箭头} {Δ} ({Δ%}) */
  99. displayLine: function() {
  100. var ch = this.change
  101. var prev = this.prevData
  102. if (!ch || !prev) return ''
  103. // 不可比 / 无对比对象:不渲染数值对照行(只留下方趋势文案行)
  104. if (ch.comparable === false) return ''
  105. var oldVal = prev.value !== undefined && prev.value !== null && prev.value !== '' ? prev.value : '--'
  106. var newVal = this.current && (this.current.numericValue !== undefined && this.current.numericValue !== null)
  107. ? this.current.numericValue : (this.current.value || '--')
  108. var unit = this.size !== 'compact' && this.current && this.current.unit ? (' ' + this.current.unit) : ''
  109. var deltaText = formatDelta(ch.delta, ch.deltaPct, ch.unitMismatch)
  110. var unitMark = ch.unitMismatch ? ' *' : ''
  111. return oldVal + ' → ' + newVal + unit + unitMark + ' ' + (this.arrow || '') + ' ' + deltaText
  112. },
  113. /** 跳比提示文案 */
  114. skipHintText: function() {
  115. var ch = this.change
  116. if (!ch || ch.skipGaps <= 0) return ''
  117. var prevDate = this.prevData && this.prevData.reportDate ? this.prevData.reportDate : ''
  118. if (this.skipDates && this.skipDates.length > 0) {
  119. return this.skipDates.join('、') + ' 两期未检测该项,对比的是 ' + prevDate
  120. }
  121. return '中间 ' + ch.skipGaps + ' 期未检测该项,对比的是 ' + prevDate
  122. }
  123. },
  124. methods: {}
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. .change-row {
  129. display: flex;
  130. flex-direction: column;
  131. align-items: flex-start;
  132. margin-top: 8rpx;
  133. }
  134. .change-row-compact { margin-top: 4rpx; }
  135. .change-main {
  136. display: flex;
  137. flex-direction: row;
  138. align-items: baseline;
  139. }
  140. .change-date {
  141. font-size: 20rpx;
  142. color: #64748B;
  143. margin-right: 10rpx;
  144. }
  145. .change-body {
  146. font-size: 24rpx;
  147. line-height: 34rpx;
  148. }
  149. .change-trend {
  150. font-size: 20rpx;
  151. margin-top: 2rpx;
  152. }
  153. .trend-impr { color: #16A34A; }
  154. .trend-worst { color: #EA580C; }
  155. .trend-flat { color: #94A3B8; }
  156. .change-skip {
  157. font-size: 20rpx;
  158. margin-top: 4rpx;
  159. color: #EA580C;
  160. line-height: 28rpx;
  161. }
  162. .skip-prefix { color: #EA580C; margin-right: 4rpx; }
  163. .skip-text { color: #EA580C; }
  164. </style>