const app = getApp() Page({ data: { popupShow: false, // popupType: 'stayTuned', popupType: 'touristsInviteCode', popupParams: {}, userInfo: {} as any, showPatient: false, applyWord: { ApplyButtonWordOne: '', ApplyButtonWordTwo: '', }, }, onShow() { app.waitLogin({ type: 0 }).then(() => { app.mpBehavior({ PageName: 'BTN_MY_NAV' }) app.getUserInfo().then((userInfo) => { this.setData({ userInfo, Days: userInfo.Days.replace(/(\d+)/g, '$1'), }) }) this.getGeneConfig() this.getApplyWord() }) }, getGeneConfig() { wx.ajax({ method: 'GET', url: '?r=wtx/common/get-gene-config', data: {}, }).then((res) => { this.setData({ showPatient: res === '1', }) }) }, getApplyWord() { wx.ajax({ method: 'GET', url: '?r=wtx/common/get-apply-word', data: {}, }).then((res) => { this.setData({ applyWord: res, }) }) }, 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, }) }, handlePopupOk() { this.setData({ popupShow: false, }) }, handlePatient(e) { const { url, pname } = e.currentTarget.dataset const { userInfo } = this.data if (pname) { app.mpBehavior({ PageName: pname }) } if (userInfo.PatientId <= 0) { this.setData({ popupShow: true, popupType: 'touristsInviteCode', }) return } wx.navigateTo({ url, }) }, routerTo(e: any) { const { url, pname } = e.currentTarget.dataset if (pname) { app.mpBehavior({ PageName: pname }) } wx.navigateTo({ url, }) }, }) export {}