godsplane
@godsplane

Калькулятор работает не стабильно. В чем причина?

Всем привет.
Сайт:
https://xn--24-dlcaz5byf.xn--p1ai/
Внизу "Рассчитать стомиость товара"
Если прокручивать ползунок, то цена не меняется, но если переключить между регионами, то все начинает работать.
Что можно сделать с этим?
Сам код калькулятора:
spoiler

jQuery(function () {

	new WOW().init();



	jQuery('.navbar-tog').click(function () {
		jQuery(this).toggleClass('navbar-on');
		jQuery('.nav-wrapper').toggleClass('active');
	});

	var elem = document.querySelector('.js-range');
	var init = new Powerange(elem, { min: 0, max: 100, start: 1, step: 1, hideRange: true });

	var elemTwo = document.querySelector('.js-range-two');
	var init = new Powerange(elemTwo, { min: 5, max: 20, start: 10, step: 5, hideRange: true, vertical: true });

	jQuery('.footer__callback a').click(function () {
		jQuery('.modal-fade').fadeIn(300);
		return false;
	})

	jQuery('.modal__close').click(function () {
		jQuery('.modal-fade').fadeOut(300);
	});


	// Калькулятор

	var type = 8;
	var region;
	var regionPrice;
	var size = 8;
	var quantity = 1;
	var price = 0;
	var outputPrice = 0;
	var totalPrice;


	function calc(region, type, size, quantity) {

	}

	// Выбор типа контейнера

	jQuery('input[name=type]').change(function () {
		type = jQuery('input[name=type]:checked').val();
		document.getElementById('calc-value-one').innerHTML = type;

		region = elemTwo.value + ' км';
		document.getElementById('calc-value-two').innerHTML = region;
		if (document.getElementById('type-one').checked) {
			if (region == '5 км') { price = 6000 };
			if (region == '10 км') { price = 6500 };
			if (region == '15 км') { price = 7000 };
			if (region == '20 км') { price = 7500 };
		};
		if (document.getElementById('type-two').checked) {
			if (region == '5 км') { price = 17000 };
			if (region == '10 км') { price = 18000 };
			if (region == '15 км') { price = 19000 };
			if (region == '20 км') { price = 20000 };
		};
		if (document.getElementById('type-three').checked) {
			if (region == '5 км') { price = 19000 };
			if (region == '10 км') { price = 20000 };
			if (region == '15 км') { price = 21000 };
			if (region == '20 км') { price = 22000 };
		};

		outputPrice = (price + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');

		document.getElementById('calc-value-four').innerHTML = outputPrice;
		totalPrice = quantity * price;
		totalPrice = (totalPrice + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
		document.getElementById('calc-value-five').innerHTML = totalPrice;
	});

	// Переключение между Москвой и Московской областью

	jQuery('input[name=area]').change(function () {
		if (document.getElementById('area-one').checked) {
			jQuery('.map__distance').removeClass('active');
			jQuery('.calc__map_block').addClass('active');
			jQuery('.calc__map_choice-switch').removeClass('two');
		}
		if (document.getElementById('area-two').checked) {
			jQuery('.map__distance').addClass('active');
			jQuery('.calc__map_block').removeClass('active');
			jQuery('.calc__map_choice-switch').addClass('two');
		}
	});

	//

	elemTwo.onchange = function () {
		region = elemTwo.value + ' км';
		document.getElementById('calc-value-two').innerHTML = region;
		if (document.getElementById('type-one').checked) {
			if (region == '5 км') { price = 6000 };
			if (region == '10 км') { price = 6500 };
			if (region == '15 км') { price = 7000 };
			if (region == '20 км') { price = 7500 };
		};
		if (document.getElementById('type-two').checked) {
			if (region == '5 км') { price = 17000 };
			if (region == '10 км') { price = 18000 };
			if (region == '15 км') { price = 19000 };
			if (region == '20 км') { price = 20000 };
		};
		if (document.getElementById('type-three').checked) {
			if (region == '5 км') { price = 19000 };
			if (region == '10 км') { price = 20000 };
			if (region == '15 км') { price = 21000 };
			if (region == '20 км') { price = 22000 };
		};

		outputPrice = (price + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');

		document.getElementById('calc-value-four').innerHTML = outputPrice;
		totalPrice = quantity * price;
		totalPrice = (totalPrice + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
		document.getElementById('calc-value-five').innerHTML = totalPrice;
	};

	elem.onchange = function () {
		document.getElementById('calc-value-three').innerHTML = elem.value;
		quantity = elem.value;
		totalPrice = quantity * price;
		if (quantity > 10 & document.getElementById('type-two').checked) { totalPrice = totalPrice * 0.9; }
		else if (quantity > 10 & document.getElementById('type-three').checked) { totalPrice = totalPrice * 0.9; };
		totalPrice = (totalPrice + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
		document.getElementById('calc-value-five').innerHTML = totalPrice;
	};

	jQuery('.calc__map svg g').click(function () {
		jQuery('.calc__map svg g').removeClass('map-region_active');
		jQuery(this).addClass('map-region_active');
		region = jQuery(this).attr('data-name');
		document.getElementById('calc-value-two').innerHTML = region;
		if (document.getElementById('type-one').checked) {
			if (region == 'ВАО' || region == 'ЮВАО') { price = 5990 };
			if (region == 'СВАО' || region == 'САО' || region == 'ЮЗАО' || region == 'ЮАО' || region == 'ЦАО') {price = 6500};
			if (region == 'СЗАО' || region == 'ЗАО') { price = 6500 };
		};
		if (document.getElementById('type-two').checked) {
			if (region == 'ВАО' || region == 'СВАО' || region == 'ЮВАО') { price = 15990 };
			if (region == 'ЮАО' || region == 'САО') { price = 16990
			};
			if (region == 'СЗАО') { price = 16990
			};
			if (region == 'ЗАО' || region == 'ЮЗАО' || region == 'ЦАО') { price = 16990
			};
		};
		if (document.getElementById('type-three').checked) {
			if (region == 'ВАО' || region == 'СВАО' || region == 'ЮВАО') { price = 18990
			};
			if (region == 'ЮАО' || region == 'САО') { price = 19990
			};
			if (region == 'СЗАО') { price = 19990
			};
			if (region == 'ЗАО' || region == 'ЮЗАО' || region == 'ЦАО') { price = 19990
			};
		};

		outputPrice = (price + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');

		document.getElementById('calc-value-four').innerHTML = outputPrice;
		totalPrice = quantity * price;
		if (quantity > 10 & document.getElementById('type-two').checked) { totalPrice = totalPrice * 0.9; }
		else if (quantity > 10 & document.getElementById('type-three').checked) { totalPrice = totalPrice * 0.9; };
		totalPrice = (totalPrice + '').replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
		document.getElementById('calc-value-five').innerHTML = totalPrice;
	});
});

  • Вопрос задан
  • 180 просмотров
Пригласить эксперта
Ответы на вопрос 1
wagoodoogoo
@wagoodoogoo
prestashop, webix, phalcon, vue, slim, craft cms
Цена считается от региона, а изначально регион не задан?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы