| | |
| | | import { formatDecimal, AMOUNT_DECIMAL_SCALE } from './numberFormat' |
| | | |
| | | /** |
| | | * 通用的表格合计方法 |
| | | * @param {Object} param - 包含表格列配置和数据源的对象 |
| | |
| | | // 如果指定了不需要保留小数,则直接转换为整数 |
| | | sums[index] = Math.round(sum).toString(); |
| | | } else { |
| | | // 默认保留两位小数 |
| | | sums[index] = parseFloat(sum).toFixed( |
| | | sums[index] = formatDecimal( |
| | | sum, |
| | | specialFormat[prop]?.decimalPlaces ?? 2 |
| | | ); |
| | | } |
| | | } else { |
| | | sums[index] = ""; |
| | | sums[index] = ''; |
| | | } |
| | | } else { |
| | | sums[index] = ""; |
| | | sums[index] = ''; |
| | | } |
| | | }); |
| | | return sums; |
| | | }; |
| | | |
| | | // 不含税总价计算 |
| | | const calculateTaxExclusiveTotalPrice = (taxInclusiveTotalPrice, taxRate) => { |
| | | const taxRateDecimal = taxRate / 100; |
| | | return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(2); |
| | | return formatDecimal( |
| | | Number(taxInclusiveTotalPrice) / (1 + taxRateDecimal), |
| | | AMOUNT_DECIMAL_SCALE |
| | | ); |
| | | }; |
| | | // 含税总价计算 |
| | | const calculateTaxIncludeTotalPrice = (taxInclusiveUnitPrice, quantity) => { |
| | | return (taxInclusiveUnitPrice * quantity).toFixed(2); |
| | | return formatDecimal( |
| | | Number(taxInclusiveUnitPrice) * Number(quantity), |
| | | AMOUNT_DECIMAL_SCALE |
| | | ); |
| | | }; |
| | | // 导出函数供其他文件使用 |
| | | export { |