diff --git a/src/modules/first-leg/components/InboundBillingPanel.test.mjs b/src/modules/first-leg/components/InboundBillingPanel.test.mjs index 98edded..083ba22 100644 --- a/src/modules/first-leg/components/InboundBillingPanel.test.mjs +++ b/src/modules/first-leg/components/InboundBillingPanel.test.mjs @@ -19,7 +19,7 @@ test('shows the confirmed merchant inbound and fee fields without write actions' assert.match(source, new RegExp(label)) } assert.match(source, /formatInboundMoney\(props\.data\.latestFee\.totalAmount/) - assert.match(source, /getRoundingModeLabel\(props\.data\.latestFee\.roundingMode\)/) + assert.match(source, /formatConversionPrecision\(/) assert.doesNotMatch(source, /确认费用|调整费用|发送费用|下载照片/) assert.doesNotMatch(source, /internalNotes|statusHistory|files/) assert.match(source, /latestFee\.ruleCode/) diff --git a/src/modules/first-leg/components/InboundBillingPanel.vue b/src/modules/first-leg/components/InboundBillingPanel.vue index 0b15be3..ec715c1 100644 --- a/src/modules/first-leg/components/InboundBillingPanel.vue +++ b/src/modules/first-leg/components/InboundBillingPanel.vue @@ -2,12 +2,12 @@ import { Clock3, PackageCheck, RefreshCw, TriangleAlert } from '@lucide/vue' import type { MerchantInboundBilling } from '@/modules/first-leg/types/inboundBilling' import { + formatConversionPrecision, formatInboundDateTime, formatInboundMeasure, formatInboundMoney, formatInboundNumber, getChargeModeLabel, - getRoundingModeLabel, getTaxModeLabel, } from '@/modules/first-leg/utils/inboundBilling' @@ -109,10 +109,11 @@ defineEmits<{
计费方式
{{ getChargeModeLabel(props.data.latestFee.chargeMode) }} · {{ getTaxModeLabel(props.data.latestFee.taxMode) }}
换算与精度
-
- 系数 {{ formatInboundNumber(props.data.latestFee.conversionFactor) }} · - 保留 {{ props.data.latestFee.roundingScale }} 位 {{ getRoundingModeLabel(props.data.latestFee.roundingMode) }} -
+
{{ formatConversionPrecision( + props.data.latestFee.conversionFactor, + props.data.latestFee.roundingScale, + props.data.latestFee.roundingMode, + ) }}
实际重量
{{ formatInboundMeasure(props.data.latestFee.actualWeightKg, 'kg') }}
实际体积
{{ formatInboundMeasure(props.data.latestFee.actualVolumeCbm, 'm³') }}
diff --git a/src/modules/first-leg/types/inboundBilling.ts b/src/modules/first-leg/types/inboundBilling.ts index e700078..68ffe25 100644 --- a/src/modules/first-leg/types/inboundBilling.ts +++ b/src/modules/first-leg/types/inboundBilling.ts @@ -79,9 +79,9 @@ export interface MerchantInboundFeeSnapshot { destinationCode: string taxMode: string chargeMode: 'KG' | 'CBM' - conversionFactor: number - roundingScale: number - roundingMode: string + conversionFactor: number | null + roundingScale: number | null + roundingMode: string | null actualWeightKg: number actualVolumeCbm: number convertedQuantity: number diff --git a/src/modules/first-leg/utils/inboundBilling.test.mjs b/src/modules/first-leg/utils/inboundBilling.test.mjs index bb093f5..fec95b4 100644 --- a/src/modules/first-leg/utils/inboundBilling.test.mjs +++ b/src/modules/first-leg/utils/inboundBilling.test.mjs @@ -16,5 +16,12 @@ test('translates backend rounding modes into customer-facing calculation labels' assert.match(source, /export function getRoundingModeLabel/) assert.match(source, /CEILING: '向上取整'/) assert.match(source, /HALF_UP: '四舍五入'/) - assert.match(source, /return labels\[value\] \|\| value \|\| '-'/) + assert.match(source, /return value \? labels\[value\] \|\| value : '-'/) +}) + +test('renders conversion metadata as one complete label or a single empty marker', () => { + assert.match(source, /export function formatConversionPrecision/) + assert.match(source, /roundingScale === null \|\| roundingScale === undefined/) + assert.match(source, /\|\| !roundingMode\) return '-'/) + assert.match(source, /`系数 \$\{formatInboundNumber\(conversionFactor\)\} · 保留 \$\{roundingScale\} 位 \$\{getRoundingModeLabel\(roundingMode\)\}`/) }) diff --git a/src/modules/first-leg/utils/inboundBilling.ts b/src/modules/first-leg/utils/inboundBilling.ts index 842cd58..600fcad 100644 --- a/src/modules/first-leg/utils/inboundBilling.ts +++ b/src/modules/first-leg/utils/inboundBilling.ts @@ -46,7 +46,7 @@ export function getTaxModeLabel(value: string) { return value || '-' } -export function getRoundingModeLabel(value: string) { +export function getRoundingModeLabel(value: string | null | undefined) { const labels: Record = { UP: '向上舍入', DOWN: '向下舍入', @@ -56,5 +56,16 @@ export function getRoundingModeLabel(value: string) { HALF_DOWN: '五舍六入', HALF_EVEN: '银行家舍入', } - return labels[value] || value || '-' + return value ? labels[value] || value : '-' +} + +export function formatConversionPrecision( + conversionFactor: number | null | undefined, + roundingScale: number | null | undefined, + roundingMode: string | null | undefined, +) { + if (conversionFactor === null || conversionFactor === undefined + || roundingScale === null || roundingScale === undefined + || !roundingMode) return '-' + return `系数 ${formatInboundNumber(conversionFactor)} · 保留 ${roundingScale} 位 ${getRoundingModeLabel(roundingMode)}` }