DmitrMakeev commited on
Commit
7792ca7
·
verified ·
1 Parent(s): 677e494

Update nutri_call.html

Browse files
Files changed (1) hide show
  1. nutri_call.html +67 -94
nutri_call.html CHANGED
@@ -330,72 +330,62 @@
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",
@@ -404,39 +394,22 @@ document.getElementById('calculate-btn').addEventListener('click', async functio
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
 
 
330
 
331
 
332
  <script>
333
+ document.getElementById('calculate-btn').addEventListener('click', function() {
334
+ // 1. Собираем данные (как РАБОТАЛО РАНЬШЕ)
335
+ const requestData = {
336
+ fertilizerConstants: {
337
+ "Кальциевая селитра": {
338
+ "N (NO3-)": parseFloat(document.getElementById('fert_ca_no3').value) / 100,
339
+ "Ca": parseFloat(document.getElementById('fert_ca_ca').value) / 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  },
341
+ "Калий азотнокислый": {
342
+ "N (NO3-)": parseFloat(document.getElementById('fert_kno3_no3').value) / 100,
343
+ "K": parseFloat(document.getElementById('fert_kno3_k').value) / 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  },
345
+ "Аммоний азотнокислый": {
346
+ "N (NO3-)": parseFloat(document.getElementById('fert_nh4no3_no3').value) / 100,
347
+ "N (NH4+)": parseFloat(document.getElementById('fert_nh4no3_nh4').value) / 100
348
+ },
349
+ "Сульфат магния": {
350
+ "Mg": parseFloat(document.getElementById('fert_mgso4_mg').value) / 100,
351
+ "S": parseFloat(document.getElementById('fert_mgso4_s').value) / 100
352
+ },
353
+ "Монофосфат калия": {
354
+ "P": parseFloat(document.getElementById('fert_kh2po4_p').value) / 100,
355
+ "K": parseFloat(document.getElementById('fert_kh2po4_k').value) / 100
356
+ },
357
+ "Калий сернокислый": {
358
+ "K": parseFloat(document.getElementById('fert_k2so4_k').value) / 100,
359
+ "S": parseFloat(document.getElementById('fert_k2so4_s').value) / 100
360
+ }
361
+ },
362
+ profileSettings: {
363
+ 'P': parseFloat(document.getElementById('profile_p').value),
364
+ 'K': parseFloat(document.getElementById('profile_k').value),
365
+ 'Mg': parseFloat(document.getElementById('profile_mg').value),
366
+ 'Ca': parseFloat(document.getElementById('profile_ca').value),
367
+ 'S': parseFloat(document.getElementById('profile_s').value),
368
+ 'N (NO3-)': parseFloat(document.getElementById('profile_no3').value),
369
+ 'N (NH4+)': parseFloat(document.getElementById('profile_nh4').value),
370
+ 'liters': parseInt(document.getElementById('liters-input').value) || 1
371
  }
372
+ };
373
+
374
+ console.log("Отправляемые данные:", requestData);
375
 
376
+ // 2. Отправка (старый рабочий вариант)
377
+ fetch('/calculation', {
378
+ method: 'POST',
379
+ headers: {
380
+ 'Content-Type': 'application/json',
381
+ },
382
+ body: JSON.stringify(requestData)
383
+ })
384
+ .then(response => response.json())
385
+ .then(data => {
386
+ console.log("ОТВЕТ СЕРВЕРА:", data);
387
+
388
+ // 3. Заполнение результатов (как было)
389
  const fertilizerMap = {
390
  "Сульфат магния": "magnesium_sulfate",
391
  "Кальциевая селитра": "calcium_nitrate",
 
394
  "Калий сернокислый": "potassium_sulfate",
395
  "Калий азотнокислый": "potassium_nitrate"
396
  };
397
+
398
+ // Заполняем граммовки
399
+ data.fertilizers.forEach(fert => {
400
+ const fieldId = fertilizerMap[fert.name];
401
+ if (fieldId) {
402
+ document.getElementById(fieldId).value = fert.grams.toFixed(3);
403
+ }
404
  });
405
+
406
+ // Выводим EC
407
+ document.getElementById('ec-value').textContent = data.ec.toFixed(2);
408
+ })
409
+ .catch(error => {
410
+ console.error("ОШИБКА:", error);
411
+ alert("Ошибка расчета: " + error.message);
412
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  });
414
  </script>
415