diff --git a/miniprogram/pages/addUser/addUser.ts b/miniprogram/pages/addUser/addUser.ts index 1a3b2d2..3055bb1 100644 --- a/miniprogram/pages/addUser/addUser.ts +++ b/miniprogram/pages/addUser/addUser.ts @@ -55,13 +55,16 @@ Page({ rawUser: null as Record | null, isEdit: false, queryError: false, + today: '', }, onLoad(options: Record) { targetSn = decodeURIComponent(options.sn || '') console.log(targetSn); editId = decodeURIComponent(options.id || '') - this.setData({ isEdit: !!editId }) + const now = new Date() + const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}` + this.setData({ isEdit: !!editId, today }) if (editId) { this._loadEditUser(editId) } @@ -295,6 +298,28 @@ Page({ this.setData({ 'form.weight': e.detail.value }) }, + /** 身高失焦校验:不在 50-250 则清空 */ + onHeightBlur() { + const height = this.data.form.height.trim() + if (!height) return + const h = parseFloat(height) + if (isNaN(h) || h < 50 || h > 250) { + wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' }) + this.setData({ 'form.height': '' }) + } + }, + + /** 体重失焦校验:不在 20-300 则清空 */ + onWeightBlur() { + const weight = this.data.form.weight.trim() + if (!weight) return + const w = parseFloat(weight) + if (isNaN(w) || w < 20 || w > 300) { + wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' }) + this.setData({ 'form.weight': '' }) + } + }, + /** 复用已有信息:关弹框直接提交 */ onConfirmModalConfirm() { this.setData({ showConfirmModal: false }) @@ -329,10 +354,6 @@ Page({ wx.showToast({ title: '请先查询员工信息', icon: 'none' }) return } - if (!height || isNaN(heightNum) || heightNum <= 0) { - wx.showToast({ title: '请填写身高', icon: 'none' }) - return - } } else { if (!name.trim()) { wx.showToast({ title: '请填写昵称', icon: 'none' }) @@ -346,10 +367,16 @@ Page({ wx.showToast({ title: '请填写出生年月', icon: 'none' }) return } - if (!height || isNaN(heightNum) || heightNum <= 0) { - wx.showToast({ title: '请填写身高', icon: 'none' }) - return - } + } + + // 身高体重范围校验(员工/家庭用户共用) + if (!height || isNaN(heightNum) || heightNum < 50 || heightNum > 250) { + wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' }) + return + } + if (weight && (isNaN(weightNum) || weightNum < 20 || weightNum > 300)) { + wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' }) + return } // 家庭用户新增:身份证查询报错 → 重新查询,成功后再提交 diff --git a/miniprogram/pages/addUser/addUser.wxml b/miniprogram/pages/addUser/addUser.wxml index 208e877..0e45f4c 100644 --- a/miniprogram/pages/addUser/addUser.wxml +++ b/miniprogram/pages/addUser/addUser.wxml @@ -78,7 +78,7 @@ - + cm @@ -87,7 +87,7 @@ 体重 - + kg @@ -142,7 +142,7 @@ * - + {{ birthday || '请选择出生年月' }} @@ -157,7 +157,7 @@ - + cm @@ -166,7 +166,7 @@ 体重 - + kg