gongchunyi
5 天以前 58246805d5f5d33ec43e88eca01acefa7dfd9777
src/utils/numberFormat.js
@@ -1,6 +1,9 @@
/** 金额类字段默认最大小数位数 */
export const AMOUNT_DECIMAL_SCALE = 6
/** 金额(元)默认展示小数位数 */
export const MONEY_DECIMAL_SCALE = 2
/**
 * 格式化数字:最多保留 scale 位小数,并去除末尾多余的 0
 */
@@ -25,6 +28,11 @@
  return formatDecimal(cellValue)
}
/** el-table-column formatter:金额(元)列,最多保留 2 位小数 */
export function moneyAmountFormatter(row, column, cellValue) {
  return formatDecimal(cellValue, MONEY_DECIMAL_SCALE)
}
/** 计算后保留指定位小数 */
export function roundAmount(value, scale = AMOUNT_DECIMAL_SCALE) {
  if (value === null || value === undefined || value === '') {
@@ -38,10 +46,14 @@
}
/** 构建 summarizeTable 金额列格式配置 */
export function buildAmountSummaryFormat(fields, extraFormat = {}) {
export function buildAmountSummaryFormat(
  fields,
  extraFormat = {},
  scale = AMOUNT_DECIMAL_SCALE
) {
  const format = { ...extraFormat }
  fields.forEach(field => {
    format[field] = { decimalPlaces: AMOUNT_DECIMAL_SCALE }
    format[field] = { decimalPlaces: scale }
  })
  return format
}