164 lines
4.7 KiB
JavaScript
164 lines
4.7 KiB
JavaScript
import $ from "../../utils/request";
|
|
const app = getApp();
|
|
|
|
Component({
|
|
properties: {
|
|
|
|
},
|
|
data: {
|
|
animationData: null,
|
|
modalStatus: false,
|
|
workNo: "",
|
|
userInfo: null,
|
|
},
|
|
lifetimes: {
|
|
// 在组件实例进入页面节点树时执行
|
|
attached() {
|
|
|
|
},
|
|
|
|
// 在组件实例被从页面节点树移除时执行
|
|
detached() {
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
// 显示对话框
|
|
showModal() {
|
|
// 显示遮罩层
|
|
let animation = wx.createAnimation({
|
|
duration: 200,
|
|
timingFunction: "linear",
|
|
delay: 0
|
|
})
|
|
this.animation = animation;
|
|
animation.translateY(1100).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
modalStatus: true
|
|
})
|
|
setTimeout(() => {
|
|
animation.translateY(0).step();
|
|
this.setData({
|
|
animationData: animation.export()
|
|
})
|
|
}, 200);
|
|
},
|
|
|
|
//隐藏对话框
|
|
hideModal() {
|
|
// 隐藏遮罩层
|
|
let animation = wx.createAnimation({
|
|
duration: 200,
|
|
timingFunction: "linear",
|
|
delay: 0
|
|
})
|
|
this.animation = animation;
|
|
animation.translateY(1100).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
})
|
|
setTimeout(() => {
|
|
animation.translateY(0).step();
|
|
this.setData({
|
|
animationData: animation.export(),
|
|
modalStatus: false
|
|
})
|
|
}, 200);
|
|
},
|
|
|
|
// 关闭弹窗并重置数据
|
|
closeModal() {
|
|
this.setData({
|
|
workNo: "",
|
|
userInfo: null,
|
|
});
|
|
this.hideModal();
|
|
},
|
|
|
|
// 监听工号输入
|
|
onWorkNoInput(e) {
|
|
this.setData({ workNo: e.detail.value });
|
|
},
|
|
|
|
// 监听身高输入
|
|
onHeightInput(e) {
|
|
this.setData({ 'userInfo.height': e.detail.value });
|
|
},
|
|
|
|
// 监听体重输入
|
|
onWeightInput(e) {
|
|
this.setData({ 'userInfo.weight': e.detail.value });
|
|
},
|
|
|
|
// 根据工号查询用户信息
|
|
searchUser() {
|
|
let workNo = this.data.workNo.trim();
|
|
if (!workNo) {
|
|
wx.showToast({
|
|
title: "请输入工号",
|
|
icon: "none"
|
|
})
|
|
return;
|
|
}
|
|
let sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
|
|
$.ajax("weighingScale/v2/getUserInfoByWkno", {
|
|
workNo: workNo,
|
|
sn: sn
|
|
}, "GET", true, "正在查询...").then(res => {
|
|
if (res.result) {
|
|
this.setData({ userInfo: res.result });
|
|
} else {
|
|
this.setData({ userInfo: null });
|
|
wx.showToast({
|
|
title: "未查询到该工号的用户信息",
|
|
icon: "none"
|
|
})
|
|
}
|
|
}).catch((err) => {
|
|
console.log(err);
|
|
this.setData({ userInfo: null });
|
|
wx.showToast({
|
|
title: (err && err.message) || "查询失败",
|
|
icon: "none"
|
|
})
|
|
})
|
|
},
|
|
|
|
// 确定提交
|
|
submit() {
|
|
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 = 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"
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}); |