const app = getApp(); Page({ /** * 页面的初始数据 */ data: { /** * avatar: "" companyName: "测试" email: "majt@vandh.org" expireTime: null ifOverFlow: "Y" loginRole: "admin" loginTime: null mobile: "17601625351" nickName: "马江涛" status: "20" userId: 145 */ ossPath:app.globalData.$filePath, imageUrl:'' }, uploadImg() { var that = this; const {image,nickName,userId} = that.data.userInfo; wx.chooseImage({ count: 1, // 单选 success: function (res) { var filePath = res.tempFilePaths && res.tempFilePaths[0] app.wxUploadFile({ url: "/common/upload", filePath: filePath, name: "file", }).then(function (res) { var data = JSON.parse(res.data); if (data.url) { that.editImageAndNickName(data.url,nickName,userId); } else { app.showToptip(that, "error", "上传失败请联系管理员") } }).catch(function () { app.showToptip(that, "error", "上传失败请联系管理员") }) } }) }, editImageAndNickName(image,nickName,userId){ var that = this; app.requestP({ url:'/user/editImageAndNickName', method:'post', contentType: ' application/json', data:{ image, nickName:nickName || '', userId, } }).then(res=>{ app.showToptip(that,'success',res.data.msg); wx.navigateBack({ delta: 1, }) }).catch(err=>{ app.showToptip(that,'error',err.data.msg) }) }, goEmail(){ var userInfo = this.data.userInfo; if(userInfo.email){ wx.navigateTo({ url:"/pages/user/email?email="+userInfo.email+"&userId="+userInfo.userId }) }else{ wx.navigateTo({ url:"/pages/user/emailEdit?userId="+userInfo.userId }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const userInfo = JSON.parse(options.userInfo); this.setData({ userInfo }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, })