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.

305 lines
7.0 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: '',
projectName: '',
currentProjectName: '',
projectIndex: 0,
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>,
// 扫码获取的药师ID
pharmacistId: '',
isLogin: 0,
isPatient: 0,
// 是否已有项目
hasProject: false,
// 选中的适应症名称
selectedIndicationName: '',
bannerList: [] as any[],
1 month ago
},
2 weeks ago
onLoad() {
const app = getApp<IAppOption>()
// 从 globalData 初始化扫码参数
const pharmacistId = app.globalData.pharmacistId || ''
const projectId = app.globalData.projectId || ''
this.setData({
pharmacistId,
projectId,
})
app.waitLogin().then(() => {
this.getProjectList()
this.getBanner()
this.checkStatus()
})
},
// 获取项目列表
getProjectList() {
wx.ajax({
method: 'GET',
url: '/app/patient/patient/project-list',
}).then((res: any) => {
const projectList = res.list || []
const currentProjectId = res.currentProjectId
// 找到当前项目的索引
let projectIndex = 0
projectList.forEach((item: any, index: number) => {
if (item.projectId === currentProjectId) {
projectIndex = index
}
})
this.setData({
projectList,
projectIndex,
currentProjectName: projectList[projectIndex]?.projectName || '华观健康',
})
})
},
// 切换项目
onProjectChange(e: WechatMiniprogram.CustomEvent) {
const index = e.detail.value
const project = this.data.projectList[index]
if (!project || project.projectId === this.data.projectList[this.data.projectIndex]?.projectId) {
return
}
wx.ajax({
method: 'POST',
url: '/app/patient/patient/switch-project',
data: {
projectId: project.projectId,
},
}).then(() => {
this.setData({
projectIndex: index,
currentProjectName: project.projectName,
projectId: String(project.projectId),
})
// 刷新页面数据
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/recent-project',
})
.then((res: any) => {
if (res && res.projectId) {
// 已有项目,显示已参加项目状态
this.setData({
isLogin: 1,
isPatient: 1,
projectId: res.projectId,
projectName: res.projectName,
hasProject: true,
selectedIndicationName: res.indicationName,
})
} else {
// 没有项目,获取项目列表供选择
this.setData({
hasProject: false,
})
this.getProjectInfo()
}
})
.catch(() => {
// 接口失败,获取项目列表
this.setData({
hasProject: false,
})
this.getProjectInfo()
})
},
getProjectInfo() {
1 week ago
const params: any = {}
// 如果有 projectId,传入获取指定项目信息
if (this.data.projectId) {
params.projectId = this.data.projectId
}
wx.ajax({
method: 'GET',
url: '/app/patient/patient/project-info',
1 week ago
data: params,
}).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) {
1 week ago
const app = getApp<IAppOption>()
const sessionKey = app.globalData.initLoginInfo?.sessionKey || ''
// 患者微信登录/注册
const params: any = {
sessionKey,
encryptedData,
iv,
}
// 如果有扫码参数,传入
if (this.data.pharmacistId) {
params.pharmacistId = Number.parseInt(this.data.pharmacistId)
}
if (this.data.projectId) {
params.projectId = this.data.projectId
}
1 week ago
wx.ajax({
method: 'POST',
url: '/app/patient/patient/wx-login',
data: params,
}).then((res: any) => {
const jumpUrl = res.jumpUrl
// 如果有药师ID,创建绑定关系
if (this.data.pharmacistId) {
wx.ajax({
method: 'POST',
url: '/app/patient/patient/bind-pharmacist',
data: {
pharmacistId: Number.parseInt(this.data.pharmacistId),
1 week ago
projectId: this.data.projectId,
indicationId: selectedOption.indicationId,
},
}).then(() => {
// 绑定成功后跳转
1 week ago
wx.navigateToMiniProgram({
appId: 'wx05551c5ee1fd1c12',
path: jumpUrl,
})
this.checkStatus()
})
} else {
// 没有药师ID,直接跳转
wx.navigateToMiniProgram({
appId: 'wx05551c5ee1fd1c12',
path: jumpUrl,
success: () => {
this.checkStatus()
},
})
}
})
}
},
1 month ago
toggleAgreement() {
this.setData({
agreementChecked: !this.data.agreementChecked,
1 month ago
})
},
handleAgreement() {
wx.navigateTo({
url: '/privacy/pages/policy/index',
})
},
handleWork() {
1 month ago
wx.navigateTo({
url: '/pages/work/index',
1 month ago
})
},
handleJump() {
// 跳转到腾讯药箱小程序
wx.navigateToMiniProgram({
appId: 'wx05551c5ee1fd1c12',
path: '',
})
},
onShareAppMessage() {
return {
title: '华观健康',
path: '/pages/index/index',
1 month ago
}
},
})