// 都道府県選択時の市区町村更新
document.getElementById(‘prefecture’).addEventListener(‘change’, function() {
const prefecture = this.value;
const citySelect = document.getElementById(‘city’);
// 市区町村選択をリセット
citySelect.innerHTML = ‘
‘;
citySelect.disabled = false;
if (prefecture) {
const cities = cityData[prefecture] || defaultCities;
cities.forEach(city => {
const option = document.createElement(‘option’);
option.value = city.name;
option.dataset.price = city.price;
option.textContent = city.name;
citySelect.appendChild(option);
});
} else {
citySelect.disabled = true;
citySelect.innerHTML = ‘
‘;
}
});
document.getElementById(‘appraisalForm’).addEventListener(‘submit’, function(e) {
e.preventDefault();
calculateAppraisal();
});
function calculateAppraisal() {
// 入力値を取得
const prefecture = document.getElementById(‘prefecture’).value;
const citySelect = document.getElementById(‘city’);
const selectedCity = citySelect.value;
const landArea = parseFloat(document.getElementById(‘landArea’).value);
const buildingArea = parseFloat(document.getElementById(‘buildingArea’).value);
const buildingAge = parseInt(document.getElementById(‘buildingAge’).value);
const structure = document.getElementById(‘structure’).value;
const stationDistance = document.getElementById(‘stationDistance’).value;
const condition = document.getElementById(‘condition’).value;
// 市区町村の単価を取得(選択されている場合)
let basePrice;
if (selectedCity && citySelect.selectedOptions[0].dataset.price) {
basePrice = parseFloat(citySelect.selectedOptions[0].dataset.price);
} else {
basePrice = regionPrices[prefecture];
}
// 土地評価額計算
const landValue = landArea * basePrice * 10000 * stationMultiplier[stationDistance];
// 建物評価額計算(築年数による減価を考慮)
const buildingBaseValue = buildingArea * basePrice * 8000 * structureMultiplier[structure];
const depreciationRate = Math.max(0.1, 1 – (buildingAge * 0.03)); // 年3%減価、最低10%
const buildingValue = buildingBaseValue * depreciationRate * conditionMultiplier[condition];
// 立地補正額
const locationAdjustment = (landValue + buildingValue) * (stationMultiplier[stationDistance] – 1);
// 状態補正額
const conditionAdjustment = buildingValue * (conditionMultiplier[condition] – 1);
// 合計
const totalValue = landValue + buildingValue;
// 価格帯(±15%)
const lowerRange = Math.round(totalValue * 0.85);
const upperRange = Math.round(totalValue * 1.15);
// 結果を表示
displayResults(landValue, buildingValue, locationAdjustment, conditionAdjustment, totalValue, lowerRange, upperRange);
}
実家じまい簡易査定ツール