You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
3.8 KiB

1 month ago
Page({
data: {
background: 'transparent',
imageUrl: '',
Timestamp: Date.now(),
1 month ago
popupShow: false,
popupType: '',
popupParams: {},
1 month ago
options: [] as Array<{ indicationId: number; indicationName: string; active: boolean }>,
agreementChecked: true,
projectId: 0,
projectName: '',
isLogin: 0,
isPatient: 0,
bannerList: [] as any[],
1 month ago
},
2 weeks ago
onLoad() {
const app = getApp<IAppOption>()
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,
})),
})
1 month ago
})
},
handlePopupOk() {
this.setData({
popupShow: false,
1 month ago
})
},
handlePopupCancel() {
this.setData({
popupShow: false,
1 month ago
})
},
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,
1 month ago
})
},
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,
})
})
})
},
})
}
},
1 month ago
toggleAgreement() {
this.setData({
agreementChecked: !this.data.agreementChecked,
1 month ago
})
},
handleWork() {
1 month ago
wx.navigateTo({
url: '/pages/work/index',
1 month ago
})
},
onShareAppMessage() {
return {
title: '华观健康',
path: '/pages/index/index',
1 month ago
}
},
})