Spaces:
Sleeping
Sleeping
Update nutri_call.html
Browse files- nutri_call.html +97 -94
nutri_call.html
CHANGED
@@ -330,110 +330,113 @@
|
|
330 |
|
331 |
|
332 |
<script>
|
333 |
-
document.getElementById('calculate-btn').addEventListener('click', function() {
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
"
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
"
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
"
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
"
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
"K": getValue('fert_kh2po4_k') / 100
|
367 |
},
|
368 |
-
|
369 |
-
|
370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
}
|
372 |
-
}
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
}
|
383 |
-
};
|
384 |
|
385 |
-
|
386 |
-
|
387 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
}
|
399 |
-
}
|
400 |
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
hasErrors = true;
|
406 |
}
|
407 |
-
}
|
408 |
|
409 |
-
|
410 |
-
console.error("Обнаружены ошибки в данных! Отправка отменена.");
|
411 |
-
return;
|
412 |
-
}
|
413 |
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
if (xhr.readyState === 4) {
|
422 |
-
console.log("Статус ответа:", xhr.status);
|
423 |
-
if (xhr.status === 200) {
|
424 |
-
console.log("Успешный ответ от сервера:", JSON.parse(xhr.responseText));
|
425 |
-
} else {
|
426 |
-
console.error("Ошибка сервера:", xhr.status, xhr.statusText);
|
427 |
-
console.error("Текст ошибки:", xhr.responseText);
|
428 |
-
}
|
429 |
-
}
|
430 |
-
};
|
431 |
-
|
432 |
-
xhr.onerror = function() {
|
433 |
-
console.error("Ошибка сети при отправке запроса");
|
434 |
-
};
|
435 |
-
|
436 |
-
xhr.send(JSON.stringify(requestData));
|
437 |
});
|
438 |
</script>
|
439 |
|
|
|
330 |
|
331 |
|
332 |
<script>
|
333 |
+
document.getElementById('calculate-btn').addEventListener('click', async function() {
|
334 |
+
const btn = this;
|
335 |
+
btn.disabled = true;
|
336 |
+
btn.textContent = 'Расчет...';
|
337 |
+
|
338 |
+
try {
|
339 |
+
// 1. Собираем данные
|
340 |
+
const requestData = {
|
341 |
+
fertilizerConstants: {
|
342 |
+
"Кальциевая селитра": {
|
343 |
+
"N (NO3-)": parseFloat(document.getElementById('fert_ca_no3').value) / 100 || 0,
|
344 |
+
"Ca": parseFloat(document.getElementById('fert_ca_ca').value) / 100 || 0
|
345 |
+
},
|
346 |
+
"Калий азотнокислый": {
|
347 |
+
"N (NO3-)": parseFloat(document.getElementById('fert_kno3_no3').value) / 100 || 0,
|
348 |
+
"K": parseFloat(document.getElementById('fert_kno3_k').value) / 100 || 0
|
349 |
+
},
|
350 |
+
"Аммоний азотнокислый": {
|
351 |
+
"N (NO3-)": parseFloat(document.getElementById('fert_nh4no3_no3').value) / 100 || 0,
|
352 |
+
"N (NH4+)": parseFloat(document.getElementById('fert_nh4no3_nh4').value) / 100 || 0
|
353 |
+
},
|
354 |
+
"Сульфат магния": {
|
355 |
+
"Mg": parseFloat(document.getElementById('fert_mgso4_mg').value) / 100 || 0,
|
356 |
+
"S": parseFloat(document.getElementById('fert_mgso4_s').value) / 100 || 0
|
357 |
+
},
|
358 |
+
"Монофосфат калия": {
|
359 |
+
"P": parseFloat(document.getElementById('fert_kh2po4_p').value) / 100 || 0,
|
360 |
+
"K": parseFloat(document.getElementById('fert_kh2po4_k').value) / 100 || 0
|
361 |
+
},
|
362 |
+
"Калий сернокислый": {
|
363 |
+
"K": parseFloat(document.getElementById('fert_k2so4_k').value) / 100 || 0,
|
364 |
+
"S": parseFloat(document.getElementById('fert_k2so4_s').value) / 100 || 0
|
365 |
+
}
|
|
|
366 |
},
|
367 |
+
profileSettings: {
|
368 |
+
'P': parseFloat(document.getElementById('profile_p').value) || 0,
|
369 |
+
'K': parseFloat(document.getElementById('profile_k').value) || 0,
|
370 |
+
'Mg': parseFloat(document.getElementById('profile_mg').value) || 0,
|
371 |
+
'Ca': parseFloat(document.getElementById('profile_ca').value) || 0,
|
372 |
+
'S': parseFloat(document.getElementById('profile_s').value) || 0,
|
373 |
+
'N (NO3-)': parseFloat(document.getElementById('profile_no3').value) || 0,
|
374 |
+
'N (NH4+)': parseFloat(document.getElementById('profile_nh4').value) || 0,
|
375 |
+
'liters': parseInt(document.getElementById('liters-input').value) || 1
|
376 |
}
|
377 |
+
};
|
378 |
+
|
379 |
+
console.log("Отправляемые данные:", requestData);
|
380 |
+
|
381 |
+
// 2. Отправка запроса
|
382 |
+
const response = await fetch('/calculation', {
|
383 |
+
method: 'POST',
|
384 |
+
headers: {
|
385 |
+
'Content-Type': 'application/json',
|
386 |
+
},
|
387 |
+
body: JSON.stringify(requestData)
|
388 |
+
});
|
389 |
+
|
390 |
+
// 3. Обработка ответа
|
391 |
+
const result = await response.json();
|
392 |
+
console.log("Полный ответ сервера:", result);
|
393 |
+
|
394 |
+
if (!response.ok) {
|
395 |
+
throw new Error(result.message || `HTTP error! status: ${response.status}`);
|
396 |
}
|
|
|
397 |
|
398 |
+
// 4. Заполнение результатов
|
399 |
+
const fertilizerMap = {
|
400 |
+
"Сульфат магния": "magnesium_sulfate",
|
401 |
+
"Кальциевая селитра": "calcium_nitrate",
|
402 |
+
"Монофосфат калия": "monopotassium_phosphate",
|
403 |
+
"Аммоний азотнокислый": "ammonium_nitrate",
|
404 |
+
"Калий сернокислый": "potassium_sulfate",
|
405 |
+
"Калий азотнокислый": "potassium_nitrate"
|
406 |
+
};
|
407 |
|
408 |
+
// Очистка полей
|
409 |
+
Object.values(fertilizerMap).forEach(id => {
|
410 |
+
const field = document.getElementById(id);
|
411 |
+
if (field) field.value = "0";
|
412 |
+
});
|
413 |
+
|
414 |
+
// Заполнение данных
|
415 |
+
if (result.data?.fertilizers) {
|
416 |
+
result.data.fertilizers.forEach(fert => {
|
417 |
+
const fieldId = fertilizerMap[fert.name];
|
418 |
+
if (fieldId) {
|
419 |
+
const field = document.getElementById(fieldId);
|
420 |
+
if (field) field.value = fert.grams?.toFixed(3) || "0";
|
421 |
+
}
|
422 |
+
});
|
423 |
}
|
|
|
424 |
|
425 |
+
// Вывод EC
|
426 |
+
if (result.data?.ec !== undefined) {
|
427 |
+
const ecField = document.getElementById('ec-value');
|
428 |
+
if (ecField) ecField.textContent = result.data.ec.toFixed(2);
|
|
|
429 |
}
|
|
|
430 |
|
431 |
+
alert("Расчет успешно завершен!");
|
|
|
|
|
|
|
432 |
|
433 |
+
} catch (error) {
|
434 |
+
console.error("Ошибка:", error);
|
435 |
+
alert(`Ошибка: ${error.message}`);
|
436 |
+
} finally {
|
437 |
+
btn.disabled = false;
|
438 |
+
btn.textContent = 'Рассчитать';
|
439 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
440 |
});
|
441 |
</script>
|
442 |
|