const app = getApp() Page({ data: { popupShow: false, popupType: 'stayTuned', popupParams: {}, }, onLoad() { app.waitLogin().then(() => { app.mpBehavior({ PageName: 'PG_MY' }) app.getUserInfo().then((userInfo) => { this.setData({ userInfo, // 数字变红 Days: userInfo.Days.replace(/(\d+)/g, '$1'), }) }) }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail const url = `${app.globalData.upFileUrl}?r=file-service/upload-img` wx.showLoading({ title: '上传中', }) wx.uploadFile({ url, filePath: avatarUrl, name: 'file', success: (res) => { const data = JSON.parse(res.data) const avatarUrl = data.data.Url wx.ajax({ method: 'POST', url: '?r=wtx/user/update-avatar', data: { Avatar: avatarUrl, }, }) .then(() => { wx.hideLoading() wx.showToast({ title: '头像更新成功!', icon: 'none', }) this.setData({ 'userInfo.Avatar': avatarUrl, }) }) .catch(() => { wx.hideLoading() }) }, fail() { wx.hideLoading() }, }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, routerTo(e) { const { url } = e.currentTarget.dataset wx.navigateTo({ url, }) }, handleNone(e: any) { const { index } = e.currentTarget.dataset const PageName = { 1: 'BTN_MY_SWITCHPATIENT', 2: 'BTN_MY_SWITCH_DOCTOR', }[index] app.mpBehavior({ PageName }) this.setData({ popupShow: true, popupType: 'stayTuned', }) }, }) export {}