index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const app = getApp()
  2. import {
  3. setUserInfo
  4. } from '~/api/user'
  5. import {
  6. storeBindingsBehavior
  7. } from 'mobx-miniprogram-bindings'
  8. import {
  9. store
  10. } from '~/store/index'
  11. Component({
  12. // 自动绑定
  13. behaviors: [storeBindingsBehavior],
  14. storeBindings: {
  15. store,
  16. fields: {
  17. userInfo: 'userInfo'
  18. },
  19. actions: {
  20. setUser: 'setUser'
  21. }
  22. },
  23. properties: {
  24. title: {
  25. type: String,
  26. value: '朗读小咖秀',
  27. }
  28. },
  29. data: {
  30. navBarHeight: app.globalData.navBarHeight,
  31. menuRight: app.globalData.menuRight,
  32. menuTop: app.globalData.menuTop,
  33. menuHeight: app.globalData.menuHeight,
  34. isGradeShow: false,
  35. temporaryGrade: null
  36. },
  37. methods: {
  38. closeGrade() {
  39. this.setData({
  40. isGradeShow: false,
  41. })
  42. },
  43. // 选择年级
  44. selectGrade({
  45. target
  46. }) {
  47. let code = target.dataset.code
  48. if (!code) {
  49. return
  50. }
  51. this.setData({
  52. temporaryGrade: code
  53. })
  54. },
  55. showGrade() {
  56. this.setData({
  57. isGradeShow: true,
  58. temporaryGrade: this.data.userInfo.grade
  59. })
  60. },
  61. // 修改年级
  62. async changeGrade(e) {
  63. const grade = this.data.temporaryGrade
  64. if (!grade) {
  65. return wx.showToast({
  66. title: '请选择年级',
  67. icon: 'none',
  68. duration: 2000
  69. })
  70. }
  71. this.setData({
  72. isGradeShow: false,
  73. })
  74. let res = await setUserInfo({
  75. grade
  76. }, 'put')
  77. this.setUser(res)
  78. setTimeout(() => {
  79. this.triggerEvent('reload')
  80. }, 300)
  81. },
  82. }
  83. })