index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. /**
  8. * avatar: ""
  9. companyName: "测试"
  10. email: "majt@vandh.org"
  11. expireTime: null
  12. ifOverFlow: "Y"
  13. loginRole: "admin"
  14. loginTime: null
  15. mobile: "17601625351"
  16. nickName: "马江涛"
  17. status: "20"
  18. userId: 145
  19. */
  20. ossPath:app.globalData.$filePath,
  21. imageUrl:''
  22. },
  23. uploadImg() {
  24. var that = this;
  25. const {image,nickName,userId} = that.data.userInfo;
  26. wx.chooseImage({
  27. count: 1, // 单选
  28. success: function (res) {
  29. var filePath = res.tempFilePaths && res.tempFilePaths[0]
  30. app.wxUploadFile({
  31. url: "/common/upload",
  32. filePath: filePath,
  33. name: "file",
  34. }).then(function (res) {
  35. var data = JSON.parse(res.data);
  36. if (data.url) {
  37. that.editImageAndNickName(data.url,nickName,userId);
  38. } else {
  39. app.showToptip(that, "error", "上传失败请联系管理员")
  40. }
  41. }).catch(function () {
  42. app.showToptip(that, "error", "上传失败请联系管理员")
  43. })
  44. }
  45. })
  46. },
  47. editImageAndNickName(image,nickName,userId){
  48. var that = this;
  49. app.requestP({
  50. url:'/user/editImageAndNickName',
  51. method:'post',
  52. contentType: ' application/json',
  53. data:{
  54. image,
  55. nickName:nickName || '',
  56. userId,
  57. }
  58. }).then(res=>{
  59. app.showToptip(that,'success',res.data.msg);
  60. wx.navigateBack({
  61. delta: 1,
  62. })
  63. }).catch(err=>{
  64. app.showToptip(that,'error',err.data.msg)
  65. })
  66. },
  67. goEmail(){
  68. var userInfo = this.data.userInfo;
  69. if(userInfo.email){
  70. wx.navigateTo({
  71. url:"/pages/user/email?email="+userInfo.email+"&userId="+userInfo.userId
  72. })
  73. }else{
  74. wx.navigateTo({
  75. url:"/pages/user/emailEdit?userId="+userInfo.userId
  76. })
  77. }
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. const userInfo = JSON.parse(options.userInfo);
  84. this.setData({
  85. userInfo
  86. })
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. },
  93. })