userinfo.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. main.postData('UpdateMPSUserNickNameAndAvatar?UserID=' + app.globalData.userInfo.UserID, param, function (data) {
  54. that.setData({
  55. ReturnCount:1,
  56. });
  57. that.gotoReturn();
  58. });
  59. }
  60. },
  61. uploadFileToServer: function (file, callback) {
  62. var url = common.Encrypt("MiaoguoUploadFile2");
  63. wx.showLoading({
  64. title: '上传中',
  65. mask: true,
  66. });
  67. wx.uploadFile({
  68. url: app.globalData.serverUrl + url,
  69. filePath: file,
  70. name: 'file',
  71. success(res) {
  72. var err = JSON.parse(res.data);
  73. if (err.errcode == 10000) {
  74. wx.hideLoading();
  75. callback(err.result);
  76. } else {
  77. wx.hideLoading();
  78. wx.showModal({
  79. title: '上传文件失败',
  80. showCancel: false,
  81. content: JSON.stringify(err.errMsg),
  82. });
  83. }
  84. },
  85. fail: function (err) {
  86. wx.hideLoading();
  87. wx.showModal({
  88. title: '上传文件失败',
  89. showCancel: false,
  90. content: JSON.stringify(err),
  91. });
  92. }
  93. });
  94. },
  95. gotoReturn: function () {
  96. if (this.data.ReturnCount==2)
  97. app.globalData.TempParam="return";
  98. wx.navigateBack({
  99. delta: 1
  100. });
  101. },
  102. onShareAppMessage: function () {
  103. return {
  104. title: app.globalData.ShareTitle,
  105. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  106. imageUrl: app.globalData.ShareImage,
  107. }
  108. },
  109. })