feat(supplementPersonal): 身高体重范围校验并失焦清空
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
1dfda24645
commit
e0f201f15c
@@ -123,6 +123,28 @@ Page({
|
|||||||
this.setData({ weight: e.detail.value })
|
this.setData({ weight: e.detail.value })
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** 身高失焦校验:不在 50-250 则清空 */
|
||||||
|
onHeightBlur() {
|
||||||
|
const height = this.data.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({ height: '' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 体重失焦校验:不在 20-300 则清空 */
|
||||||
|
onWeightBlur() {
|
||||||
|
const weight = this.data.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({ weight: '' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async onSubmit() {
|
async onSubmit() {
|
||||||
const { name, idCard, height, weight } = this.data
|
const { name, idCard, height, weight } = this.data
|
||||||
const heightNum = parseFloat(height)
|
const heightNum = parseFloat(height)
|
||||||
@@ -136,8 +158,12 @@ Page({
|
|||||||
wx.showToast({ title: '请填写正确的身份证号', icon: 'none' })
|
wx.showToast({ title: '请填写正确的身份证号', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!height || isNaN(heightNum) || heightNum <= 0) {
|
if (!height || isNaN(heightNum) || heightNum < 50 || heightNum > 250) {
|
||||||
wx.showToast({ title: '请填写身高', icon: 'none' })
|
wx.showToast({ title: '身高需在50-250cm之间', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (weight && (isNaN(weightNum) || weightNum < 20 || weightNum > 300)) {
|
||||||
|
wx.showToast({ title: '体重需在20-300kg之间', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,8 @@
|
|||||||
placeholder-class="form-placeholder"
|
placeholder-class="form-placeholder"
|
||||||
value="{{ height }}"
|
value="{{ height }}"
|
||||||
disabled="{{ readonly }}"
|
disabled="{{ readonly }}"
|
||||||
bind:input="onHeightInput" />
|
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>
|
||||||
@@ -99,7 +100,8 @@
|
|||||||
placeholder-class="form-placeholder"
|
placeholder-class="form-placeholder"
|
||||||
value="{{ weight }}"
|
value="{{ weight }}"
|
||||||
disabled="{{ readonly }}"
|
disabled="{{ readonly }}"
|
||||||
bind:input="onWeightInput" />
|
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