diff --git a/pages/home/home.js b/pages/home/home.js index f138dcd..78b8ba8 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -14,7 +14,13 @@ Page({ }, onShow() { - this.getOrderList() + // 重置页码并重新获取数据 + this.setData({ + pageNum: 1, + news: [] + }, () => { + this.getOrderList() + }) }, // =============== 页面跳转相关 =============== @@ -123,14 +129,22 @@ Page({ // 处理资讯列表响应 handleOrderListResponse(res) { - if (res.data.erro !== 0) return + if (res.data.erro !== 0) { + wx.showToast({ + title: '获取数据失败', + icon: 'none' + }) + return + } const { lists, currentPage } = res.data - this.setData({ - news: currentPage === 1 ? lists : this.data.news.concat(lists), - pageNum: currentPage + 1 - }) + if (lists && lists.length > 0) { + this.setData({ + news: currentPage === 1 ? lists : this.data.news.concat(lists), + pageNum: currentPage + 1 + }) + } }, // 资讯项点击 @@ -172,14 +186,21 @@ Page({ * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { - + // 下拉刷新时重置页码并重新获取数据 + this.setData({ + pageNum: 1, + news: [] + }, () => { + this.getOrderList() + }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { - + // 上拉加载更多数据 + this.getOrderList() }, /** * 用户点击右上角分享 diff --git a/pages/home/home.json b/pages/home/home.json index 8835af0..09e623a 100644 --- a/pages/home/home.json +++ b/pages/home/home.json @@ -1,3 +1,5 @@ { - "usingComponents": {} + "usingComponents": {}, + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark" } \ No newline at end of file diff --git a/pages/tool/tool.js b/pages/tool/tool.js index 9c3291f..7e6554b 100644 --- a/pages/tool/tool.js +++ b/pages/tool/tool.js @@ -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 }) } }) \ No newline at end of file diff --git a/pages/tool/tool.wxml b/pages/tool/tool.wxml index 1e0f9f0..36831c8 100644 --- a/pages/tool/tool.wxml +++ b/pages/tool/tool.wxml @@ -22,39 +22,102 @@ 姓名: - + 年龄: - + 身高(cm): - + 骨龄: - + 父亲身高(cm): - + 母亲身高(cm): - + IGF-1:(ng/ml) - + LH基础(mIU/ml): - + 子宫厚度(mm): - +