const basePrice = JSON.parse('{"1":{"square":"16-27","btu":"7000-9000 \/ 2.1-2.6","price":"7000","price_our_item":"6500","price_remont":"2500","plus_cart":"1000-3000 \u0433\u0440\u043d.","plus_facade":"300-500 \u0433\u0440\u043d."},"2":{"square":"28-37","btu":"12000 \/ 3.2-3.6","price":"7200","price_our_item":"6500","price_remont":"3200","plus_cart":"100-1500 \u0433\u0440\u043d.","plus_facade":"300-500 \u0433\u0440\u043d."},"3":{"square":"38-55","btu":"18000 \/ 4.2-5.5","price":"7500","price_our_item":"6500","price_remont":"4300","plus_cart":"2000-4500 \u0433\u0440\u043d.","plus_facade":"300-500 \u0433\u0440\u043d."}}'); const installOption = JSON.parse('{"2-standard":{"1":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"1","img":"indoor-unit-to-the-right-of-the-window.png"},"10":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"10","img":"indoor-unit-to-the-left-of-the-window.png"},"11":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"11","img":"installation-through-the-balcony.png"}},"1-standard":{"2":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"2","img":"indoor-unit-to-the-right-of-the-window.png"},"16":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"16","img":"indoor-unit-to-the-left-of-the-window.png"},"5":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"5","img":"installation-through-the-balcony.png"}},"1-beforeRepair":{"7":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"7","img":"piping-laid-to-the-right-of-the-window.png"},"6":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"6","img":"piping-laid-to-the-left-of-the-window.png"},"8":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"8","img":"piping-routed-through-the-balcony.png"},"9":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","value":"9","img":"piping-routed-above-the-door.png"}},"2-beforeRepair":{"13":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"13","img":"piping-laid-to-the-right-of-the-window.png"},"12":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"12","img":"piping-laid-to-the-left-of-the-window.png"},"14":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"14","img":"piping-routed-through-the-balcony.png"},"15":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","value":"15","img":"piping-routed-above-the-door.png"}},"3-standard":{"17":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"17","img":"indoor-unit-to-the-right-of-the-window.png"},"18":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"18","img":"indoor-unit-to-the-left-of-the-window.png"},"19":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"19","img":"installation-through-the-balcony.png"}},"3-beforeRepair":{"20":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"20","img":"piping-laid-to-the-right-of-the-window.png"},"21":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","value":"21","img":"piping-laid-to-the-left-of-the-window.png"},"22":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","value":"22","img":"piping-routed-through-the-balcony.png"},"23":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","value":"23","img":"piping-routed-above-the-door.png"}}}'); const variantPrice = JSON.parse('{"2-standard-1":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"500"},"1-standard-2":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"800"},"1-standard-16":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1500"},"1-standard-5":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2200"},"1-beforeRepair-7":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1200"},"1-beforeRepair-6":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1500"},"1-beforeRepair-8":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2100"},"1-beforeRepair-9":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","plus_to_price":"3350"},"2-beforeRepair-13":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1300"},"2-standard-10":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1000"},"2-beforeRepair-12":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1600"},"2-standard-11":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2000"},"2-beforeRepair-14":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2300"},"3-standard-17":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"600"},"2-beforeRepair-15":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","plus_to_price":"3500"},"3-standard-18":{"h1":"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0431\u043b\u043e\u043a \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1100"},"3-standard-19":{"h1":"\u041c\u043e\u043d\u0442\u0430\u0436 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2150"},"3-beforeRepair-20":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1400"},"3-beforeRepair-21":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u043e\u043a\u043d\u0430","plus_to_price":"1700"},"3-beforeRepair-22":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u0431\u0430\u043b\u043a\u043e\u043d","plus_to_price":"2500"},"3-beforeRepair-23":{"h1":"\u0417\u0430\u043a\u043b\u0430\u0434\u043a\u0430 \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e","plus_to_price":"3700"}}'); const step2Content = document.getElementById('step-2-content'); const step3Content = document.getElementById('step-3-content'); const step4Content = document.getElementById('step-4-content'); /** * Define a function to navigate betweens form steps. * It accepts one parameter. That is - step number. */ const navigateToFormStep = (stepNumber) => { /** * Hide all form steps. */ document.querySelectorAll(".form-step").forEach((formStepElement) => { formStepElement.classList.add("d-none"); }); /** * Mark all form steps as unfinished. */ document.querySelectorAll(".form-stepper-list").forEach((formStepHeader) => { formStepHeader.classList.add("form-stepper-unfinished"); formStepHeader.classList.remove("form-stepper-active", "form-stepper-completed"); }); /** * Show the current form step (as passed to the function). */ document.querySelector("#step-" + stepNumber).classList.remove("d-none"); /** * Select the form step circle (progress bar). */ const formStepCircle = document.querySelector('li[step="' + stepNumber + '"]'); /** * Mark the current form step as active. */ formStepCircle.classList.remove("form-stepper-unfinished", "form-stepper-completed"); formStepCircle.classList.add("form-stepper-active"); /** * Loop through each form step circles. * This loop will continue up to the current step number. * Example: If the current step is 3, * then the loop will perform operations for step 1 and 2. */ for (let index = 0; index < stepNumber; index++) { /** * Select the form step circle (progress bar). */ const formStepCircle = document.querySelector('li[step="' + index + '"]'); /** * Check if the element exist. If yes, then proceed. */ if (formStepCircle) { formStepCircle.classList.remove("form-stepper-unfinished", "form-stepper-active"); formStepCircle.classList.add("form-stepper-completed"); } } }; /** * Select all form navigation buttons, and loop through them. */ document.querySelectorAll(".btn-navigate-form-step").forEach((formNavigationBtn) => { /** * Add a click event listener to the button. */ formNavigationBtn.addEventListener("click", () => { /** * Get the value of the step. */ const stepNumber = parseInt(formNavigationBtn.getAttribute("step-number")); const skipValidation = parseInt(formNavigationBtn.getAttribute("skip-validation")); if( !skipValidation && !validateStep(stepNumber-1) ) { return false; } changeStepContent(stepNumber); /** * Call the function to navigate to the target form step. */ navigateToFormStep(stepNumber); }); }); function changeStepContent(stepNumber) { if(stepNumber == 2) { step2ChangeContent(); } else if(stepNumber == 3) { step3ChangeContent(); } } function step2ChangeContent() { const roomArea = document.querySelector('input[name="room-area"]:checked').value; // const step2Content = document.getElementById('step-2-content'); if(roomArea === "2") { //step2Content.innerHTML = 'BIG-variants'; } else { //step2Content.innerHTML = 'Other-variants'; } } function step3ChangeContent() { const roomArea = document.querySelector('input[name="room-area"]:checked').value; const installType = document.querySelector('input[name="install-type"]:checked').value; let installTypeForJS = getInstallTypeForJS(installType); //console.log(roomArea, installType, basePrice[roomArea]); const optionForSelectedType = installOption[roomArea+'-'+installTypeForJS]; let item = ''; for (const [key, o] of Object.entries(optionForSelectedType)) { //console.log(`${key}: ${o} -- ${o["h1"]}`); item += `
`; } step3Content.innerHTML = item; } function getInstallTypeForJS(installType) { let installTypeForJS = "standard"; if( installType === "price_remont" ) { installTypeForJS = "beforeRepair"; } return installTypeForJS; } const fieldNames = ['room-area', 'install-type', 'install-variant']; function validateStep(step) { //step = step - 1; const fields = fieldNames.map((fieldName) => { return document.querySelector(`#step-${step} input[name=${fieldName}]:checked`); }); //console.log(fields); const checkedFields = fields.filter((field) => field !== null); console.log(checkedFields); if (checkedFields.length === 0) { alert('Выберите один из вариантов'); return false; } return true; } let calcTotalPrice = ''; function totalPrice() { const roomArea = document.querySelector('input[name="room-area"]:checked').value; const roomAreaH1 = document.querySelector('input[name="room-area"]:checked').dataset.h1; const roomAreaImg = document.querySelector('input[name="room-area"]:checked').dataset.img; const installType = document.querySelector('input[name="install-type"]:checked').value; const installTypeH1 = document.querySelector('input[name="install-type"]:checked').parentNode.textContent.trim(); const installVariant = document.querySelector('input[name="install-variant"]:checked').value; const installVariantH1 = document.querySelector('input[name="install-variant"]:checked').parentNode.textContent.trim(); const installTypeForJS = getInstallTypeForJS(installType); const concatIndex = `${roomArea}-${installTypeForJS}-${installVariant}`; calcTotalPrice = parseInt(basePrice[roomArea][installType]) + parseInt(variantPrice[concatIndex]["plus_to_price"]); let linkToPriceTable = ` Цена установки кондиционера`; if( installType == 'price_remont' ) { linkToPriceTable = ` Цены на закладку магистрали для кондиционера`; } let youChoose = `
По выбранным парамметрам:
Площадь / мощность: ${roomAreaH1}.
Этап монтажа: ${installTypeH1}.
Вид установки: ${installVariantH1}
`; step4Content.innerHTML = youChoose + `
Цена установки: ${calcTotalPrice} грн.
При наличии утепленного фасада - плюс: ${basePrice[roomArea]["plus_facade"]}
При установке в корзину - плюс: ${basePrice[roomArea]["plus_cart"]}
${linkToPriceTable}
`; //console.log('log:'+roomAreaH1, roomAreaImg, installTypeH1, installVariantH1); //console.log('log:'+roomArea, installType, installTypeForJS, installVariant, concatIndex); //console.log(basePrice[roomArea][installType], variantPrice[concatIndex]); } const stepResult = document.getElementById('step-result-btn'); stepResult.addEventListener('click', function (event){ event.preventDefault(); if( validateStep(3) ) { totalPrice(); } }); /*const stepSubmit = document.getElementById('step-form-submit'); stepSubmit.addEventListener('click', function (event){ event.preventDefault(); if( validateStep(3) ) { alert('sent user contacts'); } });*/ const formCalc = document.querySelector('#form-calc'); const phoneField = document.querySelector('#phone-calc'); const phoneError = document.querySelector('#phone-calc-error'); const phoneSuccess = document.querySelector('#phone-calc-success'); formCalc.addEventListener('submit', async (event) => { event.preventDefault(); // Valid the phone field if (!phoneField.checkValidity()) { phoneField.classList.add('error'); phoneError.style.display = 'block'; phoneSuccess.style.display = 'none'; return; } const phone = phoneField.value; const catalogId = document.querySelector('.productCode')?.textContent.match(/\d+/)[0]; // Selected Option const roomAreaH1 = document.querySelector('input[name="room-area"]:checked').dataset.h1; const installTypeH1 = document.querySelector('input[name="install-type"]:checked').parentNode.textContent.trim(); const installVariantH1 = document.querySelector('input[name="install-variant"]:checked').parentNode.textContent.trim(); try { // Send to server const response = await fetch('/api/?do=send-phone-from-calculator', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ phone, area: roomAreaH1, type: installTypeH1, variant: installVariantH1, catalogId, totalPrice: calcTotalPrice }) }); // Get answer const result = await response.json(); if (true) {//result.success phoneField.classList.remove('error'); phoneField.value = ''; phoneError.style.display = 'none'; phoneSuccess.textContent = result.message; //'Form submitted successfully!'; phoneSuccess.style.display = 'block'; setTimeout(() => { phoneSuccess.style.display = 'none'; }, 3000); } else { phoneError.textContent = result.message; //'There was an error submitting the form.'; phoneError.style.display = 'block'; phoneSuccess.style.display = 'none'; } } catch (error) { console.error(error); phoneError.textContent = "Произошла ошибка. Вы можете связаться с нами через телефон или мессенджеры."; phoneError.style.display = 'block'; phoneSuccess.style.display = 'none'; } }); // Добавляем обработчик события для снятия подсветки с поля телефона при вводе phoneField.addEventListener('input', () => { if (phoneField.checkValidity()) { phoneField.classList.remove('error'); phoneError.style.display = 'none'; phoneSuccess.style.display = 'none'; } });