Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

122 wiersze
3.6KB

  1. const form = document.getElementById("orderForm");
  2. const quantityInput = document.getElementById("quantity");
  3. const turnaround = document.getElementById("turnaround");
  4. const envelopeSupply = document.getElementById("envelopeSupply");
  5. const serviceInputs = [...document.querySelectorAll('input[name="services"]')];
  6. const summaryQuantity = document.getElementById("summaryQuantity");
  7. const serviceSummary = document.getElementById("serviceSummary");
  8. const setupFeeElement = document.getElementById("setupFee");
  9. const rushLine = document.getElementById("rushLine");
  10. const rushFeeElement = document.getElementById("rushFee");
  11. const estimatedTotal = document.getElementById("estimatedTotal");
  12. const dialog = document.getElementById("confirmationDialog");
  13. const currency = new Intl.NumberFormat("en-US", {
  14. style: "currency",
  15. currency: "USD"
  16. });
  17. const number = new Intl.NumberFormat("en-US");
  18. function calculateOrder() {
  19. const quantity = Math.max(Number(quantityInput.value) || 0, 0);
  20. const setupFee = quantity > 0 ? 45 : 0;
  21. let subtotal = setupFee;
  22. const lines = [];
  23. serviceInputs.forEach((input) => {
  24. if (!input.checked) return;
  25. const rate = Number(input.dataset.rate || 0);
  26. const flat = Number(input.dataset.flat || 0);
  27. const amount = flat || quantity * rate;
  28. subtotal += amount;
  29. lines.push({
  30. label: input.dataset.label,
  31. amount
  32. });
  33. });
  34. if (envelopeSupply.value === "vendor") {
  35. const envelopeCost = quantity * 0.18;
  36. subtotal += envelopeCost;
  37. lines.push({
  38. label: "Purple envelope stock",
  39. amount: envelopeCost
  40. });
  41. }
  42. const rushFee = turnaround.value === "rush" ? subtotal * 0.25 : 0;
  43. const total = subtotal + rushFee;
  44. summaryQuantity.textContent = number.format(quantity);
  45. setupFeeElement.textContent = currency.format(setupFee);
  46. rushFeeElement.textContent = currency.format(rushFee);
  47. estimatedTotal.textContent = currency.format(total);
  48. rushLine.hidden = turnaround.value !== "rush";
  49. serviceSummary.innerHTML = lines
  50. .map(
  51. (line) => `
  52. <div class="summary-line">
  53. <span>${line.label}</span>
  54. <strong>${currency.format(line.amount)}</strong>
  55. </div>
  56. `
  57. )
  58. .join("");
  59. }
  60. function showSelectedFile(input) {
  61. const uploadBox = input.closest(".upload-box");
  62. const strong = uploadBox.querySelector("strong");
  63. const small = uploadBox.querySelector("small");
  64. if (input.files.length) {
  65. strong.textContent = input.files[0].name;
  66. small.textContent = "File selected";
  67. }
  68. }
  69. quantityInput.addEventListener("input", calculateOrder);
  70. turnaround.addEventListener("change", calculateOrder);
  71. envelopeSupply.addEventListener("change", calculateOrder);
  72. serviceInputs.forEach((input) => input.addEventListener("change", calculateOrder));
  73. document.querySelectorAll('input[type="file"]').forEach((input) => {
  74. input.addEventListener("change", () => showSelectedFile(input));
  75. });
  76. form.addEventListener("submit", (event) => {
  77. event.preventDefault();
  78. if (!form.checkValidity()) {
  79. form.reportValidity();
  80. return;
  81. }
  82. dialog.showModal();
  83. });
  84. dialog.querySelectorAll(".dialog-close, .dialog-button").forEach((button) => {
  85. button.addEventListener("click", () => dialog.close());
  86. });
  87. dialog.addEventListener("click", (event) => {
  88. const bounds = dialog.getBoundingClientRect();
  89. const clickedOutside =
  90. event.clientX < bounds.left ||
  91. event.clientX > bounds.right ||
  92. event.clientY < bounds.top ||
  93. event.clientY > bounds.bottom;
  94. if (clickedOutside) dialog.close();
  95. });
  96. document.getElementById("year").textContent = new Date().getFullYear();
  97. calculateOrder();

Powered by TurnKey Linux.