//引入请求 import { ApiModel } from "../../utils/api" //引入校验文件 import { TestVerify } from "../../utils/verify" const _Http = new ApiModel(); const _Verify = new TestVerify(); Page({ /** * 页面的初始数据 */ data: { fname: "", //用户名 frole: "", //角色 fphonenumber: "", //手机号 fsex: "", //性别 fbirthdate: "", //生日 femail: "", //邮箱 fwechatno: "", //微信 faddress: "", //地址 /* 必填项未填红色显示 */ inputErrRed: { isFname: false, //用户名 isFrole: false, //角色 } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { /* 初始化数据 */ const data = JSON.parse(options.data) this.setData({ fname: data.fname, frole: data.frole, fsex: data.fsex, fbirthdate: data.fbirthdate, femail: data.femail, fwechatno: data.fwechatno, faddress: data.faddress, frole: data.frole, faddress: data.faddress, fphonenumber: data.fphonenumber, }) }, /* 修改用户头像 */ changeUserImg() { var that = this; wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], camera: 'back', success(res) { const file = res.tempFiles[0]; var index = file.tempFilePath.lastIndexOf("."); var ext = file.tempFilePath.substr(index + 1); var timestamp = Date.parse(new Date()); wx.getFileSystemManager().readFile({ filePath: file.tempFilePath, // encoding:'utf-8', success: result => { //返回临时文件路径 const fileData = result.data _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "system.system.docManage", "method": "getFileName", "content": { "filename": 'wx' + timestamp, "filetype": ext, "ownertable": "tenterprise_users", "ownerid": getApp().globalData.accountList[0].userid, "ftype": "headportrait", } }).then(res => { const a1 = _Http.uploadFile(res, fileData); console.log(a1) /* .then(res => { if (res.msg != "成功") return; console.log(res) }).catch(err => { console.log(err) }) */ }).catch(err => { console.log(err) }) }, fail: console.error }) } }) }, /* input必填项获取焦点 */ inputEssentialFocus(e) { const { name } = e.currentTarget.dataset; let inputErrRed = this.data.inputErrRed; inputErrRed[name] = false; this.setData({ inputErrRed }) }, /* input必填项失去焦点 */ inputEssentialBlur(e) { if (e.detail.value != "" && e.detail.value != " ") return; const { name } = e.currentTarget.dataset; let inputErrRed = this.data.inputErrRed; inputErrRed[name] = true; this.setData({ inputErrRed }) }, /* 校验必填项 */ inputCertain() { let state = true, inputErrRed = this.data.inputErrRed; if (!_Verify.required(this.data.fname)) { inputErrRed["isFname"] = true; state = false; }; if (!_Verify.required(this.data.frole)) { inputErrRed["isFrole"] = true; state = false; }; this.setData({ inputErrRed }); return state; }, /* 表单提交 */ formSubmit() { /* 检测是否还有为空必填项 */ if (!this.inputCertain()) return wx.showToast({ title: '必填项不可为空!', icon: "none" }); /* 发送请求 */ _Http.basic({ "accesstoken": wx.getStorageSync('token'), "classname": "customer.usercenter.usermsg.usermsg", "method": "update_usermsg", "content": { fname: this.data.fname, frole: this.data.frole, fsex: this.data.fsex, fbirthdate: this.data.fbirthdate, femail: this.data.femail, fwechatno: this.data.fwechatno, faddress: this.data.faddress, } }).then(s => { if (s.msg != "成功") return; wx.showToast({ title: '保存成功', }) setTimeout(() => { wx.navigateBack({ delta: 1 }) }, 500) this.setData({ userMsg: s.data[0] }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })