123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- import {
- setUserInfo
- } from '~/api/user'
- let storeBindings
- Page({
- data: {
- gradeIndex: 0,
- gradeArray: [{
- value: 'PRESCHOOL',
- key: '学前班'
- }, {
- value: 'PRIMARY_FIRST_GRADE',
- key: '一年级'
- },
- {
- value: 'PRIMARY_SECOND_GRADE',
- key: '二年级'
- },
- {
- value: 'PRIMARY_THREE_GRADE',
- key: '三年级'
- },
- {
- value: 'PRIMARY_SENIOR_GRADE',
- key: '四年级'
- },
- ],
- },
- onLoad(options) {
- // 手工绑定
- this.storeBindings = createStoreBindings(this, {
- store,
- fields: {
- userInfo: 'userInfo'
- },
- actions: {
- setUser: 'setUser'
- }
- })
- // 立刻更新
- this.storeBindings.updateStoreBindings()
- let {
- grade
- } = this.data.userInfo
- let gradeIndex = this.data.gradeArray.findIndex(item => {
- return item.value == grade
- })
- this.setData({
- gradeIndex
- })
- },
- // 调用清理函数
- onUnload() {
- this.storeBindings.destroyStoreBindings()
- },
- changeAvatar(e) {
- const {
- avatarUrl
- } = e.detail
- wx.uploadFile({
- url: 'https://reader-api.ai160.com/file/upload',
- filePath: avatarUrl,
- name: '头像',
- header: {
- uid: wx.getStorageSync('uid')
- },
- success: (res) => {
- const newAvatar = JSON.parse(res.data).data;
- const str = 'userInfo.avatar'
- this.setData({
- [str]: newAvatar
- })
- this.setUserInfo({
- avatar: newAvatar
- })
- }
- })
- },
- saveNickName(e) {
- let nickName = e.detail.value;
- if (nickName == this.data.userInfo.nickName) {
- return
- }
- this.setUserInfo({
- nickName
- })
- },
- selectProfession() {
- wx.showActionSheet({
- itemList: ['学生', '家长', '老师'],
- success: (res) => {
- /* if (res.tapIndex == this.data.userInfo.gender) {
- return
- }
- this.setUserInfo({
- gender: res.tapIndex
- }) */
- },
- })
- },
- selectGender() {
- wx.showActionSheet({
- itemList: ['女', '男'],
- success: (res) => {
- if (res.tapIndex == this.data.userInfo.gender) {
- return
- }
- this.setUserInfo({
- gender: res.tapIndex
- })
- },
- })
- },
- bindDateChange(e) {
- this.setUserInfo({
- birthday: e.detail.value
- })
- },
- bindGradeChange(e) {
- let grade = this.data.gradeArray[e.detail.value].value
- this.setUserInfo({
- grade
- })
- },
- saveSchool(e) {
- let schoolName = e.detail.value;
- if (schoolName == this.data.userInfo.schoolName) {
- return
- }
- this.setUserInfo({
- schoolName
- })
- },
- async setUserInfo(data) {
- wx.showLoading({
- title: '提交中',
- })
- let res = await setUserInfo(data, 'put').finally(() => {
- wx.hideLoading()
- })
- this.setUser(res)
- },
- })
|