imeik-bizui 2.7.2 → 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.
@@ -242,10 +242,10 @@ export default {
242
242
  type: Boolean,
243
243
  default: false
244
244
  },
245
- /** 价格/金额小数位,默认两位 */
245
+ /** 价格/金额小数位;默认 null 不强制,跟随接口原值 */
246
246
  numberDigits: {
247
247
  type: Number,
248
- default: 2
248
+ default: null
249
249
  },
250
250
  maxColumns: {
251
251
  type: Number,
@@ -309,7 +309,7 @@ export default {
309
309
  },
310
310
  applyTotalFeeText() {
311
311
  if (this.applyTotalFee == null || this.applyTotalFee === '') return ''
312
- return `${formatNumber(this.applyTotalFee, { digits: this.numberDigits })} 元`
312
+ return `${formatNumber(this.applyTotalFee)} 元`
313
313
  },
314
314
  yearText() {
315
315
  if (this.year == null || this.year === '') return ''
@@ -397,9 +397,9 @@ export default {
397
397
  },
398
398
  formatCell(value, col = {}) {
399
399
  if (col.type === 'number' || col.type === 'highlight' || col.digits != null) {
400
- // 价格/金额统一两位小数;数量列勿标 type:number,或显式 digits:null
400
+ // 金额按接口原样展示(不千分位、不截断小数)
401
401
  return formatNumber(value, {
402
- digits: col.digits != null ? col.digits : 2,
402
+ digits: col.digits != null ? col.digits : null,
403
403
  fallback: '-'
404
404
  })
405
405
  }
@@ -408,7 +408,7 @@ export default {
408
408
  },
409
409
  formatGapCell(value, col = {}) {
410
410
  return formatSignedNumber(value, {
411
- digits: col.digits != null ? col.digits : 2,
411
+ digits: col.digits != null ? col.digits : null,
412
412
  fallback: '-'
413
413
  })
414
414
  },
@@ -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 */
@@ -149,7 +151,7 @@ function buildSections(data = {}) {
149
151
  footer: {
150
152
  label: '合计(含本次)',
151
153
  theme: 'purple',
152
- values: [`金额 ${formatNumber(sumBy(saleRows, 'amount'), { digits: 2 })}`]
154
+ values: [`金额 ${formatNumber(sumBy(saleRows, 'amount'))}`]
153
155
  }
154
156
  })
155
157
  }
@@ -171,7 +173,7 @@ function buildSections(data = {}) {
171
173
  theme: 'danger',
172
174
  values: [
173
175
  `数量 ${formatNumber(sumBy(nonSaleRows, 'qty'))}`,
174
- `折算费用 ${formatNumber(sumBy(nonSaleRows, 'amount'), { digits: 2 })}`
176
+ `折算费用 ${formatNumber(sumBy(nonSaleRows, 'amount'))}`
175
177
  ]
176
178
  }
177
179
  })
@@ -191,7 +193,7 @@ function buildSections(data = {}) {
191
193
  footer: {
192
194
  label: '合计(含本次)',
193
195
  theme: 'danger',
194
- values: [formatNumber(sumBy(expenseRows, 'costAmount'), { digits: 2 })]
196
+ values: [formatNumber(sumBy(expenseRows, 'costAmount'))]
195
197
  }
196
198
  })
197
199
  }
@@ -2,40 +2,62 @@
2
2
  * 底价看板 / 明细弹窗 · 纯展示工具(格式化、默认文案、前端差距推导)
3
3
  */
4
4
 
5
- /** 千分位金额/数量;无效值返回 fallback */
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
+
12
+ /**
13
+ * 数值展示:默认按接口原样(不千分位、不截断小数位)。
14
+ * 仅当显式传入 digits 时才按固定小数位输出。
15
+ * 注意:toLocaleString 默认最多 3 位小数,会导致四位金额被截断,故原样路径不用它。
16
+ */
6
17
  export function formatNumber(value, { digits = null, fallback = '-' } = {}) {
7
18
  if (value === undefined || value === null || value === '') return fallback
8
- const n = Number(value)
9
- if (Number.isNaN(n)) return String(value)
19
+
10
20
  if (digits === null || digits === undefined) {
11
- return n.toLocaleString('zh-CN')
21
+ if (typeof value === 'string') {
22
+ const s = value.trim()
23
+ if (s === '') return fallback
24
+ if (Number.isNaN(Number(s))) return fallback
25
+ return s
26
+ }
27
+ const n = Number(value)
28
+ if (Number.isNaN(n)) return String(value)
29
+ return String(n)
12
30
  }
13
- return n.toLocaleString('zh-CN', {
14
- minimumFractionDigits: digits,
15
- maximumFractionDigits: digits
16
- })
31
+
32
+ const n = Number(value)
33
+ if (Number.isNaN(n)) return String(value)
34
+ return n.toFixed(digits)
17
35
  }
