This commit is contained in:
2025-03-09 23:40:39 +08:00
parent ed1188098f
commit 7e801fed23
4 changed files with 218 additions and 148 deletions

View File

@@ -1,166 +1,135 @@
// pages/tool/tool.js
const app = getApp()
Page({
data: {
heightone: '',
name: '诺言',
age: '6',
height: '120',
boneAge: '6',
fatherHeight: '32',
motherHeight: '28',
igf: '334',
lh: '0.6',
thickness: '11',
// 表单数据
formData: {
name: '',
age: '',
height: '',
boneAge: '',
fatherHeight: '',
motherHeight: '',
igf: '',
lh: '',
thickness: ''
},
// 计算结果
result: '',
show: false,
// 结果弹窗显示状态
show: false
},
inputName: function (e) {
// =============== 表单输入处理 ===============
// 统一的输入处理函数
handleInput(e) {
const { field } = e.currentTarget.dataset
this.setData({
name: e.detail.value
[`formData.${field}`]: e.detail.value
})
},
inputAge: function (e) {
this.setData({
age: e.detail.value
})
},
inputHeight: function (e) {
this.setData({
height: e.detail.value
})
},
inputBoneAge: function (e) {
this.setData({
boneAge: e.detail.value
})
},
inputFatherHeight: function (e) {
this.setData({
fatherHeight: e.detail.value
})
},
inputMotherHeight: function (e) {
this.setData({
motherHeight: e.detail.value
})
},
inputIGF: function (e) {
this.setData({
igf: e.detail.value
})
},
inputLH: function (e) {
this.setData({
lh: e.detail.value
})
},
inputThickness: function (e) {
this.setData({
thickness: e.detail.value
})
},
pintuan() {
this.setData({
show: true
});
},
tiaoguo() {
this.setData({
show: false
});
},
calculate: function () {
const data = this.data;
const result = {
};
console.log(result);
if (wx.getStorageSync('phone') == '') {
wx.setStorageSync('uidFlag', false);
console.log('请登录')
this.isdenglu()
} else {
this.setData({
show: true
});
this.payment()
// =============== 登录检查 ===============
checkLogin() {
if (!wx.getStorageSync('phone')) {
wx.setStorageSync('uidFlag', false)
this.showLoginModal()
return false
}
return true
},
//是否登录
isdenglu() {
showLoginModal() {
wx.showModal({
title: '提示',
content: '请先登录',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
wx.switchTab({
url: '/pages/my/my'
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
payment() {
if (this.data.name == '') {
// =============== 计算相关 ===============
// 开始计算
calculate() {
if (!this.checkLogin()) return
if (!this.validateForm()) return
this.setData({ show: true })
this.submitCalculation()
},
// 表单验证
validateForm() {
const { name } = this.data.formData
if (!name.trim()) {
wx.showToast({
title: '请输入姓名',
icon: 'none'
});
return
})
return false
}
var that = this;
return true
},
// 提交计算请求
submitCalculation() {
const { formData } = this.data
wx.request({
url: app.globalData.url + 'app/Ruilaiwechat/calculate',
data: {
uid: wx.getStorageSync('uid'), //人员id
name: this.data.name, //姓名
age: this.data.age, //年龄
height: this.data.height, //身高
bone_age: this.data.boneAge, //骨龄
father_height: this.data.fatherHeight, //父亲身高
mother_height: this.data.motherHeight, //母亲身高
IGF: this.data.igf, //IGF-1值
LH: this.data.lh, //LH基础值
uterus_thickness: this.data.thickness, //子宫厚度
},
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success(res) {
if (res.data.erro == 0) {
that.setData({
result: res.data.calculate_resutlt,
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'error',
duration: 2000
})
}
}
data: {
uid: wx.getStorageSync('uid'),
name: formData.name,
age: formData.age,
height: formData.height,
bone_age: formData.boneAge,
father_height: formData.fatherHeight,
mother_height: formData.motherHeight,
IGF: formData.igf,
LH: formData.lh,
uterus_thickness: formData.thickness
},
success: this.handleCalculationResponse.bind(this)
})
},
onLoad: function (options) {
},
go_history(){
wx.navigateTo({
url: '/pages/order/order',
})
},
reset() {
if (wx.getStorageSync('phone') == '') {
wx.setStorageSync('uidFlag', false);
console.log('请登录')
this.isdenglu()
} else {
// 处理计算响应
handleCalculationResponse(res) {
if (res.data.erro === 0) {
this.setData({
result: res.data.calculate_resutlt
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'error',
duration: 2000
})
}
},
// =============== 其他功能 ===============
// 重置表单
reset() {
if (!this.checkLogin()) return
this.setData({
formData: {
name: '',
age: '',
height: '',
@@ -169,9 +138,24 @@ Page({
motherHeight: '',
igf: '',
lh: '',
thickness: '',
});
console.log('order_id==')
}
thickness: ''
}
})
},
// 查看历史记录
go_history() {
wx.navigateTo({
url: '/pages/order/order'
})
},
// 弹窗控制
pintuan() {
this.setData({ show: true })
},
tiaoguo() {
this.setData({ show: false })
}
})