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