imeik-bizui 2.7.3 → 2.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,8 @@ import {
9
9
  buildResultCopy,
10
10
  computePriceGap,
11
11
  formatNumber,
12
- resolvePanelState
12
+ resolvePanelState,
13
+ roundMoney
13
14
  } from './utils'
14
15
 
15
16
  const SALE_TYPE_LABEL = {
@@ -119,7 +120,8 @@ function summaryColumns() {
119
120
  }
120
121
 
121
122
  function sumBy(rows, prop) {
122
- return (rows || []).reduce((sum, row) => sum + (Number(row[prop]) || 0), 0)
123
+ const total = (rows || []).reduce((sum, row) => sum + (Number(row[prop]) || 0), 0)
124
+ return roundMoney(total)
123
125
  }
124
126
 
125
127
  /** getProductPriceDetail:saleOrderList / noSaleOrderList / costList */
@@ -2,6 +2,13 @@
2
2
  * 底价看板 / 明细弹窗 · 纯展示工具(格式化、默认文案、前端差距推导)
3
3
  */
4
4
 
5
+ /** 前端运算结果统一保留两位小数(避免 45.44999999999999) */
6
+ export function roundMoney(value) {
7
+ const n = Number(value)
8
+ if (!Number.isFinite(n)) return n
9
+ return Math.round(n * 100) / 100
10
+ }
11
+
5
12
  /**
6
13
  * 数值展示:默认按接口原样(不千分位、不截断小数位)。
7
14
  * 仅当显式传入 digits 时才按固定小数位输出。
@@ -61,9 +68,9 @@ export function formatSignedNumber(value, { digits = null, fallback = '-' } = {}
61
68
  * - gap < 0 → 低于底价 / 禁止;文案「低 N 元/支」
62
69
  * - gap > 0 → 通过;文案「高 N 元/支」
63
70
  * - gap = 0 → 持平
64
- * 展示不截断小数位(不用 toLocaleString)
71
+ * 运算结果保留两位小数
65
72
  */
66
- export function computePriceGap(afterPrice, standard, { digits = null } = {}) {
73
+ export function computePriceGap(afterPrice, standard) {
67
74
  const after = Number(afterPrice)
68
75
  const std = Number(standard)
69
76
  if (
@@ -78,13 +85,9 @@ export function computePriceGap(afterPrice, standard, { digits = null } = {}) {
78
85
  ) {
79
86
  return { gap: null, gapLabel: '', hit: false, tone: 'ok' }
80
87
  }
81
- const gap = after - std
88
+ const gap = roundMoney(after - std)
82
89
  const hit = gap < 0
83
- const abs = Math.abs(gap)
84
- const body =
85
- digits === null || digits === undefined
86
- ? String(abs)
87
- : abs.toFixed(digits)
90
+ const body = Math.abs(gap).toFixed(2)
88
91
  let gapLabel = '持平'
89
92
  if (gap < 0) gapLabel = `低 ${body} 元/支`
90
93
  else if (gap > 0) gapLabel = `高 ${body} 元/支`