From 7a662d7c342fd2bd88a62bbf36e5df9c4ecfc575 Mon Sep 17 00:00:00 2001
From: 17792275749 <812100002@qq.com>
Date: Wed, 8 Apr 2026 09:26:39 +0800
Subject: [PATCH] =?UTF-8?q?[AI=20Generated]:=20feat(Comp):=20=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E5=BC=B9=E7=AA=97?=
=?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7=E7=B1=BB=E5=9E=8B=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E5=91=98=E5=B7=A5?=
=?UTF-8?q?=E6=A8=A1=E5=BC=8F=EF=BC=88=E5=B7=A5=E5=8F=B7=E6=9F=A5=E8=AF=A2?=
=?UTF-8?q?=EF=BC=89=E4=B8=8E=E5=AE=B6=E5=BA=AD=E7=94=A8=E6=88=B7=E6=A8=A1?=
=?UTF-8?q?=E5=BC=8F=EF=BC=88=E6=89=8B=E5=8A=A8=E5=A1=AB=E5=86=99=EF=BC=89?=
=?UTF-8?q?=EF=BC=8C=E5=88=87=E6=8D=A2=E6=97=B6=E8=87=AA=E5=8A=A8=E6=B8=85?=
=?UTF-8?q?=E7=A9=BA=E5=B7=B2=E5=A1=AB=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../configureDevice_2_addUser.js | 179 +++++++++++++----
.../configureDevice_2_addUser.wxml | 186 +++++++++++++-----
2 files changed, 274 insertions(+), 91 deletions(-)
diff --git a/components/configureDevice_2_addUser/configureDevice_2_addUser.js b/components/configureDevice_2_addUser/configureDevice_2_addUser.js
index 51b8bbd..61f3a8e 100644
--- a/components/configureDevice_2_addUser/configureDevice_2_addUser.js
+++ b/components/configureDevice_2_addUser/configureDevice_2_addUser.js
@@ -8,8 +8,22 @@ Component({
data: {
animationData: null,
modalStatus: false,
+ // 用户类型:employee=员工,family=家庭用户
+ userType: 'employee',
+ // 员工模式
workNo: "",
userInfo: null,
+ // 家庭用户模式 - 手动填写
+ familyInfo: {
+ name: '',
+ sex: 1,
+ birthday: '',
+ height: '',
+ weight: ''
+ },
+ // 性别选择器选项
+ genderOptions: ['男', '女'],
+ genderIndex: 0,
},
lifetimes: {
// 在组件实例进入页面节点树时执行
@@ -32,7 +46,7 @@ Component({
delay: 0
})
this.animation = animation;
- animation.translateY(1100).step();
+ animation.translateY(1200).step();
this.setData({
animationData: animation.export(),
modalStatus: true
@@ -54,7 +68,7 @@ Component({
delay: 0
})
this.animation = animation;
- animation.translateY(1100).step();
+ animation.translateY(1200).step();
this.setData({
animationData: animation.export(),
})
@@ -67,16 +81,44 @@ Component({
}, 200);
},
- // 关闭弹窗并重置数据
+ // 关闭弹窗并重置所有数据
closeModal() {
this.setData({
+ userType: 'employee',
workNo: "",
userInfo: null,
+ familyInfo: {
+ name: '',
+ sex: 1,
+ birthday: '',
+ height: '',
+ weight: ''
+ },
+ genderIndex: 0,
});
this.hideModal();
},
- // 监听工号输入
+ // 切换用户类型,同时清空所有已填数据
+ switchUserType(e) {
+ const type = e.currentTarget.dataset.type;
+ if (type === this.data.userType) return;
+ this.setData({
+ userType: type,
+ workNo: "",
+ userInfo: null,
+ familyInfo: {
+ name: '',
+ sex: 1,
+ birthday: '',
+ height: '',
+ weight: ''
+ },
+ genderIndex: 0,
+ });
+ },
+
+ // 监听工号输入(员工模式)
onWorkNoInput(e) {
this.setData({
workNo: e.detail.value,
@@ -84,17 +126,47 @@ Component({
});
},
- // 监听身高输入
+ // 监听身高输入(员工模式)
onHeightInput(e) {
this.setData({ 'userInfo.height': e.detail.value });
},
- // 监听体重输入
+ // 监听体重输入(员工模式)
onWeightInput(e) {
this.setData({ 'userInfo.weight': e.detail.value });
},
- // 根据工号查询用户信息
+ // 监听家庭用户姓名输入
+ onFamilyNameInput(e) {
+ this.setData({ 'familyInfo.name': e.detail.value });
+ },
+
+ // 监听家庭用户性别选择
+ onFamilyGenderChange(e) {
+ const index = e.detail.value;
+ // 1=男,2=女
+ this.setData({
+ genderIndex: index,
+ 'familyInfo.sex': index === '0' || index === 0 ? 1 : 2
+ });
+ },
+
+ // 监听家庭用户生日选择
+ onFamilyBirthdayChange(e) {
+ this.setData({ 'familyInfo.birthday': e.detail.value });
+ },
+
+ // 监听家庭用户身高输入
+ onFamilyHeightInput(e) {
+ this.setData({ 'familyInfo.height': e.detail.value });
+ },
+
+ // 监听家庭用户体重输入
+ onFamilyWeightInput(e) {
+ this.setData({ 'familyInfo.weight': e.detail.value });
+ },
+
+ // 根据工号查询用户信息(员工模式)
searchUser() {
let workNo = this.data.workNo.trim();
if (!workNo) {
@@ -130,38 +202,67 @@ Component({
// 确定提交
submit() {
- if (!this.data.userInfo) {
- wx.showToast({
- title: "请先查询用户信息",
- icon: "none"
- })
- return;
+ const sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
+
+ if (this.data.userType === 'employee') {
+ // 员工模式:必须先查询到用户信息
+ if (!this.data.userInfo) {
+ wx.showToast({ title: "请先查询用户信息", icon: "none" });
+ return;
+ }
+ let userInfo = this.data.userInfo;
+ if (!userInfo.height) {
+ wx.showToast({ title: "请输入身高", icon: "none" });
+ return;
+ }
+ if (!userInfo.weight) {
+ wx.showToast({ title: "请输入体重", icon: "none" });
+ return;
+ }
+ userInfo.sn = sn;
+ $.ajax("weighingScale/v2/edit/user", userInfo, "POST", true, "正在添加...").then(res => {
+ wx.showToast({ title: "添加成功", icon: "success" });
+ this.triggerEvent('returnDate', { userInfo });
+ this.closeModal();
+ }).catch(() => {
+ wx.showToast({ title: "添加失败,请重试", icon: "none" });
+ });
+
+ } else {
+ // 家庭用户模式:校验手动填写的字段
+ const familyInfo = this.data.familyInfo;
+ if (!familyInfo.name.trim()) {
+ wx.showToast({ title: "请输入姓名", icon: "none" });
+ return;
+ }
+ if (!familyInfo.birthday) {
+ wx.showToast({ title: "请选择生日", icon: "none" });
+ return;
+ }
+ if (!familyInfo.height) {
+ wx.showToast({ title: "请输入身高", icon: "none" });
+ return;
+ }
+ if (!familyInfo.weight) {
+ wx.showToast({ title: "请输入体重", icon: "none" });
+ return;
+ }
+ const submitData = {
+ realname: familyInfo.name.trim(),
+ sex: familyInfo.sex,
+ birthday: familyInfo.birthday,
+ height: familyInfo.height,
+ weight: familyInfo.weight,
+ sn: sn
+ };
+ $.ajax("weighingScale/v2/edit/user", submitData, "POST", true, "正在添加...").then(res => {
+ wx.showToast({ title: "添加成功", icon: "success" });
+ this.triggerEvent('returnDate', { userInfo: submitData });
+ this.closeModal();
+ }).catch(() => {
+ wx.showToast({ title: "添加失败,请重试", icon: "none" });
+ });
}
- let userInfo = this.data.userInfo;
- // 校验身高
- if (!userInfo.height) {
- wx.showToast({ title: "请输入身高", icon: "none" });
- return;
- }
- // 校验体重
- if (!userInfo.weight) {
- wx.showToast({ title: "请输入体重", icon: "none" });
- return;
- }
- userInfo.sn = app.globalData.ppScale.device.mac.replace(/:/g, '')
- $.ajax("weighingScale/v2/edit/user", userInfo, "POST", true, "正在添加...").then(res => {
- wx.showToast({
- title: "添加成功",
- icon: "success"
- })
- this.triggerEvent('returnDate', { userInfo });
- this.closeModal();
- }).catch(() => {
- wx.showToast({
- title: "添加失败,请重试",
- icon: "none"
- })
- })
}
}
-});
\ No newline at end of file
+});
diff --git a/components/configureDevice_2_addUser/configureDevice_2_addUser.wxml b/components/configureDevice_2_addUser/configureDevice_2_addUser.wxml
index 8dfe659..8070a09 100644
--- a/components/configureDevice_2_addUser/configureDevice_2_addUser.wxml
+++ b/components/configureDevice_2_addUser/configureDevice_2_addUser.wxml
@@ -8,76 +8,158 @@
添加用户
-
- 工号:
-
-
-
-
+
+
+ 员工
+ 家庭用户
-
- 姓名:
-
+
+
+
+
+
+ 工号:
-
- {{userInfo.realname || ''}}
-
-
- 请先输入工号
-
+
-
-
-
- 性别:
-
+
+
+ 姓名:
-
- {{userInfo.sex === 1 ? '男' : userInfo.sex === 2 ? '女' : ''}}
-
-
- 请先输入工号
-
+
+
+ {{userInfo.realname || ''}}
+
+
+ 请先输入工号
+
+
+
-
-
-
- 生日:
-
+
+
+ 性别:
-
- {{userInfo.birthday || ''}}
-
-
- 请先输入工号
-
+
+
+ {{userInfo.sex === 1 ? '男' : userInfo.sex === 2 ? '女' : ''}}
+
+
+ 请先输入工号
+
+
+
-
-
-
- 身高:
-
+
+
+ 生日:
-
+
+
+ {{userInfo.birthday || ''}}
+
+
+ 请先输入工号
+
+
+
- cm
-
-
- 体重:
-
+
+
+ 身高:
-
+
+
+
+ cm
- kg
-
+
+
+ 体重:
+
+
+
+
+ kg
+
+
+
+
+
+
+
+
+ 姓名:
+
+
+
+
+
+
+ 性别:
+
+
+
+
+ {{genderOptions[genderIndex]}}
+
+
+
+
+
+
+
+
+ 生日:
+
+
+
+
+ {{familyInfo.birthday || '请选择生日'}}
+
+
+
+
+
+
+
+
+ 身高:
+
+
+
+
+ cm
+
+
+
+
+ 体重:
+
+
+
+
+ kg
+
+
+
+
-
\ No newline at end of file
+