index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // pages/user/info/index.js
  2. const app = getApp()
  3. Page({
  4. data: {
  5. userInfo: null,
  6. spinShow: false,
  7. levelIndex: 0
  8. },
  9. onLoad: function(options) {
  10. this.loadUserInfo()
  11. },
  12. loadUserInfo() {
  13. let _this = this
  14. _this.setData({
  15. spinShow: true
  16. });
  17. app.formPost('/api/wx/student/user/current', null).then(res => {
  18. if (res.code == 1) {
  19. _this.setData({
  20. userInfo: res.response,
  21. levelIndex: res.response.userLevel-1
  22. });
  23. }
  24. _this.setData({
  25. spinShow: false
  26. });
  27. }).catch(e => {
  28. _this.setData({
  29. spinShow: false
  30. });
  31. app.message(e, 'error')
  32. })
  33. },
  34. bindLevelChange: function(e) {
  35. this.setData({
  36. levelIndex: e.detail.value
  37. })
  38. },
  39. bindDateChange(e) {
  40. let {
  41. value
  42. } = e.detail;
  43. this.setData({
  44. "userInfo.birthDay": value
  45. })
  46. },
  47. formSubmit: function(e) {
  48. let _this = this
  49. wx.showLoading({
  50. title: '提交中',
  51. mask: true
  52. })
  53. app.formPost('/api/wx/student/user/update', e.detail.value)
  54. .then(res => {
  55. if (res.code == 1) {
  56. wx.reLaunch({
  57. url: '/pages/my/index/index',
  58. });
  59. } else {
  60. app.message(res.message, 'error')
  61. }
  62. wx.hideLoading()
  63. }).catch(e => {
  64. app.message(e, 'error')
  65. wx.hideLoading()
  66. })
  67. }
  68. })