Помогите пожалуйста с калькулятором
Народ подскажите как привязать скидку к пункту ввода, есть такой код:
$('#calc_metric').on("keyup",function(){ Calc(); }); $('#calc_metric').change(function(){ Calc(); }); function Calc(){ select.Metric = $('#calc_metric').val(); var price = Math.round(select.RoomType * select.RemontType * select.HouseType * select.Metric); var priceMat = Math.round(price * (100 - select.coefficientCalcMaterials)/100); if (price != 0 && !isNaN(price)){ $('#calc-result').html(numberFormatCalc(price)); $('#calc-result-mat').html(numberFormatCalc(priceMat)); $('#calc-result-full').html(numberFormatCalc(price+priceMat)); $('.calc-result').show(); }else{ $('.calc-result').hide(); } } function numberFormatCalc(priceString){ var a = priceString.toString().split(''); var mod = a.length%3; for (i in a){ if ((i+1)%3 == mod){ a[i] = a[i] + ' '; } } return a.join(''); } Если правильно понимаю отвечает за ввод данных и подсчет с неё <input type="text" id="calc_metric"> вот не понимаю как добавить к этому пункту что если там метраж грубо от 4 до 10 м2 то скидки нет если от 10 до 100 есть условно 5% если более 100 то условно 10%, Помогите с решением чет я уже запутался. Буду очень очень признателен. |
или я ошибся вот полный код
$(document).ready(function(){ $('#calc_metric').mask('9?999999', {placeholder: ''}); $('.calc-result').hide(); var select = {'RoomType':0,'RemontType':0,'HouseType':0,'Metric':0,'coefficientCalcMaterials':0}; var jsonData = $('#calc-data').val(); jsonData = eval('(' + jsonData + ')'); select.coefficientCalcMaterials = $('#coefficientCalcMaterials').val(); $('input:radio[name=roomType]').each(function(){ if ($(this).prop('checked')){ var selected = $(this).attr('item'); select.RoomType = jsonData.RoomType[selected].coefficient; initCarousel(selected); } }); $('.calc-room-type-item').click(function(){ $('input:radio', this).attr('checked', 1); $('input:radio', this).change(); //method ?? }); $('input:radio').change(function(){ var hidden = false; switch ($(this).attr('name')){ case 'roomType': select.RoomType = $(this).val(); var id = $(this).attr('item'); if (select.RoomType == 0){ $('#b-calc-content-hidden').html(jsonData.RoomType[id].text); hidden = true; } initCarousel(id); break; case 'remontType': select.RemontType = $(this).val(); break; case 'houseType': select.HouseType = $(this).val(); break; } if (hidden){ $('.b-calc-content-hidden').show(); $('.b-calc-content').hide(); }else{ $('.b-calc-content-hidden').hide(); $('.b-calc-content').show(); } Calc(); }); $('#calc_metric').on("keyup",function(){ Calc(); }); $('#calc_metric').change(function(){ Calc(); }); function Calc(){ select.Metric = $('#calc_metric').val(); var price = Math.round(select.RoomType * select.RemontType * select.HouseType * select.Metric); var priceMat = Math.round(price * (100 - select.coefficientCalcMaterials)/100); if (price != 0 && !isNaN(price)){ $('#calc-result').html(numberFormatCalc(price)); $('#calc-result-mat').html(numberFormatCalc(priceMat)); $('#calc-result-full').html(numberFormatCalc(price+priceMat)); $('.calc-result').show(); }else{ $('.calc-result').hide(); } } function numberFormatCalc(priceString){ var a = priceString.toString().split(''); var mod = a.length%3; for (i in a){ if ((i+1)%3 == mod){ a[i] = a[i] + ' '; } } return a.join(''); } function initCarousel(id){ items = jsonData.RoomType[id]; if (typeof items != 'undefined'){ if (items.gallery.length > 0){ $('#gallery_slider').html(); var html = ''; for (i in items.gallery){ html = html + '<li><a class="single_3" rel="carousel-group" href="'+ items.gallery[i]['med_src'] +'"><img src="' + items.gallery[i]['min_src'] + '" alt="' + items.gallery[i]['title'] + '" height="160px" /></a></li>' + ''; } $('#gallery_slider').html(html); $('#gallery_slider img:last').ready(function(){ setTimeout( startCarousel, 50 ); $('.b-calc-carousel').show(); }); } } } function startCarousel () { $("#gallery_slider").carouFredSel({ circular: false, auto : false, width : '100%', height: 200, align : 'false', prev : { button : "#foo2_prev", key : "left", items: 1 }, next : { button : "#foo2_next", key : "right", items: 1 } }); } }); |
Часовой пояс GMT +3, время: 03:59. |