12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import {showLoading, toast} from "../../utils/utils";
- import Api from "../../model/api";
- import User from "../../model/user";
- import Upload from "../../model/upload";
- import Config from "../../model/config";
- import Route from "../../model/route";
- Page({
- data: {
- userInfo: {},
- formData: {
- name: '',
- picUrl: '',
- },
- },
- async onShow(options) {
- const user = User.getUserInfoByLocal();
- this.setData({
- userInfo: user,
- 'formData.name': user.name,
- 'formData.picUrl': user.picUrl || '',
- })
- },
- changePhone(e) {
- Route.tocChangePhone();
- },
- async chooseImg(e) {
- const img = await wx.chooseImage({count: 1});
- const file = {url: img.tempFilePaths[0]};
- wx.showLoading({
- title: '正在上传...',
- mask: true
- });
- await Upload.uploadRes(Config.UPLOAD_PATH.AVATER, file);
- this.setData({
- 'formData.picUrl': file.url
- })
- wx.hideLoading();
- },
- async loginByWechat(e) {
- if (!this.data.userInfo.wechatOpenId) {
- showLoading();
- await User.bindWechat();
- wx.hideLoading()
- this.setData({
- 'userInfo.wechatOpenId': "已绑定"
- })
- }
- },
- async put(e) {
- if (!this.data.formData.name.trim()) {
- toast('请输入姓名')
- return;
- }
- showLoading();
- await Api.changeUserInfo(this.data.formData)
- await User.updateUserInfo()
- wx.hideLoading()
- wx.showToast({
- title: '修改成功',
- icon: 'success'
- });
- }
- })
|