diff --git a/package.json b/package.json index 8ad3b06..beff0fb 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", + "prod": "tsc -b && vite build --base calc", "lint": "eslint .", "preview": "vite preview" }, diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..5ed0b5a --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +allowBuilds: + esbuild: true diff --git a/src/App.tsx b/src/App.tsx index ed6127e..616a054 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,21 +26,21 @@ const packages: Package[] = [ const COMBO_DISCOUNT = 5; const DEPOSIT_RATE = 0.5; -/** 当「订单金额 ×50%」低于该值,且订单金额超过该值时,定金取该值 */ -const DEPOSIT_FLOOR = 50; +/** 定金封顶:50% 超过该值时只收该金额,避免大额订单定金过高 */ +const DEPOSIT_CAP = 50; function formatMoney(n: number): string { return n % 1 === 0 ? String(n) : n.toFixed(1); } -/** 定金:默认 50%;若 50% 不足 50 元且订单超过 50 元,则定金为 50 元(且不超过订单总额) */ -function computeDeposit(finalPrice: number): { amount: number; isFloor50: boolean; half: number } { - if (finalPrice <= 0) return { amount: 0, isFloor50: false, half: 0 }; +/** 定金:默认应付的 50%;若 50% 超过 50 元则封顶 50 元(且不超过订单总额) */ +function computeDeposit(finalPrice: number): { amount: number; isCapped: boolean; half: number } { + if (finalPrice <= 0) return { amount: 0, isCapped: false, half: 0 }; const half = finalPrice * DEPOSIT_RATE; - if (finalPrice > DEPOSIT_FLOOR && half < DEPOSIT_FLOOR) { - return { amount: Math.min(DEPOSIT_FLOOR, finalPrice), isFloor50: true, half }; + if (half > DEPOSIT_CAP) { + return { amount: Math.min(DEPOSIT_CAP, finalPrice), isCapped: true, half }; } - return { amount: half, isFloor50: false, half }; + return { amount: half, isCapped: false, half }; } function App() { @@ -70,7 +70,7 @@ function App() { const hasCombo = selectedSingle.length > 0 && selectedDual.length > 0; const finalPrice = hasCombo ? originalTotal - COMBO_DISCOUNT : originalTotal; - const { amount: deposit, isFloor50, half: depositHalf } = computeDeposit(finalPrice); + const { amount: deposit, isCapped, half: depositHalf } = computeDeposit(finalPrice); const balance = finalPrice - deposit; const totalSinglePhotos = selectedSingle.reduce((sum, p) => sum + p.photos * getQty(p.id), 0); @@ -218,9 +218,9 @@ function App() {
定金 - {isFloor50 ? ( + {isCapped ? ( - ({DEPOSIT_RATE * 100}% 为 {formatMoney(depositHalf)} 元,不足 ¥{DEPOSIT_FLOOR};订单 > ¥{DEPOSIT_FLOOR} 时收 ¥{DEPOSIT_FLOOR} 定金) + ({DEPOSIT_RATE * 100}% 为 {formatMoney(depositHalf)} 元,超过 ¥{DEPOSIT_CAP} 时封顶 ¥{DEPOSIT_CAP}) ) : ( (应付×{DEPOSIT_RATE * 100}%) @@ -253,9 +253,9 @@ function App() {

定金: - {isFloor50 ? ( + {isCapped ? ( - 应付 {formatMoney(finalPrice)} × {DEPOSIT_RATE} = {formatMoney(depositHalf)} 元 < ¥{DEPOSIT_FLOOR},且应付 > ¥{DEPOSIT_FLOOR},收{" "} + 应付 {formatMoney(finalPrice)} × {DEPOSIT_RATE} = {formatMoney(depositHalf)} 元 > ¥{DEPOSIT_CAP},封顶收{" "} ¥{formatMoney(deposit)};尾款 ¥{formatMoney(balance)} ) : finalPrice > 0 ? ( @@ -272,7 +272,7 @@ function App() {

);