175 lines
4.4 KiB
JavaScript
175 lines
4.4 KiB
JavaScript
// pages/cppDeceleration/cppDeceleration.js
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
formData: {
|
|
name: '',
|
|
bone_age: '',
|
|
uterus_length: '',
|
|
uterus_width: '',
|
|
lh_peak: '',
|
|
fsh_peak: '',
|
|
fsh_3m: '',
|
|
igf1: ''
|
|
},
|
|
result: null,
|
|
riskLevel: '',
|
|
suggestion: '',
|
|
show: false
|
|
},
|
|
|
|
onLoad(options) {
|
|
if (options.data) {
|
|
try {
|
|
const data = JSON.parse(decodeURIComponent(options.data));
|
|
this.setData({
|
|
formData: {
|
|
name: data.name || '',
|
|
bone_age: data.bone_age || '',
|
|
uterus_length: data.uterus_length || '',
|
|
uterus_width: data.uterus_width || '',
|
|
lh_peak: data.lh_peak || '',
|
|
fsh_peak: data.fsh_peak || '',
|
|
fsh_3m: data.fsh_3m || '',
|
|
igf1: data.igf1 || ''
|
|
}
|
|
});
|
|
} catch (e) {}
|
|
}
|
|
},
|
|
|
|
// 返回
|
|
onClickLeft() {
|
|
wx.navigateBack();
|
|
},
|
|
|
|
// 统一输入处理
|
|
handleInput(e) {
|
|
const { field } = e.currentTarget.dataset;
|
|
this.setData({
|
|
[`formData.${field}`]: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 登录检查
|
|
checkLogin() {
|
|
if (!wx.getStorageSync('phone')) {
|
|
wx.setStorageSync('uidFlag', false);
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请先登录',
|
|
success(res) {
|
|
if (res.confirm) {
|
|
wx.switchTab({ url: '/pages/my/my' });
|
|
}
|
|
}
|
|
});
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
// 表单验证
|
|
validateForm() {
|
|
const { name, bone_age, uterus_length, uterus_width, lh_peak, fsh_peak, fsh_3m, igf1 } = this.data.formData;
|
|
if (!name.trim()) {
|
|
wx.showToast({ title: '请输入姓名', icon: 'none' });
|
|
return false;
|
|
}
|
|
const fields = [
|
|
{ key: 'bone_age', name: '初诊骨龄', min: 5, max: 13 },
|
|
{ key: 'uterus_length', name: '初诊子宫长', min: 1, max: 4.5 },
|
|
{ key: 'uterus_width', name: '初诊子宫宽', min: 0.5, max: 3.5 },
|
|
{ key: 'lh_peak', name: 'LH峰值', min: 0.5, max: 90 },
|
|
{ key: 'fsh_peak', name: 'FSH峰值', min: 0.5, max: 25 },
|
|
{ key: 'fsh_3m', name: '治疗3月FSH', min: 0, max: 8 },
|
|
{ key: 'igf1', name: '基础IGF-1', min: 100, max: 800 }
|
|
];
|
|
for (const f of fields) {
|
|
const val = parseFloat(this.data.formData[f.key]);
|
|
if (isNaN(val) || val === '') {
|
|
wx.showToast({ title: '请输入' + f.name, icon: 'none' });
|
|
return false;
|
|
}
|
|
if (val < f.min || val > f.max) {
|
|
wx.showToast({ title: f.name + '范围: ' + f.min + '-' + f.max, icon: 'none' });
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
},
|
|
|
|
// 开始计算
|
|
calculate() {
|
|
if (!this.checkLogin()) return;
|
|
if (!this.validateForm()) return;
|
|
|
|
this.setData({ show: true });
|
|
this.submitCalculation();
|
|
},
|
|
|
|
// 提交计算
|
|
submitCalculation() {
|
|
const { formData } = this.data;
|
|
wx.request({
|
|
url: app.globalData.url + 'app/Cppwechat/calculate',
|
|
method: 'POST',
|
|
header: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
data: {
|
|
uid: wx.getStorageSync('uid'),
|
|
name: formData.name,
|
|
bone_age: formData.bone_age,
|
|
uterus_length: formData.uterus_length,
|
|
uterus_width: formData.uterus_width,
|
|
lh_peak: formData.lh_peak,
|
|
fsh_peak: formData.fsh_peak,
|
|
fsh_3m: formData.fsh_3m,
|
|
igf1: formData.igf1
|
|
},
|
|
success: this.handleCalculationResponse.bind(this),
|
|
fail: function() {
|
|
wx.showToast({ title: '网络请求失败', icon: 'error' });
|
|
}
|
|
});
|
|
},
|
|
|
|
// 处理计算结果
|
|
handleCalculationResponse(res) {
|
|
if (res.data.erro === 0) {
|
|
const prob = (res.data.calculate_result * 100).toFixed(1);
|
|
const level = res.data.risk_level;
|
|
|
|
this.setData({
|
|
result: prob + '%',
|
|
riskLevel: level,
|
|
suggestion: res.data.suggestion
|
|
});
|
|
} else {
|
|
wx.showToast({ title: res.data.msg, icon: 'error' });
|
|
this.setData({ show: false });
|
|
}
|
|
},
|
|
|
|
// 重置表单
|
|
reset() {
|
|
if (!this.checkLogin()) return;
|
|
this.setData({
|
|
formData: {
|
|
name: '', bone_age: '', uterus_length: '', uterus_width: '',
|
|
lh_peak: '', fsh_peak: '', fsh_3m: '', igf1: ''
|
|
}
|
|
});
|
|
},
|
|
|
|
// 查看历史
|
|
go_history() {
|
|
wx.navigateTo({ url: '/pages/order/order' });
|
|
},
|
|
|
|
// 关闭结果弹窗
|
|
tiaoguo() {
|
|
this.setData({ show: false });
|
|
}
|
|
});
|