18
36
 
19
- /** 金额带 ¥,如 ¥ 800.00;价格/金额默认保留两位小数 */
20
- export function formatMoney(value, { digits = 2, fallback = '-' } = {}) {
37
+ /** 金额带 ¥;默认跟随接口原值,如 ¥ 2401.4385 */
38
+ export function formatMoney(value, { digits = null, fallback = '-' } = {}) {
21
39
  const body = formatNumber(value, { digits, fallback: null })
22
40
  if (body == null) return fallback
23
41
  return `¥ ${body}`
24
42
  }
25
43
 
26
- /** 带正负号的差距展示,如 -23.68 / +3.10;金额默认两位小数 */
27
- export function formatSignedNumber(value, { digits = 2, fallback = '-' } = {}) {
44
+ /** 绝对值的原样展示(去掉正负号) */
45
+ function rawAbsBody(value, n) {
46
+ if (typeof value === 'string') {
47
+ return value.trim().replace(/^[+-]/, '')
48
+ }
49
+ return String(Math.abs(n))
50
+ }
51
+
52
+ /** 带正负号的差距展示;默认跟随原精度,如 +23.6800 / -3.1 */
53
+ export function formatSignedNumber(value, { digits = null, fallback = '-' } = {}) {
28
54
  if (value === undefined || value === null || value === '') return fallback
29
55
  const n = Number(value)
30
56
  if (Number.isNaN(n)) return String(value)
31
- const abs = Math.abs(n)
32
57
  const body =
33
58
  digits === null || digits === undefined
34
- ? abs.toLocaleString('zh-CN')
35
- : abs.toLocaleString('zh-CN', {
36
- minimumFractionDigits: digits,
37
- maximumFractionDigits: digits
38
- })
59
+ ? rawAbsBody(value, n)
60
+ : Math.abs(n).toFixed(digits)
39
61
  if (n > 0) return `+${body}`
40
62
  if (n < 0) return `-${body}`
41
63
  return body
@@ -46,9 +68,9 @@ export function formatSignedNumber(value, { digits = 2, fallback = '-' } = {}) {
46
68
  * - gap < 0 → 低于底价 / 禁止;文案「低 N 元/支」
47
69
  * - gap > 0 → 通过;文案「高 N 元/支」
48
70
  * - gap = 0 → 持平
49
- * digits 默认 2,与看板/明细金额展示一致
71
+ * 运算结果保留两位小数
50
72
  */
51
- export function computePriceGap(afterPrice, standard, { digits = 2 } = {}) {
73
+ export function computePriceGap(afterPrice, standard) {
52
74
  const after = Number(afterPrice)
53
75
  const std = Number(standard)
54
76
  if (
@@ -63,16 +85,9 @@ export function computePriceGap(afterPrice, standard, { digits = 2 } = {}) {
63
85
  ) {
64
86
  return { gap: null, gapLabel: '', hit: false, tone: 'ok' }
65
87
  }
66
- const gap = after - std
88
+ const gap = roundMoney(after - std)
67
89
  const hit = gap < 0
68
- const abs = Math.abs(gap)
69
- const body =
70
- digits === null || digits === undefined
71
- ? abs.toLocaleString('zh-CN')
72
- : abs.toLocaleString('zh-CN', {
73
- minimumFractionDigits: digits,
74
- maximumFractionDigits: digits
75
- })
90
+ const body = Math.abs(gap).toFixed(2)
76
91
  let gapLabel = '持平'
77
92
  if (gap < 0) gapLabel = `低 ${body} 元/支`
78
93
  else if (gap > 0) gapLabel = `高 ${body} 元/支`