1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- const app = getApp()
- import {
- setUserInfo
- } from '~/api/user'
- import {
- storeBindingsBehavior
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- Component({
- // 自动绑定
- behaviors: [storeBindingsBehavior],
- storeBindings: {
- store,
- fields: {
- userInfo: 'userInfo'
- },
- actions: {
- setUser: 'setUser'
- }
- },
- properties: {
- title: {
- type: String,
- value: '朗读小咖秀',
- }
- },
- data: {
- navBarHeight: app.globalData.navBarHeight,
- menuRight: app.globalData.menuRight,
- menuTop: app.globalData.menuTop,
- menuHeight: app.globalData.menuHeight,
- isGradeShow: false,
- temporaryGrade: null
- },
- methods: {
- closeGrade() {
- this.setData({
- isGradeShow: false,
- })
- },
- // 选择年级
- selectGrade({
- target
- }) {
- let code = target.dataset.code
- if (!code) {
- return
- }
- this.setData({
- temporaryGrade: code
- })
- },
- showGrade() {
- this.setData({
- isGradeShow: true,
- temporaryGrade: this.data.userInfo.grade
- })
- },
- // 修改年级
- async changeGrade(e) {
- const grade = this.data.temporaryGrade
- if (!grade) {
- return wx.showToast({
- title: '请选择年级',
- icon: 'none',
- duration: 2000
- })
- }
- this.setData({
- isGradeShow: false,
- })
- let res = await setUserInfo({
- grade
- }, 'put')
- this.setUser(res)
- setTimeout(() => {
- this.triggerEvent('reload')
- }, 300)
- },
- }
- })
|