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(), ReturnCount:options.ReturnCount, 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; if (!that.data.NickName || that.data.NickName==""){ wx.showToast({ title: "请写昵称", duration: 2000, image: "../images/universalpic_exclamation_white_120x120.png", }); } else { 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; main.postData('UpdateMPSUserNickNameAndAvatar?UserID=' + app.globalData.userInfo.UserID, param, function (data) { that.setData({ ReturnCount:1, }); 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 () { if (this.data.ReturnCount==2) app.globalData.TempParam="return"; wx.navigateBack({ delta: 1 }); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })