Files
client-web/src/modules/first-leg/utils/priceEstimate.ts
T

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2026-08-21 09:59:58 +08:00
const KG_PER_CBM = 167
const KG_PER_BILLABLE_CBM = 363
function formatFormulaNumber(value: number) {
return value.toLocaleString('zh-CN', { maximumFractionDigits: 6, useGrouping: false })
}
export interface PriceEstimateBreakdown {
actualLabel: string
actualQuantity: number
convertedLabel: string
convertedQuantity: number
convertedFormula: string
chargeableLabel: string
basisLabel: string
}
/**
* Explains the server's current first-leg chargeable-quantity rules. The server
* response remains authoritative for the final chargeable quantity and amount.
*/
export function createPriceEstimateBreakdown(
actualWeightKg: number,
actualVolumeCbm: number,
chargeUnit: string,
): PriceEstimateBreakdown | null {
if (chargeUnit === 'KG') {
const volumeWeightKg = actualVolumeCbm * KG_PER_CBM
return {
actualLabel: '实际毛重',
actualQuantity: actualWeightKg,
convertedLabel: '体积重量',
convertedQuantity: volumeWeightKg,
convertedFormula: `${formatFormulaNumber(actualVolumeCbm)} m³ × ${KG_PER_CBM}`,
chargeableLabel: '计费重量',
basisLabel: actualWeightKg >= volumeWeightKg ? '采用实际毛重' : '采用体积重量',
}
}
if (chargeUnit === 'CBM') {
const convertedVolumeCbm = actualWeightKg / KG_PER_BILLABLE_CBM
return {
actualLabel: '实际体积',
actualQuantity: actualVolumeCbm,
convertedLabel: '重量折算体积',
convertedQuantity: convertedVolumeCbm,
convertedFormula: `${formatFormulaNumber(actualWeightKg)} KG ÷ ${KG_PER_BILLABLE_CBM}`,
chargeableLabel: '计费体积',
basisLabel: actualVolumeCbm >= convertedVolumeCbm ? '采用实际体积' : '采用重量折算体积',
}
}
return null
}