userchange.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // pages/userchange/userchange.js
  2. import Toast from '@vant/weapp/toast/toast';
  3. const {upLoad,chooseImage} = require('../../utils/util');
  4. const {modify} = require('../../API/appraise');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. changeAvatarUrl:'',
  11. changeNickName:'',
  12. changePhoneNumber:'',
  13. changePersonalSignatrue:''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady() {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow() {
  29. },
  30. /**
  31. * 生命周期函数--监听页面隐藏
  32. */
  33. onHide() {
  34. },
  35. /**
  36. * 生命周期函数--监听页面卸载
  37. */
  38. onUnload() {
  39. },
  40. /**
  41. * 页面相关事件处理函数--监听用户下拉动作
  42. */
  43. onPullDownRefresh() {
  44. },
  45. /**
  46. * 页面上拉触底事件的处理函数
  47. */
  48. onReachBottom() {
  49. },
  50. /**
  51. * 用户点击右上角分享
  52. */
  53. onShareAppMessage() {
  54. },
  55. chooseImage() {
  56. chooseImage().then((res)=>{
  57. this.uploadImage(res.tempFilePaths[0]);
  58. })
  59. },
  60. uploadImage(imagePath){
  61. upLoad( imagePath ).then((res) => {
  62. console.log(res);
  63. this.setData({
  64. changeAvatarUrl: res.Url
  65. });
  66. wx.setStorageSync('changeAvatarUrl', res.Url);
  67. })
  68. },
  69. onChangeUsername:function(e){
  70. wx.setStorageSync('changeNickName', e.detail);
  71. },
  72. onChangePhonenumber:function(e){
  73. wx.setStorageSync('changePhoneNumber', e.detail);
  74. },
  75. // onChangePassword: function(e) {
  76. // wx.setStorageSync('password', e.detail);
  77. // },
  78. onChangePersonalSignatrue: function(e) {
  79. wx.setStorageSync('changePersonalSignatrue', e.detail);
  80. },
  81. changeInfo:function(){
  82. console.log(wx.getStorageSync('uid'));
  83. console.log(wx.getStorageSync('changePersonalSignatrue'));
  84. // modifyOption.data = {
  85. // avatar: wx.getStorageSync('changeAvatarUrl'),
  86. // name: wx.getStorageSync('changeNickName'),
  87. // phone: wx.getStorageSync('changePhoneNumber'),
  88. // sign: wx.getStorageSync('changePersonalSignatrue'),
  89. // uid: wx.getStorageSync('uid'),
  90. // }
  91. var modifyOption = {
  92. data: {
  93. avatar: wx.getStorageSync('changeAvatarUrl'),
  94. name: wx.getStorageSync('changeNickName'),
  95. phone: wx.getStorageSync('changePhoneNumber'),
  96. sign: wx.getStorageSync('changePersonalSignatrue'),
  97. uid: wx.getStorageSync('uid'),
  98. },
  99. }
  100. console.log(wx.getStorageSync('changeAvatarUrl'));
  101. console.log(wx.getStorageSync('changePersonalSignatrue'));
  102. console.log(modifyOption.data);
  103. modify(modifyOption).then((res)=>{
  104. console.log(res);
  105. console.log(res.data);
  106. console.log(res.data.data);
  107. wx.setStorageSync('avatarUrl', res.data.data.avatar);
  108. wx.setStorageSync('nickName', res.data.data.name);
  109. wx.setStorageSync('personalSignatrue', res.data.data.sign);
  110. wx.switchTab({
  111. url: '/pages/user/user',
  112. })
  113. }).catch((err) => {
  114. if(err.data.message == "fail to update"){
  115. Toast.fail('无效修改');
  116. }else if(err.data.message == "phone number already be used"){
  117. Toast.fail('手机号已被占用');
  118. }
  119. })
  120. wx.setStorageSync('changeAvatarUrl', '');
  121. wx.setStorageSync('changeNickName', '');
  122. wx.setStorageSync('changePhoneNumber', '');
  123. wx.setStorageSync('changePersonalSignatrue', '');
  124. // wx.request({
  125. // url: 'http://192.168.31.28:8084',
  126. // method: 'POST',
  127. // data: {
  128. // "avatar": avatar,
  129. // "name": nickName,
  130. // "phone": phoneNumber,
  131. // "sign": personalSignatrue,
  132. // "uid": uid,
  133. // },
  134. // success (res) {
  135. // console.log(res);
  136. // wx.switchTab({
  137. // url: '/pages/user/user',
  138. // })
  139. // }
  140. // }),
  141. }
  142. })