26 lines
1.1 KiB
JavaScript
26 lines
1.1 KiB
JavaScript
// US02-03: Coaching-Rabatt direkt auf der Paketdetailseite, ohne Dialog.
|
|
"use strict";
|
|
(() => {
|
|
const panel = document.querySelector("[data-base-price]");
|
|
if (!panel) return;
|
|
const select = panel.querySelector("select");
|
|
const price = panel.querySelector("[data-price-output]");
|
|
const summary = panel.querySelector("[data-discount-output]");
|
|
const baseCents = Math.round(Number(panel.dataset.basePrice) * 100);
|
|
const currency = new Intl.NumberFormat("de-DE", {
|
|
style: "currency",
|
|
currency: "EUR",
|
|
});
|
|
function updatePrice() {
|
|
const rate = Number(select.value);
|
|
const saving = Math.round((baseCents * rate) / 100);
|
|
const total = baseCents - saving;
|
|
price.textContent = currency.format(total / 100);
|
|
summary.textContent = rate
|
|
? `${rate} % Coaching-Rabatt: Du sparst ${currency.format(saving / 100)}. Beispiel-Gesamtpreis: ${currency.format(total / 100)}.`
|
|
: `Ohne Coaching-Rabatt: ${currency.format(baseCents / 100)} für das gesamte Paket.`;
|
|
}
|
|
select.addEventListener("change", updatePrice);
|
|
updatePrice();
|
|
})();
|