// Функция для округления до ближайших 100 рублей
function roundTo100(num) {
return Math.round(num / 100) * 100;
}
// Функция для заполнения выпадающих списков
function populateDropdowns() {
const products = [...new Set(priceData.map(item => item.product))];
const productSelect = document.getElementById('product');
products.forEach(product => {
const option = document.createElement('option');
option.value = product;
option.textContent = product;
productSelect.appendChild(option);
});
const categories = [...new Set(priceData.map(item => item.category))];
const categorySelect = document.getElementById('category');
categories.forEach(category => {
const option = document.createElement('option');
option.value = category;
option.textContent = category;
categorySelect.appendChild(option);
});
}
// Функция для расчёта цены
function calculatePrice() {
const product = document.getElementById('product').value;
const category = document.getElementById('category').value;
const width = parseInt(document.getElementById('width').value);
const height = parseInt(document.getElementById('height').value);
const item = priceData.find(item =>
item.product === product &&
item.category === category &&
item.width === width &&
item.height === height
);
if (item) {
const roundedPrice = roundTo100(item.price);
document.getElementById('priceOutput').textContent = `Цена: ${roundedPrice} руб.`;
} else {
document.getElementById('priceOutput').textContent = 'Нет данных для выбранных параметров.';
}
}
// Инициализация
populateDropdowns();