diff --git a/src/App.css b/src/App.css index 8ecbe12..af13613 100644 --- a/src/App.css +++ b/src/App.css @@ -257,11 +257,13 @@ .selected-grid { display: grid; - grid-template-columns: 1fr auto 1fr; + grid-template-columns: 1fr auto 1fr auto 1fr; gap: 0; } .selected-column { + display: flex; + flex-direction: column; padding: 0 0.5rem; } @@ -275,7 +277,7 @@ font-size: 0.88rem; font-weight: 600; color: #555; - margin: 0 0 0.6rem; + margin: 0 0 0.3rem; padding-bottom: 0.4rem; border-bottom: 2px solid #f0f0f0; } @@ -288,6 +290,10 @@ margin: 0; } +.selected-list { + flex: 1; +} + .selected-item { display: flex; justify-content: space-between; diff --git a/src/App.tsx b/src/App.tsx index 616a054..6236c1c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,7 +3,7 @@ import "./App.css"; interface Package { id: string; - type: "single" | "dual"; + type: "single" | "dual" | "edit"; photos: number; price: number; postProcessing: string; @@ -13,14 +13,15 @@ interface Package { } const packages: Package[] = [ - { id: "s1", type: "single", photos: 1, price: 10, postProcessing: "调色简修", note: "一张不接,附加项", available: true, isAddon: true }, - { id: "s4", type: "single", photos: 4, price: 40, postProcessing: "调色简修", note: "", available: true, isAddon: false }, - { id: "s6", type: "single", photos: 6, price: 55, postProcessing: "调色简修", note: "", available: true, isAddon: false }, + { id: "s1", type: "single", photos: 1, price: 10, postProcessing: "包调色", note: "一张不接,附加项", available: true, isAddon: true }, + { id: "s4", type: "single", photos: 4, price: 40, postProcessing: "包调色", note: "", available: true, isAddon: false }, + { id: "s6", type: "single", photos: 6, price: 55, postProcessing: "包调色", note: "", available: true, isAddon: false }, { id: "s9", type: "single", photos: 9, price: 0, postProcessing: "", note: "暂不接", available: false, isAddon: false }, - { id: "d1", type: "dual", photos: 1, price: 15, postProcessing: "调色简修", note: "一张不接,附加项", available: true, isAddon: true }, - { id: "d2", type: "dual", photos: 2, price: 30, postProcessing: "调色简修", note: "", available: true, isAddon: false }, - { id: "d4", type: "dual", photos: 4, price: 65, postProcessing: "调色简修", note: "", available: true, isAddon: false }, + { id: "d1", type: "dual", photos: 1, price: 15, postProcessing: "包调色", note: "一张不接,附加项", available: true, isAddon: true }, + { id: "d2", type: "dual", photos: 2, price: 30, postProcessing: "包调色", note: "", available: true, isAddon: false }, + { id: "d4", type: "dual", photos: 4, price: 65, postProcessing: "包调色", note: "", available: true, isAddon: false }, { id: "d6", type: "dual", photos: 6, price: 0, postProcessing: "", note: "暂不接", available: false, isAddon: false }, + { id: "e1", type: "edit", photos: 1, price: 5, postProcessing: "简修", note: "", available: true, isAddon: false }, ]; const COMBO_DISCOUNT = 5; @@ -64,9 +65,16 @@ function App() { [quantities] ); + const selectedEdit = useMemo( + () => packages.filter((p) => p.type === "edit" && getQty(p.id) > 0), + // eslint-disable-next-line react-hooks/exhaustive-deps + [quantities] + ); + const singleSubtotal = selectedSingle.reduce((sum, p) => sum + p.price * getQty(p.id), 0); const dualSubtotal = selectedDual.reduce((sum, p) => sum + p.price * getQty(p.id), 0); - const originalTotal = singleSubtotal + dualSubtotal; + const editSubtotal = selectedEdit.reduce((sum, p) => sum + p.price * getQty(p.id), 0); + const originalTotal = singleSubtotal + dualSubtotal + editSubtotal; const hasCombo = selectedSingle.length > 0 && selectedDual.length > 0; const finalPrice = hasCombo ? originalTotal - COMBO_DISCOUNT : originalTotal; @@ -75,12 +83,14 @@ function App() { const totalSinglePhotos = selectedSingle.reduce((sum, p) => sum + p.photos * getQty(p.id), 0); const totalDualPhotos = selectedDual.reduce((sum, p) => sum + p.photos * getQty(p.id), 0); + const totalEditPhotos = selectedEdit.reduce((sum, p) => sum + p.photos * getQty(p.id), 0); const totalPhotos = totalSinglePhotos + totalDualPhotos; const hasSelection = originalTotal > 0; const singlePackages = packages.filter((p) => p.type === "single"); const dualPackages = packages.filter((p) => p.type === "dual"); + const editPackages = packages.filter((p) => p.type === "edit"); return (
未选择
) : ( <> - {selectedSingle.map((pkg) => ( -未选择
) : ( <> - {selectedDual.map((pkg) => ( -未选择
+ ) : ( + <> +