index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const app = getApp()
  2. import {
  3. setUserInfo
  4. } from '~/api/user'
  5. Component({
  6. properties: {
  7. title: {
  8. type: String,
  9. value: '朗读小咖秀',
  10. }
  11. },
  12. data: {
  13. navBarHeight: app.globalData.navBarHeight,
  14. menuRight: app.globalData.menuRight,
  15. menuTop: app.globalData.menuTop,
  16. menuHeight: app.globalData.menuHeight,
  17. grade: null,
  18. isGradeShow: false
  19. },
  20. attached: function () {
  21. // console.log(wx.getStorage(user));
  22. },
  23. methods: {
  24. // 选择年级
  25. selectGrade({
  26. target
  27. }) {
  28. let code = target.dataset.code
  29. if (!code) {
  30. return
  31. }
  32. this.setData({
  33. grade: code
  34. })
  35. },
  36. // 修改年级
  37. async changeGrade(e) {
  38. const grade = this.data.grade
  39. if (!grade) {
  40. return wx.showToast({
  41. title: '请选择年级',
  42. icon: 'none',
  43. duration: 2000
  44. })
  45. }
  46. this.setData({
  47. isGradeShow: false,
  48. })
  49. await setUserInfo({
  50. grade
  51. }, 'put')
  52. },
  53. }
  54. })