fix(addUser): 家庭用户身份证查询报错时提交前重新查询并重置状态
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
4e51432b8a
commit
55cdeae1ba
@@ -54,6 +54,7 @@ Page({
|
|||||||
employeeQueryResult: null as Record<string, any> | null,
|
employeeQueryResult: null as Record<string, any> | null,
|
||||||
rawUser: null as Record<string, any> | null,
|
rawUser: null as Record<string, any> | null,
|
||||||
isEdit: false,
|
isEdit: false,
|
||||||
|
queryError: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(options: Record<string, string>) {
|
onLoad(options: Record<string, string>) {
|
||||||
@@ -121,6 +122,7 @@ Page({
|
|||||||
serverResult: null,
|
serverResult: null,
|
||||||
form: { workNo: '', name: '', idCard: '', gender: '', age: '', height: '', weight: '', sex: 0 },
|
form: { workNo: '', name: '', idCard: '', gender: '', age: '', height: '', weight: '', sex: 0 },
|
||||||
birthday: '',
|
birthday: '',
|
||||||
|
queryError: false,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -200,6 +202,7 @@ Page({
|
|||||||
'form.weight': '',
|
'form.weight': '',
|
||||||
birthday: '',
|
birthday: '',
|
||||||
readonly: false,
|
readonly: false,
|
||||||
|
queryError: false,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -222,6 +225,7 @@ Page({
|
|||||||
'form.weight': '',
|
'form.weight': '',
|
||||||
birthday: '',
|
birthday: '',
|
||||||
readonly: false,
|
readonly: false,
|
||||||
|
queryError: false,
|
||||||
})
|
})
|
||||||
if (idCard.length === 18) this.validateIdCard()
|
if (idCard.length === 18) this.validateIdCard()
|
||||||
},
|
},
|
||||||
@@ -241,9 +245,8 @@ Page({
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
const serverResult = res.result
|
const serverResult = res.result
|
||||||
const { gender, age, sex, birthday } = parseIdCard(serverResult?.idCard || this.data.form.idCard)
|
const { gender, age, sex, birthday } = parseIdCard(serverResult?.idCard || this.data.form.idCard)
|
||||||
this.setData({ 'form.gender': gender, 'form.age': age, 'form.sex': sex, birthday })
|
this.setData({ 'form.gender': gender, 'form.age': age, 'form.sex': sex, birthday, queryError: false })
|
||||||
if (!serverResult) {
|
if (!serverResult) {
|
||||||
wx.showToast({ title: res.msg || '未查询到用户信息', icon: 'none' })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (serverResult.flag === 101) {
|
if (serverResult.flag === 101) {
|
||||||
@@ -266,7 +269,11 @@ Page({
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}).catch(() => {})
|
}).catch(() => {
|
||||||
|
// 查询报错:仍按身份证解析性别/年龄,标记需重新查询
|
||||||
|
const { gender, age, sex, birthday } = parseIdCard(this.data.form.idCard)
|
||||||
|
this.setData({ 'form.gender': gender, 'form.age': age, 'form.sex': sex, birthday, queryError: true })
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 家庭用户:性别切换 */
|
/** 家庭用户:性别切换 */
|
||||||
@@ -302,6 +309,7 @@ Page({
|
|||||||
serverResult: null,
|
serverResult: null,
|
||||||
form: { workNo: '', name: '', idCard: '', gender: '', age: '', height: '', weight: '', sex: 0 },
|
form: { workNo: '', name: '', idCard: '', gender: '', age: '', height: '', weight: '', sex: 0 },
|
||||||
birthday: '',
|
birthday: '',
|
||||||
|
queryError: false,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -310,7 +318,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/** 提交用户 */
|
/** 提交用户 */
|
||||||
onSubmit() {
|
async onSubmit() {
|
||||||
const { name, idCard, gender, height, weight, sex } = this.data.form
|
const { name, idCard, gender, height, weight, sex } = this.data.form
|
||||||
const { userType } = this.data
|
const { userType } = this.data
|
||||||
const heightNum = parseFloat(height)
|
const heightNum = parseFloat(height)
|
||||||
@@ -344,6 +352,31 @@ Page({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 家庭用户新增:身份证查询报错 → 重新查询,成功后再提交
|
||||||
|
let sexFinal = sex
|
||||||
|
let birthdayFinal = this.data.birthday
|
||||||
|
if (userType === 'family' && !editId && this.data.queryError) {
|
||||||
|
try {
|
||||||
|
const res = await getUserInfoByIdCard({ sn: targetSn, idCard, realname: name.trim() })
|
||||||
|
const result = res.result
|
||||||
|
const parsed = parseIdCard(result?.idCard || idCard)
|
||||||
|
this.setData({
|
||||||
|
serverResult: result,
|
||||||
|
'form.gender': parsed.gender,
|
||||||
|
'form.age': parsed.age,
|
||||||
|
'form.sex': parsed.sex,
|
||||||
|
birthday: parsed.birthday,
|
||||||
|
queryError: false,
|
||||||
|
})
|
||||||
|
sexFinal = parsed.sex
|
||||||
|
birthdayFinal = parsed.birthday
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('[addUser] 重新查询失败:', err)
|
||||||
|
wx.showToast({ title: err?.msg || err?.message || '查询失败,请重试', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const userInfo = wx.getStorageSync('userInfo') as Record<string, any> | null
|
const userInfo = wx.getStorageSync('userInfo') as Record<string, any> | null
|
||||||
// 编辑:以详情接口返回为 base;新增:员工用查询结果、家庭用身份证查询结果
|
// 编辑:以详情接口返回为 base;新增:员工用查询结果、家庭用身份证查询结果
|
||||||
const baseSpread = editId
|
const baseSpread = editId
|
||||||
@@ -360,8 +393,8 @@ Page({
|
|||||||
scaleDeviceId: targetSn,
|
scaleDeviceId: targetSn,
|
||||||
realname: name.trim(),
|
realname: name.trim(),
|
||||||
idCard: idCard || null,
|
idCard: idCard || null,
|
||||||
sex,
|
sex: sexFinal,
|
||||||
birthday: this.data.birthday,
|
birthday: birthdayFinal,
|
||||||
height: heightNum,
|
height: heightNum,
|
||||||
weight: isNaN(weightNum) ? 0 : weightNum,
|
weight: isNaN(weightNum) ? 0 : weightNum,
|
||||||
mode: getApp<IAppOption>().globalData.operationsEngineer ? 'ops' : 'normal',
|
mode: getApp<IAppOption>().globalData.operationsEngineer ? 'ops' : 'normal',
|
||||||
|
|||||||
Reference in New Issue
Block a user