feat: 套装方案对比与导出功能 #32

Merged
hera merged 37 commits from feat/kit-comparison-export into main 2026-04-14 13:32:34 +00:00
2 changed files with 25 additions and 4 deletions
Showing only changes of commit c090e5f3d6 - Show all commits

View File

@@ -35,12 +35,14 @@ export function useKitCost() {
}
if (totalBottlePrice === 0) return {}
// Proportional allocation
// Proportional allocation — kit accessories treated as freebies,
// so oil cost = min(kit price, sum of bottle prices)
const effectivePrice = Math.min(kit.price, totalBottlePrice)
const perDrop = {}
for (const name of resolved) {
const meta = oils.oilsMeta[name]
const bp = oilBottlePrices[name]
const kitCostForOil = (bp / totalBottlePrice) * kit.price
const kitCostForOil = (bp / totalBottlePrice) * effectivePrice
const drops = meta ? meta.dropCount : 1
perDrop[name] = drops > 0 ? kitCostForOil / drops : 0
}
@@ -124,6 +126,7 @@ export function useKitCost() {
id,
name: recipe.name,
tags: recipe.tags,
volume: recipe.volume,
ingredients: recipe.ingredients,
originalCost: recipe.originalCost,
costs,

View File

@@ -39,6 +39,7 @@
<thead>
<tr>
<th class="th-name">配方名</th>
<th class="th-times">可做次数</th>
<th class="th-cost">套装成本</th>
<th class="th-cost">原价成本</th>
<th class="th-price">售价</th>
@@ -47,7 +48,8 @@
</thead>
<tbody>
<tr v-for="r in activeKitData.recipes" :key="r._id">
<td class="td-name">{{ r.name }}</td>
<td class="td-name">{{ r.name }} <span class="td-volume">{{ r.volume || '单次' }}</span></td>
<td class="td-times">{{ calcMaxTimes(r) }}</td>
<td class="td-cost">{{ fmtPrice(r.kitCost) }}</td>
<td class="td-cost original">{{ fmtPrice(r.originalCost) }}</td>
<td class="td-price">
@@ -83,7 +85,7 @@
</thead>
<tbody>
<tr v-for="row in crossComparison" :key="row.id">
<td class="td-name">{{ row.name }}</td>
<td class="td-name">{{ row.name }} <span class="td-volume">{{ row.volume || '单次' }}</span></td>
<td v-for="ka in kitAnalysis" :key="ka.id" :class="row.costs[ka.id] != null ? 'td-kit-available' : 'td-kit-na'">
<template v-if="row.costs[ka.id] != null">{{ fmtPrice(row.costs[ka.id]) }}</template>
<template v-else><span class="na"></span></template>
@@ -142,6 +144,20 @@ function saveSellingPrices() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(sellingPrices.value))
}
// Calculate how many times a recipe can be made with the kit (limited by the oil that runs out first)
function calcMaxTimes(recipe) {
const ings = (recipe.ingredients || []).filter(i => i.oil && i.oil !== '椰子油' && i.drops > 0)
if (!ings.length) return '—'
let minTimes = Infinity
for (const ing of ings) {
const meta = oils.oilsMeta[ing.oil]
if (!meta || !meta.dropCount) return '—'
const times = Math.floor(meta.dropCount / ing.drops)
if (times < minTimes) minTimes = times
}
return minTimes === Infinity ? '—' : minTimes + '次'
}
function getSellingPrice(recipeId) {
return sellingPrices.value[recipeId] ?? 0
}
@@ -394,6 +410,8 @@ async function exportExcel(mode) {
.td-cost.original { color: #999; font-weight: 400; }
.td-profit { font-weight: 600; color: #4a9d7e; }
.td-profit.negative { color: #ef5350; }
.td-volume { font-size: 10px; color: #b0aab5; margin-left: 4px; }
.td-times { color: #6b6375; font-size: 12px; }
.td-kit-available { font-weight: 500; color: #4a9d7e; background: #f0faf5; }
.td-kit-na { background: #fafafa; }
.na { color: #ddd; }