34614-vm/assets/js/main.js
Flatlogic Bot 886646d934 v1
2025-10-03 06:23:03 +00:00

54 lines
1.9 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
const orderForm = document.getElementById('orderForm');
if (!orderForm) return;
const priceSummary = document.getElementById('price-summary');
const fileInput = document.getElementById('document');
const specificReqBtn = document.getElementById('specificReqBtn');
const basePrices = {
printType: { 'one-sided': 0.10, 'both-sided': 0.18 },
color: { 'bw': 0.05, 'color': 0.25 },
paperSize: { 'a4': 0.02, 'jumbo': 0.05 },
pagesPerSheet: { '1': 0, '2': 0.01, '4': 0.02 }
};
function calculatePrice() {
const formData = new FormData(orderForm);
const printType = formData.get('printType');
const color = formData.get('color');
const paperSize = formData.get('paperSize');
const pagesPerSheet = formData.get('pagesPerSheet');
const quantity = parseInt(formData.get('quantity') || '1', 10);
let cost = 0;
cost += basePrices.printType[printType] || 0;
cost += basePrices.color[color] || 0;
cost += basePrices.paperSize[paperSize] || 0;
cost += basePrices.pagesPerSheet[pagesPerSheet] || 0;
const total = cost * quantity;
priceSummary.textContent = `$${total.toFixed(2)}`;
}
orderForm.addEventListener('change', calculatePrice);
orderForm.addEventListener('input', calculatePrice);
orderForm.addEventListener('submit', function(e) {
if (!fileInput.files || fileInput.files.length === 0) {
e.preventDefault();
alert('Please upload a document before submitting.');
fileInput.focus();
}
});
if (specificReqBtn) {
specificReqBtn.addEventListener('click', function() {
alert('Please visit the shop for more specific requirements.');
});
}
calculatePrice();
});