feat(mall): show a reconciled price breakdown for configured services
Option labels and right-aligned amounts now add up through the monthly subtotal, term, and discount to the total on the product page and direct checkout. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cc9a522589
commit
d121ac7e73
6 files changed
+82
-23
No files matched your search
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import { t as pick } from "@vmall/shared";
|
||||
import type { OptionGroup, PricingQuote, QuoteLine } from "@vmall/shared";
|
||||
|
||||
const props = defineProps<{
|
||||
quote: PricingQuote;
|
||||
groups?: OptionGroup[];
|
||||
}>();
|
||||
|
||||
const { locale, t } = useI18n();
|
||||
|
||||
const items = computed(() => props.quote.lines.filter((line) => line.kind === "item"));
|
||||
const discounts = computed(() => props.quote.lines.filter((line) => line.kind === "discount"));
|
||||
const monthlyMinor = computed(() => items.value.reduce((sum, line) => sum + line.amount_minor, 0));
|
||||
const months = computed(() => props.quote.period?.months ?? null);
|
||||
|
||||
function label(line: QuoteLine): string {
|
||||
if (line.kind === "discount") return t("product.termDiscount");
|
||||
const group = props.groups?.find((item) => item.key === line.group_key);
|
||||
return group ? pick(group.label, locale.value) : line.group_key;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="border-border bg-bg/60 rounded-md border px-4 py-3 text-sm">
|
||||
<h3 class="text-muted mt-0 mb-2 text-xs font-medium">{{ t("product.breakdown") }}</h3>
|
||||
<dl class="m-0 grid grid-cols-[1fr_auto] gap-x-6 gap-y-1.5">
|
||||
<template v-for="(line, index) in items" :key="`${line.group_key}-${index}`">
|
||||
<dt class="text-muted min-w-0">
|
||||
{{ label(line) }}
|
||||
<span v-if="line.quantity > 1" class="ml-1 text-xs">×{{ line.quantity }}</span>
|
||||
</dt>
|
||||
<dd class="text-text m-0 text-right tabular-nums">
|
||||
<PriceText :amount-minor="line.amount_minor" :currency="quote.rule_currency" />
|
||||
</dd>
|
||||
</template>
|
||||
|
||||
<template v-if="months">
|
||||
<div class="border-border col-span-2 my-1 border-t" />
|
||||
<dt class="text-muted">{{ t("product.monthlySubtotal") }}</dt>
|
||||
<dd class="text-text m-0 text-right tabular-nums">
|
||||
<PriceText :amount-minor="monthlyMinor" :currency="quote.rule_currency" />
|
||||
</dd>
|
||||
<dt class="text-muted">{{ t("product.termTimes", { n: months }) }}</dt>
|
||||
<dd class="text-text m-0 text-right tabular-nums">
|
||||
<PriceText :amount-minor="monthlyMinor * months" :currency="quote.rule_currency" />
|
||||
</dd>
|
||||
</template>
|
||||
<template v-for="(line, index) in discounts" :key="`discount-${index}`">
|
||||
<dt class="text-muted">{{ label(line) }}</dt>
|
||||
<dd class="text-success m-0 text-right tabular-nums">
|
||||
<PriceText :amount-minor="line.amount_minor" :currency="quote.rule_currency" />
|
||||
</dd>
|
||||
</template>
|
||||
|
||||
<div class="border-border col-span-2 my-1 border-t" />
|
||||
<dt class="text-text font-semibold">{{ t("product.quoteTotal") }}</dt>
|
||||
<dd class="text-primary m-0 text-right text-base font-semibold tabular-nums">
|
||||
<PriceText :amount-minor="quote.total_minor" :currency="quote.currency" />
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</template>
|
||||
@@ -30,8 +30,6 @@ export default {
|
||||
serviceContact: "Delivery contact",
|
||||
priceChanged: "The price changed. Review the new total and confirm.",
|
||||
confirmPrice: "Confirm new price",
|
||||
monthly: "Monthly equivalent",
|
||||
termDiscount: "Term discount",
|
||||
promotion: "Promotion",
|
||||
noPromotion: "No promotion",
|
||||
thresholdDiscount: "Threshold reduction",
|
||||
@@ -86,8 +84,6 @@ export default {
|
||||
serviceContact: "交付联系方式",
|
||||
priceChanged: "价格已变化,请核对新的总价后再确认。",
|
||||
confirmPrice: "确认新价格",
|
||||
monthly: "月均",
|
||||
termDiscount: "账期折扣",
|
||||
promotion: "优惠",
|
||||
noPromotion: "不使用优惠",
|
||||
thresholdDiscount: "满减优惠",
|
||||
|
||||
@@ -57,6 +57,10 @@ export default {
|
||||
termDiscount: "Term discount",
|
||||
componentSpecs: "{vcpu} vCPU · {mem} GB · {mbps} Mbps",
|
||||
quoteFailed: "Unable to price this configuration.",
|
||||
breakdown: "Price breakdown",
|
||||
quoteTotal: "Total",
|
||||
monthlySubtotal: "Monthly subtotal",
|
||||
termTimes: "× {n} months",
|
||||
},
|
||||
},
|
||||
zh: {
|
||||
@@ -116,6 +120,10 @@ export default {
|
||||
termDiscount: "账期折扣",
|
||||
componentSpecs: "{vcpu} 核 · {mem} GB · {mbps} Mbps",
|
||||
quoteFailed: "无法计算该配置的价格。",
|
||||
breakdown: "价格明细",
|
||||
quoteTotal: "合计",
|
||||
monthlySubtotal: "月费小计",
|
||||
termTimes: "× {n} 个月",
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
Coupon,
|
||||
GroupBuyIntent,
|
||||
LocalizedText,
|
||||
OptionGroup,
|
||||
PricingQuote,
|
||||
ShippingQuote,
|
||||
ShopProfile,
|
||||
@@ -43,6 +44,7 @@ const renewSubscriptionId = computed(() =>
|
||||
const directConfig = ref<Configuration | null>(null);
|
||||
const expectedTotal = ref<number | null>(null);
|
||||
const serviceQuote = ref<PricingQuote | null>(null);
|
||||
const directGroups = ref<OptionGroup[]>([]);
|
||||
const priceChanged = ref(false);
|
||||
|
||||
function readDirectConfig(): void {
|
||||
@@ -272,6 +274,7 @@ async function loadCart(): Promise<void> {
|
||||
$api.getProduct(directProductId.value),
|
||||
$api.listShops().catch(() => [] as ShopProfile[]),
|
||||
]);
|
||||
directGroups.value = product.option_groups ?? [];
|
||||
readDirectConfig();
|
||||
const sku = product.skus?.find((item) => item.id === directSkuId.value);
|
||||
if (directConfig.value) {
|
||||
@@ -452,19 +455,12 @@ onBeforeUnmount(() => {
|
||||
<VCard class="mb-4 p-5">
|
||||
<h2 v-if="!directMode" class="mt-0 mb-4 text-base font-semibold">{{ t("checkout.address") }}</h2>
|
||||
<p v-if="directMode" class="text-muted text-sm">{{ t("checkout.serviceNoAddress") }}</p>
|
||||
<ul v-if="serviceQuote" class="text-muted mt-3 space-y-1 text-sm">
|
||||
<li v-for="(line, index) in serviceQuote.lines" :key="`${line.group_key}-${index}`">
|
||||
{{ line.kind === "discount" ? t("checkout.termDiscount") : line.group_key }}
|
||||
<PriceText :amount-minor="line.amount_minor" :currency="serviceQuote.rule_currency" />
|
||||
</li>
|
||||
<li v-if="serviceQuote.period">
|
||||
{{ t("checkout.monthly") }}
|
||||
<PriceText
|
||||
:amount-minor="serviceQuote.period.monthly_minor"
|
||||
:currency="serviceQuote.currency"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
<QuoteBreakdown
|
||||
v-if="serviceQuote"
|
||||
class="mt-3 max-w-md"
|
||||
:quote="serviceQuote"
|
||||
:groups="directGroups"
|
||||
/>
|
||||
<div v-if="!directMode && addresses.length > 0" class="grid gap-2">
|
||||
<label
|
||||
v-for="address in addresses"
|
||||
|
||||
@@ -604,12 +604,7 @@ const detailImages = computed(() => product.value?.images ?? []);
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="quoteError" class="text-danger text-sm">{{ quoteError }}</p>
|
||||
<ul v-if="serviceQuote" class="text-muted space-y-1 text-xs">
|
||||
<li v-for="(line, index) in serviceQuote.lines" :key="`${line.group_key}-${index}`">
|
||||
{{ line.kind === "discount" ? t("product.termDiscount") : line.group_key }}
|
||||
<PriceText :amount-minor="line.amount_minor" :currency="serviceQuote.rule_currency" />
|
||||
</li>
|
||||
</ul>
|
||||
<QuoteBreakdown v-if="serviceQuote" :quote="serviceQuote" :groups="product?.option_groups" />
|
||||
</div>
|
||||
<div v-for="group in configurable ? [] : attributeGroups" :key="group.key" class="mb-3 flex gap-3">
|
||||
<span class="text-muted w-16 shrink-0 pt-1 text-sm">{{ group.key }}</span>
|
||||
|
||||
@@ -26,6 +26,7 @@ Guidelines: `docs/frontend-guidelines.md`.
|
||||
| `config/chatty.ts` | Chatty plan definitions (catalog slugs, SKU attribute names, provisional examples), capabilities, FAQ, enquiry options |
|
||||
| `composables/useChattyPlans.ts` | resolves each plan's option SKUs from the `chatty` shop, plus option picking helpers; plans with no options stay provisional (not purchasable) |
|
||||
| `locales/chatty.ts` | `chatty.*` en/zh strings |
|
||||
| `components/QuoteBreakdown.vue` | configured-price breakdown (option-group labels, right-aligned monthly amounts, monthly subtotal × term, discount, total) used on the product page and direct checkout |
|
||||
| `composables/` | session/cart stores, `usePrice` (currency conversion display), `useUnreadMessages` (header badge count) |
|
||||
|
||||
Remember: mall is the only app with a mock adapter; every new live domain
|
||||
|
||||
Reference in new issue
Block a user