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:
co-authored by
Claude Opus 4.7
parent
cb626c7c88
commit
c3b031aed4
@@ -112,6 +112,8 @@ Page({
|
||||
employeeQueried: false,
|
||||
/** 员工编号查询是否未找到 */
|
||||
employeeNotFound: false,
|
||||
/** 部门展示文案 */
|
||||
unitDisplay: '',
|
||||
},
|
||||
|
||||
/** tabs 切换:清空查询结果、重置表单 */
|
||||
@@ -121,6 +123,7 @@ Page({
|
||||
userType: tab as 'employee' | 'family',
|
||||
employeeQueried: false,
|
||||
employeeNotFound: false,
|
||||
unitDisplay: '',
|
||||
readonly: false,
|
||||
hasQueried: false,
|
||||
serverResult: null,
|
||||
@@ -143,6 +146,7 @@ Page({
|
||||
'form.workNo': e.detail.value,
|
||||
employeeQueried: false,
|
||||
employeeNotFound: false,
|
||||
unitDisplay: '',
|
||||
'form.name': '',
|
||||
'form.gender': '',
|
||||
'form.age': '',
|
||||
@@ -151,15 +155,63 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/** 员工编号查询(API 预留) */
|
||||
/** 员工编号查询 */
|
||||
onQueryEmployee() {
|
||||
const workNo = this.data.form.workNo.trim()
|
||||
if (!workNo) {
|
||||
wx.showToast({ title: '请填写员工编号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// TODO: 接入员工编号查询接口
|
||||
wx.showToast({ title: '查询功能暂未开放', icon: 'none' })
|
||||
if (this.data.querying) return
|
||||
|
||||
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) {
|
||||
@@ -408,7 +460,7 @@ Page({
|
||||
const serverResult = this.data.serverResult
|
||||
|
||||
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 payload: Record<string, any> = {
|
||||
@@ -427,7 +479,7 @@ Page({
|
||||
connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : '',
|
||||
}
|
||||
|
||||
put('weighingScale/v3/edit/user', payload)
|
||||
put('weighingScale/v5/edit/user', payload)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '添加成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<view class="form-row">
|
||||
<view class="form-label"><text class="label-text">单位</text></view>
|
||||
<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>
|
||||
|
||||
@@ -22,7 +22,7 @@ Page({
|
||||
/** dataType === 1 为家庭用户 */
|
||||
isFamily: false,
|
||||
/** 单位(非家庭用户) */
|
||||
workNo: '',
|
||||
unitDisplay: '',
|
||||
/** 出生年月 YYYY-MM-DD(家庭用户) */
|
||||
birthday: '',
|
||||
/** 接口返回的原始用户数据,提交时以此为 base 覆盖修改字段 */
|
||||
@@ -59,7 +59,7 @@ Page({
|
||||
this.setData({
|
||||
rawUser: u,
|
||||
isFamily,
|
||||
workNo: u.workNo ?? '',
|
||||
unitDisplay: [u.secondDepart, u.thirdDepart].filter(Boolean).join(' / '),
|
||||
birthday: u.birthday ?? '',
|
||||
'form.name': u.realname ?? '',
|
||||
'form.idCard': u.idCard ?? '',
|
||||
@@ -163,14 +163,14 @@ Page({
|
||||
id: this.data.userId,
|
||||
realname: name.trim(),
|
||||
idCard,
|
||||
sex: this.data.form.sex,
|
||||
sex,
|
||||
birthday: this.data.birthday,
|
||||
height: heightNum,
|
||||
weight: isNaN(weightNum) ? 0 : weightNum,
|
||||
connectDeviceInfo: connectDeviceInfoRaw ? JSON.stringify(connectDeviceInfoRaw) : (rawUser?.connectDeviceInfo ?? ''),
|
||||
}
|
||||
|
||||
put('weighingScale/v3/edit/user', payload)
|
||||
put('weighingScale/v5/edit/user', payload)
|
||||
.then(() => {
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</view>
|
||||
<view class="form-control">
|
||||
<view class="form-readonly">
|
||||
<text class="readonly-text">{{ workNo }}</text>
|
||||
<text class="readonly-text">{{ unitDisplay }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user