fix(supplementPersonal): 查询报错时提交前重新查询直到成功
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
00394bf8c4
commit
8f5ccdd7e3
@@ -18,6 +18,8 @@ Page({
|
||||
readonly: false,
|
||||
/** 是否展示「复用信息」确认弹框 */
|
||||
showConfirmModal: false,
|
||||
/** 查询接口是否报错(报错时提交前需重新查询) */
|
||||
queryError: false,
|
||||
},
|
||||
|
||||
/** 姓名/身份证变动后,查询回填的信息失效,统一清空 */
|
||||
@@ -31,6 +33,7 @@ Page({
|
||||
height: '',
|
||||
weight: '',
|
||||
readonly: false,
|
||||
queryError: false,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -66,9 +69,9 @@ Page({
|
||||
const serverResult = res.result
|
||||
// 优先按服务器返回的身份证解析,未查到则回退用户输入
|
||||
const { gender, age, sex, birthday } = parseIdCard(serverResult?.idCard || this.data.idCard)
|
||||
this.setData({ gender, age, sex, birthday })
|
||||
this.setData({ gender, age, sex, birthday, queryError: false })
|
||||
if (!serverResult) {
|
||||
wx.showToast({ title: res.msg || '未查询到用户信息', icon: 'none' })
|
||||
// wx.showToast({ title: res.msg || '未查询到用户信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// flag=101:身份证已存在,弹框确认是否复用
|
||||
@@ -93,7 +96,11 @@ Page({
|
||||
})
|
||||
return
|
||||
}
|
||||
}).catch(() => {})
|
||||
}).catch(() => {
|
||||
// 查询报错:仍按身份证解析性别/年龄,标记需重新查询
|
||||
const { gender, age, sex, birthday } = parseIdCard(this.data.idCard)
|
||||
this.setData({ gender, age, sex, birthday, queryError: true })
|
||||
})
|
||||
},
|
||||
|
||||
// 复用已有信息:关闭弹框直接提交
|
||||
@@ -116,8 +123,8 @@ Page({
|
||||
this.setData({ weight: e.detail.value })
|
||||
},
|
||||
|
||||
onSubmit() {
|
||||
const { name, idCard, gender, sex, birthday, height, weight, serverResult } = this.data
|
||||
async onSubmit() {
|
||||
const { name, idCard, height, weight } = this.data
|
||||
const heightNum = parseFloat(height)
|
||||
const weightNum = parseFloat(weight)
|
||||
|
||||
@@ -125,7 +132,7 @@ Page({
|
||||
wx.showToast({ title: '请填写姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!gender) {
|
||||
if (!this.data.gender || !this.data.age || !this.data.birthday) {
|
||||
wx.showToast({ title: '请填写正确的身份证号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@@ -133,13 +140,28 @@ Page({
|
||||
wx.showToast({ title: '请填写身高', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!serverResult) {
|
||||
wx.showToast({ title: '请先验证姓名与身份证号', icon: 'none' })
|
||||
return
|
||||
|
||||
let sex = this.data.sex
|
||||
let birthday = this.data.birthday
|
||||
|
||||
// 查询接口报错 → 重新查询,成功后再提交
|
||||
if (this.data.queryError) {
|
||||
try {
|
||||
const res = await getUserInfoByIdCard({ idCard, realname: name })
|
||||
const result = res.result
|
||||
const parsed = parseIdCard(result?.idCard || idCard)
|
||||
this.setData({ serverResult: result, ...parsed, queryError: false })
|
||||
sex = parsed.sex
|
||||
birthday = parsed.birthday
|
||||
} catch (err: any) {
|
||||
console.error('[supplementPersonal] 重新查询失败:', err)
|
||||
wx.showToast({ title: err?.msg || err?.message || '查询失败,请重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
updateUser({
|
||||
...serverResult,
|
||||
...(this.data.serverResult || {}),
|
||||
idCard,
|
||||
realname: name,
|
||||
height: heightNum,
|
||||
|
||||
Reference in New Issue
Block a user