user-info.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { VueLikePage } from '../../utils/page'
  2. import UserApi from '../../apis/user'
  3. import DisplayApi from '../../apis/exhibition'
  4. import { saveUserInfo } from '../../utils/storage'
  5. import { API_BASE_URL } from '../../config/config'
  6. VueLikePage([], {
  7. data: {
  8. userInfo: {},
  9. tradeList: []
  10. },
  11. methods: {
  12. onLoad () {
  13. this.getAllTrade()
  14. },
  15. onShow () {
  16. this.setData({
  17. userInfo: Object.assign({}, getApp().globalData.userinfo)
  18. })
  19. },
  20. chooseImage () {
  21. return wx.chooseImage({
  22. count: 1,
  23. success: (res) => {
  24. const { tempFilePaths } = res
  25. return this.uploadAvatar(tempFilePaths[0])
  26. },
  27. })
  28. },
  29. updateUserInfo () {
  30. UserApi.updateUserInfo(this.data.userInfo).then(res => {
  31. wx.showToast({
  32. title: '修改成功',
  33. })
  34. getApp().globalData.userinfo = this.data.userInfo
  35. saveUserInfo(this.data.userInfo)
  36. })
  37. },
  38. uploadAvatar (filePath) {
  39. return new Promise((resolve, reject) => {
  40. wx.uploadFile({
  41. filePath: filePath,
  42. name: 'file',
  43. url: `${API_BASE_URL}/im/upload`,
  44. header: {
  45. "Content-Type": "multipart/form-data"
  46. },
  47. success: (res) => {
  48. res = JSON.parse(res.data)
  49. let userInfo = this.data.userInfo
  50. userInfo.avatar = res.data
  51. this.setData({
  52. userInfo
  53. })
  54. resolve({url: res.data});
  55. },
  56. fail: (err) => {
  57. console.log(err, 'err')
  58. }
  59. })
  60. })
  61. },
  62. bindInput (e) {
  63. let userInfo = this.data.userInfo
  64. const { key } = e.currentTarget.dataset
  65. userInfo[key] = e.detail.value
  66. this.setData({
  67. userInfo
  68. })
  69. },
  70. getAllTrade () {
  71. return DisplayApi.getTradeList().then(res => {
  72. this.originTradeList = res.data
  73. this.setData({
  74. tradeList: res.data.map(item => item.name)
  75. })
  76. })
  77. },
  78. bindPickerChange (e) {
  79. let userInfo = this.data.userInfo
  80. userInfo.companyTrade = this.originTradeList[e.detail.value].name
  81. this.setData({
  82. userInfo
  83. })
  84. },
  85. changeCheckStatus (e) {
  86. const { value } = e.currentTarget.dataset
  87. this.setData({
  88. 'userInfo.gender': value
  89. })
  90. }
  91. }
  92. })