window.addEventListener('DOMContentLoaded', () => {
// 施工可能面積データ(重機・車の横づけ・雑草・傾斜ごと)
const constructionAreaData = [
{heavy: "可", car: "可", weeds: "ほとんど生えていない", slope: "平坦", area: 40, soilTime: 0.1},
{heavy: "可", car: "可", weeds: "ほとんど生えていない", slope: "やや傾斜", area: 30, soilTime: 0.2},
{heavy: "可", car: "可", weeds: "ほとんど生えていない", slope: "きつい傾斜", area: 20, soilTime: 0.3},
{heavy: "可", car: "可", weeds: "部分的に生えている", slope: "平坦", area: 35, soilTime: 0.1},
{heavy: "可", car: "可", weeds: "部分的に生えている", slope: "やや傾斜", area: 25, soilTime: 0.2},
{heavy: "可", car: "可", weeds: "部分的に生えている", slope: "きつい傾斜", area: 15, soilTime: 0.3},
{heavy: "可", car: "可", weeds: "一面に生えている", slope: "平坦", area: 30, soilTime: 0.1},
{heavy: "可", car: "可", weeds: "一面に生えている", slope: "やや傾斜", area: 20, soilTime: 0.2},
{heavy: "可", car: "可", weeds: "一面に生えている", slope: "きつい傾斜", area: 10, soilTime: 0.3},
{heavy: "可", car: "不可", weeds: "ほとんど生えていない", slope: "平坦", area: 28, soilTime: 0.2},
{heavy: "可", car: "不可", weeds: "ほとんど生えていない", slope: "やや傾斜", area: 15, soilTime: 0.3},
{heavy: "可", car: "不可", weeds: "ほとんど生えていない", slope: "きつい傾斜", area: 8, soilTime: 0.4},
{heavy: "可", car: "不可", weeds: "部分的に生えている", slope: "平坦", area: 24, soilTime: 0.2},
{heavy: "可", car: "不可", weeds: "部分的に生えている", slope: "やや傾斜", area: 12, soilTime: 0.3},
{heavy: "可", car: "不可", weeds: "部分的に生えている", slope: "きつい傾斜", area: 6, soilTime: 0.4},
{heavy: "可", car: "不可", weeds: "一面に生えている", slope: "平坦", area: 20, soilTime: 0.2},
{heavy: "可", car: "不可", weeds: "一面に生えている", slope: "やや傾斜", area: 10, soilTime: 0.3},
{heavy: "可", car: "不可", weeds: "一面に生えている", slope: "きつい傾斜", area: 3, soilTime: 0.4},
{heavy: "不可", car: "可", weeds: "ほとんど生えていない", slope: "平坦", area: 28, soilTime: 0.5},
{heavy: "不可", car: "可", weeds: "ほとんど生えていない", slope: "やや傾斜", area: 15, soilTime: 0.6},
{heavy: "不可", car: "可", weeds: "ほとんど生えていない", slope: "きつい傾斜", area: 8, soilTime: 0.8},
{heavy: "不可", car: "可", weeds: "部分的に生えている", slope: "平坦", area: 20, soilTime: 0.5},
{heavy: "不可", car: "可", weeds: "部分的に生えている", slope: "やや傾斜", area: 10, soilTime: 0.6},
{heavy: "不可", car: "可", weeds: "部分的に生えている", slope: "きつい傾斜", area: 3, soilTime: 0.8},
{heavy: "不可", car: "可", weeds: "一面に生えている", slope: "平坦", area: 10, soilTime: 0.5},
{heavy: "不可", car: "可", weeds: "一面に生えている", slope: "やや傾斜", area: 3, soilTime: 0.6},
{heavy: "不可", car: "可", weeds: "一面に生えている", slope: "きつい傾斜", area: 1, soilTime: 0.8},
{heavy: "不可", car: "不可", weeds: "ほとんど生えていない", slope: "平坦", area: 15, soilTime: 0.7},
{heavy: "不可", car: "不可", weeds: "ほとんど生えていない", slope: "やや傾斜", area: 7, soilTime: 0.8},
{heavy: "不可", car: "不可", weeds: "ほとんど生えていない", slope: "きつい傾斜", area: 3, soilTime: 1.1},
{heavy: "不可", car: "不可", weeds: "部分的に生えている", slope: "平坦", area: 8, soilTime: 0.7},
{heavy: "不可", car: "不可", weeds: "部分的に生えている", slope: "やや傾斜", area: 4, soilTime: 0.8},
{heavy: "不可", car: "不可", weeds: "部分的に生えている", slope: "きつい傾斜", area: 2, soilTime: 1.1},
{heavy: "不可", car: "不可", weeds: "一面に生えている", slope: "平坦", area: 5, soilTime: 0.7},
{heavy: "不可", car: "不可", weeds: "一面に生えている", slope: "やや傾斜", area: 2, soilTime: 0.8},
{heavy: "不可", car: "不可", weeds: "一面に生えている", slope: "きつい傾斜", area: 1, soilTime: 1.1},
];
// チップ種類ごとの単価(円/㎡)
const chipUnitPrice = {
"竹チップ": 2300,
"筏チップ(大粒)": 2600,
"筏チップ(小粒)": 2000,
"防草シート×竹チップ": 1400,
"防草シート×筏チップ(大粒)": 1700,
"防草シート×筏チップ(小粒)": 1100
};
// 距離ごとの移動時間と運搬費用
const distanceData = {
"~15km": {moveTime: 1, carryCost: 5000},
"~30km": {moveTime: 1.5, carryCost: 8000},
"~45km": {moveTime: 2, carryCost: 11000},
"45km~": {moveTime: 3, carryCost: 14000},
};
// 施工可能面積と残土詰め込み時間を計算する関数
function getConstructionArea(heavy, car, weeds, slope) {
const item = constructionAreaData.find(d =>
d.heavy === heavy &&
d.car === car &&
d.weeds === weeds &&
d.slope === slope
);
return item || {area: 0, soilTime: 0};
}
// 四捨五入の関数
function roundNumber(num) {
return Math.round(num);
}
// 見積もり計算メイン関数
function calculateEstimate(area, distance, chipType, heavy, car, slope, weeds) {
// 施工可能面積(cond)データ取得
const cond = getConstructionArea(heavy, car, weeds, slope);
if (cond.area === 0) return null; // 該当データなし
// チップ単価(unitPrice)
const unitPrice = chipUnitPrice[chipType];
if (!unitPrice) return null;
// 距離のデータ
const dist = distanceData[distance];
if (!dist) return null;
// 移動時間と運搬費用
const MT = dist.moveTime;
const CC = dist.carryCost;
// フレコン数
const bag = Math.ceil(area / 10);
// トラック台数
const track = Math.ceil(bag / 6) + (heavy === "可" ? 1 : 0);
// 施工時間(最低1)
const constructionTime = Math.max(1, Math.ceil(area / cond.area));
// 運搬時間(最低1)
const carryTime = Math.max(1, Math.ceil(track * MT));
// 残土積込時間(soilTimeはcondから)
const soilLoadingTime = Math.ceil((area / 10) * cond.soilTime);
// 施工日数(合計時間 ÷ 8時間/日 を切り上げ)
const constructionDays = Math.ceil((constructionTime + carryTime + soilLoadingTime) / 8);
// 材料費(単価 × 面積)
const materialCost = unitPrice * area;
// 残土処分費
const soilCost = Math.ceil(area / 10) * 5000;
// 労務費
const laborCost = (constructionDays * 54000);
// 福利厚生費
const welfareCost = (laborCost * 0.15);
// 燃料費
const fuelCost = (CC * track);
// スパイク費
const spikeCost = (slope === "きつい傾斜") ? area * 3000 : 0;
// 諸経費
const overheadCost = ((materialCost + soilCost + laborCost + welfareCost + fuelCost + spikeCost) * 0.1);
// 合計見積もり金額
const total = materialCost + soilCost + laborCost + welfareCost + fuelCost + spikeCost + overheadCost;
return Math.round(total);
}
// === イベント登録(ボタンが出現するまで待つ)===
const waitForButton = setInterval(() => {
const btn = document.getElementById('calc-btn');
if (btn) {
clearInterval(waitForButton); // 一度見つかったら停止
btn.addEventListener('click', (e) => {
e.preventDefault();
const areaInput = document.querySelector('input[name="area"]');
const area = areaInput ? parseFloat(areaInput.value) : NaN;
const getCheckedValue = name => {
const el = document.querySelector(`input[name="${name}"]:checked`);
return el ? el.value : null;
};
const distance = getCheckedValue('distance');
const chipType = getCheckedValue('chip-type');
const heavy = getCheckedValue('heavy-machine');
const car = getCheckedValue('car-access');
const slope = getCheckedValue('slope');
const weeds = getCheckedValue('weeds');
if (isNaN(area) || area <= 0 || !distance || !chipType || !heavy || !car || !slope || !weeds) {
document.getElementById('estimate-result').textContent = 'すべての項目を正しく入力してください';
return;
}
const estimate = calculateEstimate(area, distance, chipType, heavy, car, slope, weeds);
if (estimate === null) {
document.getElementById('estimate-result').textContent = '条件に合うデータがありません。';
return;
}
document.getElementById('estimate-result').textContent = `概算見積もり金額は ${estimate.toLocaleString()} 円です。`;
});
}
}, 300); // 0.3秒ごとに確認
});