Page({ data: { background: 'transparent', imageUrl: '', Timestamp: Date.now(), popupShow: false, popupType: '', popupParams: {}, options: [] as Array<{ indicationId: number; indicationName: string; active: boolean }>, agreementChecked: true, projectId: 0, projectName: '', isLogin: 0, isPatient: 0, bannerList: [] as any[], }, onLoad() { const app = getApp() app.waitLogin({ types: [1, 2] }).then(() => { this.getBanner() this.checkStatus() }) }, getBanner() { wx.ajax({ method: 'GET', url: '/app/patient/patient/banner-list', data: { projectId: this.data.projectId, }, }).then((res: any) => { this.setData({ bannerList: res, }) }) }, checkStatus() { wx.ajax({ method: 'GET', url: '/app/patient/patient/check-status', }).then((res: any) => { this.setData({ isLogin: res.isLogin, isPatient: res.isPatient, projectId: res.projectId, projectName: res.projectName, }) if (res.isLogin === 1 && res.isPatient === 1 && res.projectId) { this.setData({ options: [ { indicationId: res.indicationId, indicationName: res.indicationName, active: true, }, ], }) } else { this.getProjectInfo() } }) }, getProjectInfo() { wx.ajax({ method: 'GET', url: '/app/patient/patient/project-info', }).then((res: any) => { this.setData({ projectId: res.projectId, projectName: res.projectName, options: res.indications.map((item: any) => ({ indicationId: item.indicationId, indicationName: item.indicationName, active: false, })), }) }) }, handlePopupOk() { this.setData({ popupShow: false, }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, selectOption(e) { const indicationId = e.currentTarget.dataset.id as number const newOptions = this.data.options.map((option) => ({ ...option, active: option.indicationId === indicationId, })) this.setData({ options: newOptions, }) }, handleWxSubmit(e: WechatMiniprogram.CustomEvent) { if (!this.data.agreementChecked) { wx.showToast({ icon: 'none', title: '请同意用户协议', }) return } const selectedOption = this.data.options.find((item) => item.active) if (!selectedOption) { wx.showToast({ icon: 'none', title: '请选择适应症', }) return } const { iv, encryptedData } = e.detail if (iv && encryptedData) { wx.login({ success: (loginRes) => { wx.ajax({ method: 'POST', url: '/app/common/common/wx-login', data: { code: loginRes.code, }, }).then(() => { wx.ajax({ method: 'POST', url: '/app/patient/patient/select-indication', data: { projectId: this.data.projectId, indicationId: selectedOption.indicationId, }, }).then((res: any) => { wx.navigateToMiniProgram({ appId: 'wx05551c5ee1fd1c12', path: res.jumpUrl, }) }) }) }, }) } }, toggleAgreement() { this.setData({ agreementChecked: !this.data.agreementChecked, }) }, handleWork() { wx.navigateTo({ url: '/pages/work/index', }) }, onShareAppMessage() { return { title: '华观健康', path: '/pages/index/index', } }, })