feat(addMember, editMember): 接入员工编号查询,部门展示改用secondDepart/thirdDepart

- onQueryEmployee 接入 GET /weighingScale/v5/getUserInfoByWkno
- 单位展示由 workNo 改为 secondDepart / thirdDepart 拼接
- birthday 员工查询时回填,提交统一取值
- edit/user 接口 v3 升级到 v5

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-06-11 17:57:35 +08:00
co-authored by Claude Opus 4.7
parent cb626c7c88
commit c3b031aed4
4 changed files with 63 additions and 11 deletions
+57 -5
View File
@@ -112,6 +112,8 @@ Page({
employeeQueried: false, employeeQueried: false,
/** 员工编号查询是否未找到 */ /** 员工编号查询是否未找到 */
employeeNotFound: false, employeeNotFound: false,
/** 部门展示文案 */
unitDisplay: '',
}, },
/** tabs 切换:清空查询结果、重置表单 */ /** tabs 切换:清空查询结果、重置表单 */
@@ -121,6 +123,7 @@ Page({
userType: tab as 'employee' | 'family', userType: tab as 'employee' | 'family',
employeeQueried: false, employeeQueried: false,
employeeNotFound: false, employeeNotFound: false,
unitDisplay: '',
readonly: false, readonly: false,
hasQueried: false, hasQueried: false,
serverResult: null, serverResult: null,
@@ -143,6 +146,7 @@ Page({
'form.workNo': e.detail.value, 'form.workNo': e.detail.value,
employeeQueried: false, employeeQueried: false,
employeeNotFound: false, employeeNotFound: false,
unitDisplay: '',
'form.name': '', 'form.name': '',
'form.gender': '', 'form.gender': '',
'form.age': '', 'form.age': '',
@@ -151,15 +155,63 @@ Page({
}) })
}, },
/** 员工编号查询API 预留) */ /** 员工编号查询 */
onQueryEmployee() { onQueryEmployee() {
const workNo = this.data.form.workNo.trim() const workNo = this.data.form.workNo.trim()
if (!workNo) { if (!workNo) {
wx.showToast({ title: '请填写员工编号', icon: 'none' }) wx.showToast({ title: '请填写员工编号', icon: 'none' })
return return
} }
// TODO: 接入员工编号查询接口 if (this.data.querying) return
wx.showToast({ title: '查询功能暂未开放', icon: 'none' })
this.setData({ querying: true, employeeQueried: false, employeeNotFound: false })
get<any>('weighingScale/v5/getUserInfoByWkno', {
sn: lefuService.deviceInfo?.serialNumber ?? '',
workNo
}, { loading: true })
.then(res => {
const result = res.result
if (!result) {
this.setData({
employeeQueried: true,
employeeNotFound: true,
unitDisplay: '',
'form.name': '',
'form.gender': '',
'form.age': '',
'form.height': '',
'form.weight': '',
})
return
}
const idCard = result.idCard || ''
const parsed = this.parseIdCard(idCard)
const sex = result.sex || parsed.sex
this.setData({
employeeQueried: true,
employeeNotFound: false,
unitDisplay: [result.secondDepart, result.thirdDepart].filter(Boolean).join(' / '),
'form.name': result.realname || '',
'form.idCard': idCard,
'form.gender': sex === 1 ? '男' : (sex === 2 ? '女' : parsed.gender),
'form.age': parsed.age,
'form.sex': sex,
'form.height': result.height ? String(result.height) : '',
'form.weight': result.weight ? String(result.weight) : '',
birthday: result.birthday || '',
})
})
.catch(() => {
this.setData({
employeeQueried: true,
employeeNotFound: true,
unitDisplay: '',
})
})
.finally(() => {
this.setData({ querying: false })
})
}, },
onNameInput(e: WechatMiniprogram.Input) { onNameInput(e: WechatMiniprogram.Input) {
@@ -408,7 +460,7 @@ Page({
const serverResult = this.data.serverResult const serverResult = this.data.serverResult
const baseSpread = userType === 'family' ? (this.data.selectedMember ?? {}) : {} const baseSpread = userType === 'family' ? (this.data.selectedMember ?? {}) : {}
const birthday = userType === 'family' ? this.data.birthday : '' const birthday = this.data.birthday
const finalSex = userType === 'family' ? sex : this.data.form.sex const finalSex = userType === 'family' ? sex : this.data.form.sex
const payload: Record<string, any> = { const payload: Record<string, any> = {
@@ -427,7 +479,7 @@ Page({
connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : '', connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : '',
} }
put('weighingScale/v3/edit/user', payload) put('weighingScale/v5/edit/user', payload)
.then(() => { .then(() => {
wx.showToast({ title: '添加成功', icon: 'success' }) wx.showToast({ title: '添加成功', icon: 'success' })
setTimeout(() => { setTimeout(() => {
+1 -1
View File
@@ -54,7 +54,7 @@
<view class="form-row"> <view class="form-row">
<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-readonly"><text class="readonly-text">{{ form.workNo }}</text></view> <view class="form-readonly"><text class="readonly-text">{{ unitDisplay }}</text></view>
</view> </view>
</view> </view>
</view> </view>
+4 -4
View File
@@ -22,7 +22,7 @@ Page({
/** dataType === 1 为家庭用户 */ /** dataType === 1 为家庭用户 */
isFamily: false, isFamily: false,
/** 单位(非家庭用户) */ /** 单位(非家庭用户) */
workNo: '', unitDisplay: '',
/** 出生年月 YYYY-MM-DD(家庭用户) */ /** 出生年月 YYYY-MM-DD(家庭用户) */
birthday: '', birthday: '',
/** 接口返回的原始用户数据,提交时以此为 base 覆盖修改字段 */ /** 接口返回的原始用户数据,提交时以此为 base 覆盖修改字段 */
@@ -59,7 +59,7 @@ Page({
this.setData({ this.setData({
rawUser: u, rawUser: u,
isFamily, isFamily,
workNo: u.workNo ?? '', unitDisplay: [u.secondDepart, u.thirdDepart].filter(Boolean).join(' / '),
birthday: u.birthday ?? '', birthday: u.birthday ?? '',
'form.name': u.realname ?? '', 'form.name': u.realname ?? '',
'form.idCard': u.idCard ?? '', 'form.idCard': u.idCard ?? '',
@@ -163,14 +163,14 @@ Page({
id: this.data.userId, id: this.data.userId,
realname: name.trim(), realname: name.trim(),
idCard, idCard,
sex: this.data.form.sex, sex,
birthday: this.data.birthday, birthday: this.data.birthday,
height: heightNum, height: heightNum,
weight: isNaN(weightNum) ? 0 : weightNum, weight: isNaN(weightNum) ? 0 : weightNum,
connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : (rawUser?.connectDeviceInfo ?? ''), connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : (rawUser?.connectDeviceInfo ?? ''),
} }
put('weighingScale/v3/edit/user', payload) put('weighingScale/v5/edit/user', payload)
.then(() => { .then(() => {
wx.showToast({ title: '保存成功', icon: 'success' }) wx.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => { setTimeout(() => {
+1 -1
View File
@@ -33,7 +33,7 @@
</view> </view>
<view class="form-control"> <view class="form-control">
<view class="form-readonly"> <view class="form-readonly">
<text class="readonly-text">{{ workNo }}</text> <text class="readonly-text">{{ unitDisplay }}</text>
</view> </view>
</view> </view>
</view> </view>