// pages/Calculation/Calculation.js Page({ data: { OM: '', // 有机质含量 CL: '', // 土壤粘粒重量 CEC: '', // 阳离子交换量 H: '', // 氢离子含量 HN: '', // 铵离子含量 Al: '', // 铝离子含量 free_alumina: '', // 游离氧化铝含量 free_iron_oxides: '', // 游离氧化铁含量 collection_location: '', // 采样地点 collection_date: '', // 采样时间 initialPH: '', // 土壤初始 pH targetPH: '', // 土壤目标 pH materials: ['石灰石(粉)CaCO3', '生石灰(粉)', '纯CaO (粉)', '熟石灰(粉)', '白云石 (粉)', '硅钙钾镁肥', '其他含CaO和MgO材料'], selectedMaterialIndex: 0, // 默认选中的碱性物料索引 selectedMaterial: '石灰石(粉)CaCO3', // 默认物料 }, // 更新有机质含量 onOMChange: function(e) { this.setData({ OM: e.detail.value }); }, // 更新土壤粘粒重量 onCLChange: function(e) { this.setData({ CL: e.detail.value }); }, // 更新阳离子交换量 onCECChange: function(e) { this.setData({ CEC: e.detail.value }); }, // 更新氢离子含量 onHChange: function(e) { this.setData({ H: e.detail.value }); }, // 更新铵离子含量 onHNChange: function(e) { this.setData({ HN: e.detail.value }); }, // 更新铝离子含量 onAlChange: function(e) { this.setData({ Al: e.detail.value }); }, // 更新游离氧化铝含量 onFreeAluminaChange: function(e) { this.setData({ free_alumina: e.detail.value }); }, // 更新游离氧化铁含量 onFreeIronOxidesChange: function(e) { this.setData({ free_iron_oxides: e.detail.value }); }, // 更新采样地点 onCollectionLocationChange: function(e) { this.setData({ collection_location: e.detail.value }); }, // 更新采样时间 onBindDateChange: function(e) { this.setData({ collection_date: e.detail.value }); }, // 处理土壤初始 pH 的输入 onInitialPHChange(e) { this.setData({ initialPH: e.detail.value, }); }, // 处理土壤目标 pH 的输入 onTargetPHChange(e) { this.setData({ targetPH: e.detail.value, }); }, // 处理碱性物料选择 onSelectMaterial(e) { const index = e.detail.value; this.setData({ selectedMaterialIndex: index, selectedMaterial: this.data.materials[index], }); }, // 计算方法 calculate: function() { console.log('开始计算...'); const data = { organic_matter: this.data.OM, chloride: this.data.CL, cec: this.data.CEC, h_concentration: this.data.H, hn: this.data.HN, al_concentration: this.data.Al, free_alumina: this.data.free_alumina, free_iron: this.data.free_iron_oxides, delta_ph: this.data.targetPH - this.data.initialPH // 假设delta_ph是目标pH和初始pH的差值 }; wx.request({ url: 'http://localhost:5000/predict', method: 'POST', data: JSON.stringify(data), header: { 'content-type': 'application/json' }, success: (res) => { console.log('预测结果:', res.data.predictions); wx.navigateTo({ url: `/pages/Result/Result?result=${encodeURIComponent(JSON.stringify(res.data.predictions))}` }); }, fail: (error) => { console.error('请求失败:', error); } }); } })