Feat: 增加简修套餐,5 元一张
This commit is contained in:
+8
-2
@@ -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;
|
||||
|
||||
+68
-9
@@ -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 (
|
||||
<div className="app">
|
||||
@@ -126,6 +136,20 @@ function App() {
|
||||
))}
|
||||
</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>
|
||||
|
||||
{/* Selected Items Summary */}
|
||||
@@ -149,6 +173,7 @@ function App() {
|
||||
<p className="column-empty">未选择</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="selected-list">
|
||||
{selectedSingle.map((pkg) => (
|
||||
<div key={pkg.id} className="selected-item">
|
||||
<span className="item-name">
|
||||
@@ -157,6 +182,7 @@ function App() {
|
||||
<span className="item-price">¥{pkg.price * getQty(pkg.id)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="column-subtotal">
|
||||
<span>小计 ({totalSinglePhotos} 张)</span>
|
||||
<span>¥{singleSubtotal}</span>
|
||||
@@ -173,6 +199,7 @@ function App() {
|
||||
<p className="column-empty">未选择</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="selected-list">
|
||||
{selectedDual.map((pkg) => (
|
||||
<div key={pkg.id} className="selected-item">
|
||||
<span className="item-name">
|
||||
@@ -181,6 +208,7 @@ function App() {
|
||||
<span className="item-price">¥{pkg.price * getQty(pkg.id)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="column-subtotal">
|
||||
<span>小计 ({totalDualPhotos} 张)</span>
|
||||
<span>¥{dualSubtotal}</span>
|
||||
@@ -188,6 +216,31 @@ function App() {
|
||||
</>
|
||||
)}
|
||||
</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>
|
||||
)}
|
||||
</section>
|
||||
@@ -287,7 +340,13 @@ function PackageCard({
|
||||
qty: number;
|
||||
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 (
|
||||
<div className={`package-card ${!pkg.available ? "disabled" : ""} ${qty > 0 ? "active" : ""}`}>
|
||||
|
||||
Reference in New Issue
Block a user