import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); Page({ data: { }, onLoad: function (options) { var that = this; var nickname=app.globalData.userInfo.NickName; if (app.globalData.userInfo.NickName=="陌生用户") nickname=""; this.setData({ Containnerheight: main.getWindowHeight(), NickName: nickname, AvatarUrl: app.globalData.userInfo.AvatarUrl, }); }, onChooseAvatar:function(e){ var that = this; console.log(e); that.uploadFileToServer(e.detail.avatarUrl, function (data) { if (data) { //console.log(data.Target); setTimeout(function(){ that.setData({ AvatarUrl:app.globalData.uploadImageUrl + data.Target, }); },1000); } }); }, onKeyInput: function (e) { var that=this; var nickname = e.detail.value; that.setData({ NickName: nickname, }); }, save:function(){ var that=this; app.globalData.userInfo.NickName=that.data.NickName; app.globalData.userInfo.AvatarUrl=that.data.AvatarUrl; var param={}; param.NickName=app.globalData.userInfo.NickName; param.AvatarUrl=app.globalData.userInfo.AvatarUrl; //debugger; main.postData('UpdateMPSUserNickNameAndAvatar?UserID=' + app.globalData.userInfo.UserID, param, function (data) { that.gotoReturn(); }); }, uploadFileToServer: function (file, callback) { var url = common.Encrypt("MiaoguoUploadFile2"); wx.showLoading({ title: '上传中', mask: true, }); wx.uploadFile({ url: app.globalData.serverUrl + url, filePath: file, name: 'file', success(res) { var err = JSON.parse(res.data); if (err.errcode == 10000) { wx.hideLoading(); callback(err.result); } else { wx.hideLoading(); wx.showModal({ title: '上传文件失败', showCancel: false, content: JSON.stringify(err.errMsg), }); } }, fail: function (err) { wx.hideLoading(); wx.showModal({ title: '上传文件失败', showCancel: false, content: JSON.stringify(err), }); } }); }, gotoReturn:function(){ wx.navigateBack({ delta: 1 }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })