userinfo.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {},
  6. onLoad: function (options) {
  7. var that = this;
  8. var nickname = app.globalData.userInfo.NickName;
  9. if (app.globalData.userInfo.NickName == "陌生用户")
  10. nickname = "";
  11. this.setData({
  12. Containnerheight: main.getWindowHeight(),
  13. ReturnCount:options.ReturnCount,
  14. NickName: nickname,
  15. AvatarUrl: app.globalData.userInfo.AvatarUrl,
  16. });
  17. },
  18. onChooseAvatar: function (e) {
  19. var that = this;
  20. console.log(e);
  21. that.uploadFileToServer(e.detail.avatarUrl, function (data) {
  22. if (data) {
  23. //console.log(data.Target);
  24. setTimeout(function () {
  25. that.setData({
  26. AvatarUrl: app.globalData.uploadImageUrl + data.Target,
  27. });
  28. }, 1000);
  29. }
  30. });
  31. },
  32. onKeyInput: function (e) {
  33. var that = this;
  34. var nickname = e.detail.value;
  35. that.setData({
  36. NickName: nickname,
  37. });
  38. },
  39. save: function () {
  40. var that = this;
  41. if (!that.data.NickName || that.data.NickName==""){
  42. wx.showToast({
  43. title: "请写昵称",
  44. duration: 2000,
  45. image: "../images/universalpic_exclamation_white_120x120.png",
  46. });
  47. } else {
  48. app.globalData.userInfo.NickName = that.data.NickName;
  49. app.globalData.userInfo.AvatarUrl = that.data.AvatarUrl;
  50. var param = {};
  51. param.NickName = app.globalData.userInfo.NickName;
  52. param.AvatarUrl = app.globalData.userInfo.AvatarUrl;
  53. //debugger;
  54. main.postData('UpdateMPSUserNickNameAndAvatar?UserID=' + app.globalData.userInfo.UserID, param, function (data) {
  55. that.setData({
  56. ReturnCount:1,
  57. });
  58. that.gotoReturn();
  59. });
  60. }
  61. },
  62. uploadFileToServer: function (file, callback) {
  63. var url = common.Encrypt("MiaoguoUploadFile2");
  64. wx.showLoading({
  65. title: '上传中',
  66. mask: true,
  67. });
  68. wx.uploadFile({
  69. url: app.globalData.serverUrl + url,
  70. filePath: file,
  71. name: 'file',
  72. success(res) {
  73. var err = JSON.parse(res.data);
  74. if (err.errcode == 10000) {
  75. wx.hideLoading();
  76. callback(err.result);
  77. } else {
  78. wx.hideLoading();
  79. wx.showModal({
  80. title: '上传文件失败',
  81. showCancel: false,
  82. content: JSON.stringify(err.errMsg),
  83. });
  84. }
  85. },
  86. fail: function (err) {
  87. wx.hideLoading();
  88. wx.showModal({
  89. title: '上传文件失败',
  90. showCancel: false,
  91. content: JSON.stringify(err),
  92. });
  93. }
  94. });
  95. },
  96. gotoReturn: function () {
  97. if (this.data.ReturnCount==2)
  98. app.globalData.TempParam="return";
  99. wx.navigateBack({
  100. delta: 1
  101. });
  102. },
  103. onShareAppMessage: function () {
  104. return {
  105. title: app.globalData.ShareTitle,
  106. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  107. imageUrl: app.globalData.ShareImage,
  108. }
  109. },
  110. })