<script>
(function () {
const zeroCalcBlock = document.querySelector('.uc-zeroformid');
const priceTable = document.querySelector('.uc-calc-price');
if(zeroCalcBlock&&priceTable){
zeroCalcBlock.querySelector('div[data-elem-type="form"]').addEventListener('render', function() {
calculate();
});
function calculate(){
setTimeout(function() {
const formElement = zeroCalcBlock.querySelector(`.tn-atom__form`);
if (formElement) {
let isProgrammaticChange = false;
formElement.addEventListener('change', function(event) {
if (isProgrammaticChange) {
isProgrammaticChange = false;
return;
}
if (event.target.tagName === 'SELECT') {
getSetPrice();
};
});
function getSetPrice(){
const nalog = zeroCalcBlock.querySelector('select[name="nalog"]').value.trim().toLowerCase();
const vid = zeroCalcBlock.querySelector('select[name="vid"]').value.trim().toLowerCase();
const kol = zeroCalcBlock.querySelector('select[name="kol"]').value.trim().toLowerCase();
const modeSelect = zeroCalcBlock.querySelector('select[name="mode"]');
const mode = modeSelect.selectedIndex;
const table = priceTable.querySelector('.t431__table');
const rows = table.querySelectorAll('.t431__tbody tr');
let price = null;
for (const row of rows) {
const cells = row.querySelectorAll('.t431__td');
if (cells[0].textContent.trim().toLowerCase() === nalog &&
cells[1].textContent.trim().toLowerCase() === vid &&
cells[2].textContent.trim().toLowerCase() === kol) {
let priceColumn;
if (mode === 0) priceColumn = 3; // Всё сам
else if (mode === 1) priceColumn = 4; // 50 на 50
else if (mode === 2) priceColumn = 5; // Мы сами
price = cells[priceColumn].textContent.trim();
break;
};
};
if (price!=null) {
modeSelect.querySelector('option:checked').setAttribute('data-calc-value', price);
isProgrammaticChange = true;
modeSelect.dispatchEvent(new Event('change', { bubbles: true }));
};
};
getSetPrice();
};
}, 1500);
};
};
})();
</script>