Feat: 增加简修套餐,5 元一张

This commit is contained in:
2026-11-13 00:23:23 +08:00
parent 5d93f6fed3
commit 81a58dfa52
2 changed files with 92 additions and 27 deletions
+8 -2
View File
@@ -257,11 +257,13 @@
.selected-grid { .selected-grid {
display: grid; display: grid;
grid-template-columns: 1fr auto 1fr; grid-template-columns: 1fr auto 1fr auto 1fr;
gap: 0; gap: 0;
} }
.selected-column { .selected-column {
display: flex;
flex-direction: column;
padding: 0 0.5rem; padding: 0 0.5rem;
} }
@@ -275,7 +277,7 @@
font-size: 0.88rem; font-size: 0.88rem;
font-weight: 600; font-weight: 600;
color: #555; color: #555;
margin: 0 0 0.6rem; margin: 0 0 0.3rem;
padding-bottom: 0.4rem; padding-bottom: 0.4rem;
border-bottom: 2px solid #f0f0f0; border-bottom: 2px solid #f0f0f0;
} }
@@ -288,6 +290,10 @@
margin: 0; margin: 0;
} }
.selected-list {
flex: 1;
}
.selected-item { .selected-item {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
+84 -25
View File
@@ -3,7 +3,7 @@ import "./App.css";
interface Package { interface Package {
id: string; id: string;
type: "single" | "dual"; type: "single" | "dual" | "edit";
photos: number; photos: number;
price: number; price: number;
postProcessing: string; postProcessing: string;
@@ -13,14 +13,15 @@ interface Package {
} }
const packages: Package[] = [ const packages: Package[] = [
{ id: "s1", type: "single", photos: 1, price: 10, postProcessing: "调色简修", note: "一张不接,附加项", available: true, isAddon: true }, { 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: "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: "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: "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: "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: "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: "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: "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; const COMBO_DISCOUNT = 5;
@@ -64,9 +65,16 @@ function App() {
[quantities] [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 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 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 hasCombo = selectedSingle.length > 0 && selectedDual.length > 0;
const finalPrice = hasCombo ? originalTotal - COMBO_DISCOUNT : originalTotal; 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 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 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 totalPhotos = totalSinglePhotos + totalDualPhotos;
const hasSelection = originalTotal > 0; const hasSelection = originalTotal > 0;
const singlePackages = packages.filter((p) => p.type === "single"); const singlePackages = packages.filter((p) => p.type === "single");
const dualPackages = packages.filter((p) => p.type === "dual"); const dualPackages = packages.filter((p) => p.type === "dual");
const editPackages = packages.filter((p) => p.type === "edit");
return ( return (
<div className="app"> <div className="app">
@@ -126,6 +136,20 @@ function App() {
))} ))}
</div> </div>
</div> </div>
<div className="package-group">
<h3 className="group-label">✨ 简修</h3>
<div className="package-grid">
{editPackages.map((pkg) => (
<PackageCard
key={pkg.id}
pkg={pkg}
qty={getQty(pkg.id)}
onQtyChange={(val) => setQty(pkg.id, val)}
/>
))}
</div>
</div>
</section> </section>
{/* Selected Items Summary */} {/* Selected Items Summary */}
@@ -149,14 +173,16 @@ function App() {
<p className="column-empty">未选择</p> <p className="column-empty">未选择</p>
) : ( ) : (
<> <>
{selectedSingle.map((pkg) => ( <div className="selected-list">
<div key={pkg.id} className="selected-item"> {selectedSingle.map((pkg) => (
<span className="item-name"> <div key={pkg.id} className="selected-item">
单人 {pkg.photos} 张 × {getQty(pkg.id)} <span className="item-name">
</span> 单人 {pkg.photos} 张 × {getQty(pkg.id)}
<span className="item-price">¥{pkg.price * getQty(pkg.id)}</span> </span>
</div> <span className="item-price">¥{pkg.price * getQty(pkg.id)}</span>
))} </div>
))}
</div>
<div className="column-subtotal"> <div className="column-subtotal">
<span>小计 ({totalSinglePhotos} 张)</span> <span>小计 ({totalSinglePhotos} 张)</span>
<span>¥{singleSubtotal}</span> <span>¥{singleSubtotal}</span>
@@ -173,14 +199,16 @@ function App() {
<p className="column-empty">未选择</p> <p className="column-empty">未选择</p>
) : ( ) : (
<> <>
{selectedDual.map((pkg) => ( <div className="selected-list">
<div key={pkg.id} className="selected-item"> {selectedDual.map((pkg) => (
<span className="item-name"> <div key={pkg.id} className="selected-item">
双人 {pkg.photos} 张 × {getQty(pkg.id)} <span className="item-name">
</span> 双人 {pkg.photos} 张 × {getQty(pkg.id)}
<span className="item-price">¥{pkg.price * getQty(pkg.id)}</span> </span>
</div> <span className="item-price">¥{pkg.price * getQty(pkg.id)}</span>
))} </div>
))}
</div>
<div className="column-subtotal"> <div className="column-subtotal">
<span>小计 ({totalDualPhotos} 张)</span> <span>小计 ({totalDualPhotos} 张)</span>
<span>¥{dualSubtotal}</span> <span>¥{dualSubtotal}</span>
@@ -188,6 +216,31 @@ function App() {
</> </>
)} )}
</div> </div>
<div className="selected-divider" />
<div className="selected-column">
<h3 className="column-title">✨ 简修</h3>
{selectedEdit.length === 0 ? (
<p className="column-empty">未选择</p>
) : (
<>
<div className="selected-list">
{selectedEdit.map((pkg) => (
<div key={pkg.id} className="selected-item">
<span className="item-name">
简修 {pkg.photos} 张 × {getQty(pkg.id)}
</span>
<span className="item-price">¥{pkg.price * getQty(pkg.id)}</span>
</div>
))}
</div>
<div className="column-subtotal"> <span>小计 ({totalEditPhotos} 张)</span>
<span>¥{editSubtotal}</span>
</div>
</>
)}
</div>
</div> </div>
)} )}
</section> </section>
@@ -287,7 +340,13 @@ function PackageCard({
qty: number; qty: number;
onQtyChange: (val: number) => void; onQtyChange: (val: number) => void;
}) { }) {
const typeLabel = pkg.type === "single" ? "单人" : "双人"; const typeLabel = (() => {
if (pkg.type === "single") return "单人";
if (pkg.type === "dual") return "双人";
if (pkg.type === "edit") return "简修";
return "";
})();
return ( return (
<div className={`package-card ${!pkg.available ? "disabled" : ""} ${qty > 0 ? "active" : ""}`}> <div className={`package-card ${!pkg.available ? "disabled" : ""} ${qty > 0 ? "active" : ""}`}>