diff --git a/miniprogram/pages/addMember/addMember.ts b/miniprogram/pages/addMember/addMember.ts index cb5b27b..406179f 100644 --- a/miniprogram/pages/addMember/addMember.ts +++ b/miniprogram/pages/addMember/addMember.ts @@ -1,17 +1,6 @@ import { get, put } from '../../utils/request/index' import { lefuService } from '../../lefu/index' -/** GET /weighingScale/v3/selectUserBySn/user 返回的单条结构(编辑回填用) */ -interface SysUserDevice { - id: string - realname: string - idCard: string - height: number - weight: number - sex: number - birthday: string -} - /** GET /weighingScale/v3/getUserInfoByIdcard 返回的 result 结构 */ interface UserInfoFromServer { id: string | null @@ -90,10 +79,6 @@ Page({ data: { /** tabs 当前选中:employee | family */ userType: 'employee' as 'employee' | 'family', - /** 编辑模式标记 */ - isEdit: false, - /** 编辑时的用户 ID */ - userId: '', form: { workNo: '', @@ -129,31 +114,7 @@ Page({ employeeNotFound: false, }, - onLoad(options: Record) { - const { userId } = options - if (!userId) return - this.setData({ isEdit: true, userId }) - get('weighingScale/v3/select/userinfo/byId', { id: userId }, { loading: false }) - .then((res: any) => { - const u: SysUserDevice = res.result - if (!u) return - const parsed = this.parseIdCard(u.idCard ?? '') - this.setData({ - 'form.workNo': u.workNo ?? '', - 'form.name': u.realname ?? '', - 'form.idCard': u.idCard ?? '', - 'form.gender': parsed.gender, - 'form.age': parsed.age, - 'form.height': String(u.height ?? ''), - 'form.weight': String(u.weight ?? ''), - }) - if ((u.realname ?? '').trim() && this.isIdCardValid(u.idCard ?? '')) { - this.fetchUserInfoByIdCard(u.realname.trim(), u.idCard) - } - }) - }, - - /** tabs 切换:清空查询结果、重置表单只读状态 */ + /** tabs 切换:清空查询结果、重置表单 */ onTabTap(e: WechatMiniprogram.TouchEvent) { const tab = e.currentTarget.dataset.value as string this.setData({ @@ -268,16 +229,10 @@ Page({ return Math.max(0, age) }, - /** - * 校验身份证格式:18 位,前 17 位数字,末位数字或 X - */ isIdCardValid(idCard: string): boolean { return /^\d{17}[\dX]$/.test(idCard) }, - /** - * 解析身份证,返回性别、年龄、sex 数值、出生日期 - */ parseIdCard(idCard: string): IdCardParsed { const empty: IdCardParsed = { gender: '', age: '', sex: 0, birthday: '' } if (!this.isIdCardValid(idCard)) return empty @@ -301,9 +256,6 @@ Page({ return { gender, age: String(age), sex, birthday: `${year}-${mm}-${dd}` } }, - /** - * 调用服务端接口校验身份证与姓名 - */ fetchUserInfoByIdCard(name: string, idCard: string) { if (this.data.querying) return this.setData({ querying: true, serverResult: null, hasQueried: false }) @@ -316,10 +268,7 @@ Page({ .then(res => { const serverResult = res.result if (!serverResult) { - wx.showToast({ - title: res.message || '未查询到用户信息', - icon: 'none' - }) + wx.showToast({ title: res.message || '未查询到用户信息', icon: 'none' }) const parsed = this.parseIdCard(idCard) this.setData({ hasQueried: true, @@ -361,9 +310,7 @@ Page({ this.setData(data) } }) - .catch(() => { - // 查询失败保留本地解析结果,hasQueried 维持 false - }) + .catch(() => {}) .finally(() => { this.setData({ querying: false }) }) @@ -396,13 +343,11 @@ Page({ } }, - /** 确认弹框 - 确认 */ onConfirmModalConfirm() { this.setData({ showConfirmModal: false }) this.onSubmit() }, - /** 确认弹框 - 取消 */ onConfirmModalCancel() { this.setData({ showConfirmModal: false, @@ -426,12 +371,11 @@ Page({ onSubmit() { const { name, idCard, gender, height, weight, sex } = this.data.form - const { isEdit, userType } = this.data + const { userType } = this.data const heightNum = parseFloat(height) const weightNum = parseFloat(weight) if (userType === 'employee') { - // 员工:必须查询成功 if (!this.data.employeeQueried || this.data.employeeNotFound) { wx.showToast({ title: '请先查询员工信息', icon: 'none' }) return @@ -441,7 +385,6 @@ Page({ return } } else { - // 家庭用户 if (!name.trim()) { wx.showToast({ title: '请填写昵称', icon: 'none' }) return @@ -483,16 +426,10 @@ Page({ weight: isNaN(weightNum) ? 0 : weightNum, connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : '', } - if (isEdit) { - payload.id = this.data.userId - } - - const successMsg = isEdit ? '保存成功' : '添加成功' - const failMsg = isEdit ? '保存失败,请重试' : '添加失败,请重试' put('weighingScale/v3/edit/user', payload) .then(() => { - wx.showToast({ title: successMsg, icon: 'success' }) + wx.showToast({ title: '添加成功', icon: 'success' }) setTimeout(() => { const pages = getCurrentPages() const prevPage = pages[pages.length - 2] as any @@ -503,7 +440,7 @@ Page({ }, 1500) }) .catch(() => { - wx.showToast({ title: failMsg, icon: 'none' }) + wx.showToast({ title: '添加失败,请重试', icon: 'none' }) }) } }) diff --git a/miniprogram/pages/addMember/addMember.wxml b/miniprogram/pages/addMember/addMember.wxml index f9791bf..c32cf6a 100644 --- a/miniprogram/pages/addMember/addMember.wxml +++ b/miniprogram/pages/addMember/addMember.wxml @@ -182,7 +182,7 @@ - 从已有用户中选择 + 从已有用户中选择