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 }); }, // 根据工号查询用户信息 searchUser() { let workNo = this.data.workNo.trim(); if (!workNo) { wx.showToast({ title: "请输入工号", icon: "none" }) return; } $.ajax("weighingScale/v2/getUserInfoByWkno", { workNo }, "GET", true, "正在查询...").then(res => { if (res.result) { this.setData({ userInfo: res.result }); } else { this.setData({ userInfo: null }); wx.showToast({ title: "未查询到该工号的用户信息", icon: "none" }) } }).catch(() => { wx.showToast({ title: "查询失败,请重试", icon: "none" }) }) }, // 确定提交 submit() { if (!this.data.userInfo) { wx.showToast({ title: "请先查询用户信息", icon: "none" }) return; } let sn = app.globalData.ppScale.device.mac.replace(/:/g, ''); let user = this.data.userInfo; $.ajax("weighingScale/v2/edit/user", { sn, realname: user.realname, sex: user.sex, birthday: user.birthday, height: user.height, weight: user.weight }, "POST", true, "正在添加...").then(res => { wx.showToast({ title: "添加成功", icon: "success" }) this.triggerEvent('returnDate', { userInfo: user }); this.closeModal(); }).catch(() => { wx.showToast({ title: "添加失败,请重试", icon: "none" }) }) } } });