feat(addUser): 生日不超今天、身高体重范围校验并失焦清空
- 出生年月 picker 限制到今天 - 身高 50-250cm、体重 20-300kg - 失焦时越界值清空并提示 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
55cdeae1ba
commit
1dfda24645
@@ -55,13 +55,16 @@ Page({
|
|||||||
rawUser: null as Record<string, any> | null,
|
rawUser: null as Record<string, any> | null,
|
||||||
isEdit: false,
|
isEdit: false,
|
||||||
queryError: false,
|
queryError: false,
|
||||||
|
today: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(options: Record<string, string>) {
|
onLoad(options: Record<string, string>) {
|
||||||
targetSn = decodeURIComponent(options.sn || '')
|
targetSn = decodeURIComponent(options.sn || '')
|
||||||
console.log(targetSn);
|
console.log(targetSn);
|
||||||
editId = decodeURIComponent(options.id || '')
|
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) {
|
if (editId) {
|
||||||
this._loadEditUser(editId)
|
this._loadEditUser(editId)
|
||||||
}
|
}
|
||||||
@@ -295,6 +298,28 @@ Page({
|
|||||||
this.setData({ 'form.weight': e.detail.value })
|
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() {
|
onConfirmModalConfirm() {
|
||||||
this.setData({ showConfirmModal: false })
|
this.setData({ showConfirmModal: false })
|
||||||
@@ -329,10 +354,6 @@ Page({
|
|||||||
wx.showToast({ title: '请先查询员工信息', icon: 'none' })
|
wx.showToast({ title: '请先查询员工信息', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!height || isNaN(heightNum) || heightNum <= 0) {
|
|
||||||
wx.showToast({ title: '请填写身高', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
wx.showToast({ title: '请填写昵称', icon: 'none' })
|
wx.showToast({ title: '请填写昵称', icon: 'none' })
|
||||||
@@ -346,10 +367,16 @@ Page({
|
|||||||
wx.showToast({ title: '请填写出生年月', icon: 'none' })
|
wx.showToast({ title: '请填写出生年月', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!height || isNaN(heightNum) || heightNum <= 0) {
|
}
|
||||||
wx.showToast({ title: '请填写身高', icon: 'none' })
|
|
||||||
|
// 身高体重范围校验(员工/家庭用户共用)
|
||||||
|
if (!height || isNaN(heightNum) || heightNum < 50 || heightNum > 250) {
|
||||||
|
wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (weight && (isNaN(weightNum) || weightNum < 20 || weightNum > 300)) {
|
||||||
|
wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 家庭用户新增:身份证查询报错 → 重新查询,成功后再提交
|
// 家庭用户新增:身份证查询报错 → 重新查询,成功后再提交
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="form-control">
|
<view class="form-control">
|
||||||
<view class="form-input-wrap">
|
<view class="form-input-wrap">
|
||||||
<input class="form-input form-input-with-suffix" type="digit" maxlength="5" placeholder="请填写身高" placeholder-class="form-placeholder" value="{{ form.height }}" bind:input="onHeightInput" />
|
<input class="form-input form-input-with-suffix" type="digit" maxlength="5" placeholder="请填写身高" placeholder-class="form-placeholder" value="{{ form.height }}" bind:input="onHeightInput" bind:blur="onHeightBlur" />
|
||||||
<text class="form-suffix form-suffix-inside">cm</text>
|
<text class="form-suffix form-suffix-inside">cm</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
<view class="form-label"><text class="label-text">体重</text></view>
|
<view class="form-label"><text class="label-text">体重</text></view>
|
||||||
<view class="form-control">
|
<view class="form-control">
|
||||||
<view class="form-input-wrap">
|
<view class="form-input-wrap">
|
||||||
<input class="form-input form-input-with-suffix" type="digit" maxlength="6" placeholder="请填写体重" placeholder-class="form-placeholder" value="{{ form.weight }}" bind:input="onWeightInput" />
|
<input class="form-input form-input-with-suffix" type="digit" maxlength="6" placeholder="请填写体重" placeholder-class="form-placeholder" value="{{ form.weight }}" bind:input="onWeightInput" bind:blur="onWeightBlur" />
|
||||||
<text class="form-suffix form-suffix-inside">kg</text>
|
<text class="form-suffix form-suffix-inside">kg</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
<text class="label-star">*</text>
|
<text class="label-star">*</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="form-control">
|
<view class="form-control">
|
||||||
<picker mode="date" value="{{ birthday }}" bindchange="onBirthdayChange">
|
<picker mode="date" value="{{ birthday }}" end="{{ today }}" bindchange="onBirthdayChange">
|
||||||
<view class="form-picker {{ birthday ? '' : 'form-picker-placeholder' }}">{{ birthday || '请选择出生年月' }}</view>
|
<view class="form-picker {{ birthday ? '' : 'form-picker-placeholder' }}">{{ birthday || '请选择出生年月' }}</view>
|
||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
@@ -157,7 +157,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="form-control">
|
<view class="form-control">
|
||||||
<view class="form-input-wrap">
|
<view class="form-input-wrap">
|
||||||
<input class="form-input form-input-with-suffix" type="digit" maxlength="5" placeholder="请填写身高" placeholder-class="form-placeholder" value="{{ form.height }}" bind:input="onHeightInput" />
|
<input class="form-input form-input-with-suffix" type="digit" maxlength="5" placeholder="请填写身高" placeholder-class="form-placeholder" value="{{ form.height }}" bind:input="onHeightInput" bind:blur="onHeightBlur" />
|
||||||
<text class="form-suffix form-suffix-inside">cm</text>
|
<text class="form-suffix form-suffix-inside">cm</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
<view class="form-label"><text class="label-text">体重</text></view>
|
<view class="form-label"><text class="label-text">体重</text></view>
|
||||||
<view class="form-control">
|
<view class="form-control">
|
||||||
<view class="form-input-wrap">
|
<view class="form-input-wrap">
|
||||||
<input class="form-input form-input-with-suffix" type="digit" maxlength="6" placeholder="请填写体重" placeholder-class="form-placeholder" value="{{ form.weight }}" bind:input="onWeightInput" />
|
<input class="form-input form-input-with-suffix" type="digit" maxlength="6" placeholder="请填写体重" placeholder-class="form-placeholder" value="{{ form.weight }}" bind:input="onWeightInput" bind:blur="onWeightBlur" />
|
||||||
<text class="form-suffix form-suffix-inside">kg</text>
|
<text class="form-suffix form-suffix-inside">kg</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
Reference in New Issue
Block a user