<script>
document.addEventListener("DOMContentLoaded", function(){
let percentList = [
[500000 , 40],
[1000000 , 50],
[2000000 , 55],
[4000000 , 60]
];
let currency = " ₽";
function divide(x, delimiter) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, delimiter || " ");
};
function makeСalculation(){
//Получаем значение нужных полей
let startSumm = +document.getElementsByName('start_summ')[0].value;
let term = +document.getElementsByName('term')[0].value;
//Получаем текст для вывода стартовой суммы и срока
let start_summ = document.querySelectorAll('.start_summ .tn-atom')[0].innerHTML = divide(startSumm)+currency;
let termTxt = document.querySelectorAll('.term .tn-atom')[0].innerHTML = divide(term) +' мес';
let percent=0;
for (let i = 0; i < percentList.length; i++) {
if (startSumm>=percentList[i][0]){
percent = percentList[i][1];
};
};
//Считаем без залога
let interest_rate = percent;
let monthly_income = Math.round(startSumm*percent/12*0.001)*10;
let amount_payments = monthly_income*term+startSumm;
let profitability = monthly_income*term;
//Получаем текст для вывода без залога
document.querySelectorAll('.interest_rate .tn-atom')[0].innerHTML = interest_rate + ' %';
document.querySelectorAll('.monthly_income .tn-atom')[0].innerHTML = divide( monthly_income ) + currency;
document.querySelectorAll('.amount_payments .tn-atom')[0].innerHTML = divide( amount_payments ) + currency;
document.querySelectorAll('.profitability .tn-atom')[0].innerHTML = divide( profitability ) + currency;
//Считаем с залогом
let interest_rate_coll = percent - 10;
let monthly_income_coll = Math.round(startSumm*interest_rate_coll/12*0.001)*10;
let amount_payments_coll = monthly_income_coll*term+startSumm;
let profitability_coll = monthly_income_coll*term;
//Получаем текст для вывода с залогом
document.querySelectorAll('.interest_rate_coll .tn-atom')[0].innerHTML = interest_rate_coll +' %';
document.querySelectorAll('.monthly_income_coll .tn-atom')[0].innerHTML = divide(monthly_income_coll)+currency;
document.querySelectorAll('.amount_payments_coll .tn-atom')[0].innerHTML = divide(amount_payments_coll)+currency;
document.querySelectorAll('.profitability_coll .tn-atom')[0].innerHTML = divide(profitability_coll)+currency;
};
setTimeout(function(){ makeСalculation()}, 2500);
let investForm = document.querySelectorAll('.invest-form')[0];
//При изменении стартовой суммы или срока
investForm.addEventListener( 'input' , function() { makeСalculation()});
});
</script>
<style>
.profitability .t-calc__wrapper {
color: #3ab6ec !important;
}
.invest-form .t-range__value-txt {
display: none !important;
}
</style>