import { ApiModel } from "../../utils/api"; import { TestVerify } from "../../utils/verify"; const _Http = new ApiModel(); const _Verify = new TestVerify(); Component({ /** * 组件的属性列表 */ properties: { memberMsg: { type: Object } }, /** * 组件的初始数据 */ data: { userid: '', //tenterprise_userid userName: "", //账户名称 frole: "", //身份/职位 cellPhoneNum: "", //手机号码 fright: "", //角色选择 checked: true, //是否启用 actionSheetShow: false, //弹出层显示 /* 必填项目 */ inputVerify: { userName: false, //用户名 frole: false, //身份 cellPhoneNum: false //手机号码 } }, lifetimes: { ready: function () { const { memberMsg } = this.data; /* 判断修改或新增 */ if (!memberMsg) return this.setData({ userid: 0 }) /* 修改数据 */ this.setData({ userName: memberMsg.fname, frole: memberMsg.frole, cellPhoneNum: memberMsg.fphonenumber, userid: memberMsg.tenterprise_userid }) } }, /** * 组件的方法列表 */ methods: { /* 获焦恢复 */ inputFocus(e) { let inputVerify = this.data.inputVerify; const { name } = e.currentTarget.dataset; inputVerify[name] = false; this.setData({ inputVerify }) }, /* 失焦验证 */ inputBlur(e) { let inputVerify = this.data.inputVerify; const { name } = e.currentTarget.dataset; /* 手机号验证 */ if (name == 'cellPhoneNum' && !_Verify.phoneNumber(this.data.cellPhoneNum, true)) { inputVerify[name] = true; this.setData({ inputVerify }) } /* 验证 */ if (e.detail.value != "") return; inputVerify[name] = true; this.setData({ inputVerify }) }, /* 验证 */ submitVerify() { let inputVerify = this.data.inputVerify, nextStep = true; if (!_Verify.required(this.data.userName)) { inputVerify.userName = true; nextStep = false; } if (!_Verify.required(this.data.frole)) { inputVerify.frole = true nextStep = false; } if (!_Verify.phoneNumber(this.data.cellPhoneNum)) { inputVerify.cellPhoneNum = true nextStep = false; } if (!nextStep) { this.setData({ inputVerify }) } return nextStep; }, /* 提交 */ submit() { /* 验证必填项 */ if (!this.submitVerify()) return wx.showToast({ title: '请检查输入框内容!', icon: "none" }) /* 发送请求 */ _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "customer.usercenter.teammsg.teammsg", "method": "update_userMsg", "content": { "tenterprise_userid": this.data.userid, "fname": this.data.userName, "frole": this.data.frole, "fphonenumber": this.data.cellPhoneNum, "subusers": [] } }).then(s => { if (s.msg != "成功") return wx.showToast({ title: "修改失败", icon: 'none' }) wx.showToast({ title: s.msg, }) setTimeout(() => { wx.navigateBack({ delta: 1 }) }, 500) }) }, /* 是否启用 */ switchOnChange() { this.setData({ checked: !this.data.checked }) }, /* 打开弹出框 */ actionSheetShow() { this.setData({ actionSheetShow: true }) }, /* 关闭弹出框 */ onClose() { this.setData({ actionSheetShow: false }) }, /* 返回权限选项 */ userSelect(e) { this.setData({ right: e.detail.value, actionSheetShow: false }) } } })