userInfo.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {showLoading, toast} from "../../utils/utils";
  2. import Api from "../../model/api";
  3. import User from "../../model/user";
  4. import Upload from "../../model/upload";
  5. import Config from "../../model/config";
  6. import Route from "../../model/route";
  7. Page({
  8. data: {
  9. userInfo: {},
  10. formData: {
  11. name: '',
  12. picUrl: '',
  13. },
  14. },
  15. async onShow(options) {
  16. const user = User.getUserInfoByLocal();
  17. this.setData({
  18. userInfo: user,
  19. 'formData.name': user.name,
  20. 'formData.picUrl': user.picUrl || '',
  21. })
  22. },
  23. changePhone(e) {
  24. Route.tocChangePhone();
  25. },
  26. async chooseImg(e) {
  27. const img = await wx.chooseImage({count: 1});
  28. const file = {url: img.tempFilePaths[0]};
  29. wx.showLoading({
  30. title: '正在上传...',
  31. mask: true
  32. });
  33. await Upload.uploadRes(Config.UPLOAD_PATH.AVATER, file);
  34. this.setData({
  35. 'formData.picUrl': file.url
  36. })
  37. wx.hideLoading();
  38. },
  39. async loginByWechat(e) {
  40. if (!this.data.userInfo.wechatOpenId) {
  41. showLoading();
  42. await User.bindWechat();
  43. wx.hideLoading()
  44. this.setData({
  45. 'userInfo.wechatOpenId': "已绑定"
  46. })
  47. }
  48. },
  49. async put(e) {
  50. if (!this.data.formData.name.trim()) {
  51. toast('请输入姓名')
  52. return;
  53. }
  54. showLoading();
  55. await Api.changeUserInfo(this.data.formData)
  56. await User.updateUserInfo()
  57. wx.hideLoading()
  58. wx.showToast({
  59. title: '修改成功',
  60. icon: 'success'
  61. });
  62. }
  63. })