DmitrMakeev commited on
Commit
e381455
·
verified ·
1 Parent(s): 31a7d72

Update nutri_call.html

Browse files
Files changed (1) hide show
  1. 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
- "CaN2O6": {
346
- "NO3": getValue('fert_ca_no3'),
347
- "Ca": getValue('fert_ca_ca')
348
  },
349
- "KNO3": {
350
- "NO3": getValue('fert_kno3_no3'),
351
- "K": getValue('fert_kno3_k')
352
  },
353
- "NH4NO3": {
354
- "NH4": getValue('fert_nh4no3_nh4'),
355
- "NO3": getValue('fert_nh4no3_no3')
356
  },
357
- "MgSO4": {
358
- "Mg": getValue('fert_mgso4_mg'),
359
- "S": getValue('fert_mgso4_s')
360
  },
361
- "KH2PO4": {
362
- "P": getValue('fert_kh2po4_p'),
363
- "K": getValue('fert_kh2po4_k')
364
  },
365
- "K2SO4": {
366
- "K": getValue('fert_k2so4_k'),
367
- "S": getValue('fert_k2so4_s')
368
  }
369
  },
370
  profileSettings: {
371
- 'P': getValue('profile_p'),
372
- 'K': getValue('profile_k'),
373
- 'Mg': getValue('profile_mg'),
374
- 'Ca': getValue('profile_ca'),
375
- 'S': getValue('profile_s'),
376
- 'NO3': getValue('profile_no3'),
377
- 'NH4': getValue('profile_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("Ответ от сервера:", data);
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