|
|
|
|
@ -34,6 +34,9 @@ Page({
@@ -34,6 +34,9 @@ Page({
|
|
|
|
|
nickname: '', |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 是否已经换绑,防止死循环
|
|
|
|
|
hasBindPharmacist: false, |
|
|
|
|
|
|
|
|
|
onLoad() { |
|
|
|
|
const app = getApp<IAppOption>() |
|
|
|
|
|
|
|
|
|
@ -107,64 +110,161 @@ Page({
@@ -107,64 +110,161 @@ Page({
|
|
|
|
|
currentProjectId, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (projectList.length > 0) { |
|
|
|
|
// 找到当前项目
|
|
|
|
|
const currentProject = projectList.find((p: any) => p.projectId === currentProjectId) || projectList[0] |
|
|
|
|
|
|
|
|
|
// 检查扫码的项目是否在已绑定项目列表中
|
|
|
|
|
const scanProjectId = this.data.projectId |
|
|
|
|
if (scanProjectId) { |
|
|
|
|
const scanProject = projectList.find((p: any) => String(p.projectId) === String(scanProjectId)) |
|
|
|
|
if (scanProject) { |
|
|
|
|
// 扫码的项目已绑定,切换到该项目
|
|
|
|
|
if (String(scanProjectId) !== String(currentProjectId)) { |
|
|
|
|
this.switchProject(scanProjectId) |
|
|
|
|
} else { |
|
|
|
|
// 已经是当前项目,直接显示
|
|
|
|
|
this.setData({ |
|
|
|
|
isPatient: 1, |
|
|
|
|
projectId: currentProject.projectId, |
|
|
|
|
projectName: currentProject.projectName, |
|
|
|
|
currentProjectName: currentProject.projectName, |
|
|
|
|
hasProject: true, |
|
|
|
|
selectedIndicationName: currentProject.indicationName, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 扫码的项目未绑定,进入选择流程(需要绑定新项目)
|
|
|
|
|
this.setData({ |
|
|
|
|
hasProject: false, |
|
|
|
|
}) |
|
|
|
|
this.getProjectInfo() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 没有扫码,显示当前项目
|
|
|
|
|
this.setData({ |
|
|
|
|
isPatient: 1, |
|
|
|
|
projectId: currentProject.projectId, |
|
|
|
|
projectName: currentProject.projectName, |
|
|
|
|
currentProjectName: currentProject.projectName, |
|
|
|
|
hasProject: true, |
|
|
|
|
selectedIndicationName: currentProject.indicationName, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 没有绑定任何项目,获取项目列表供选择
|
|
|
|
|
this.setData({ |
|
|
|
|
hasProject: false, |
|
|
|
|
}) |
|
|
|
|
// 没有绑定任何项目,进入选择流程
|
|
|
|
|
if (projectList.length === 0) { |
|
|
|
|
this.setData({ hasProject: false }) |
|
|
|
|
this.getProjectInfo() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 找到当前项目
|
|
|
|
|
const currentProject = projectList.find((p: any) => p.projectId === currentProjectId) || projectList[0] |
|
|
|
|
const scanProjectId = this.data.projectId |
|
|
|
|
const scanPharmacistId = this.data.pharmacistId |
|
|
|
|
|
|
|
|
|
// 没有扫码,直接显示当前项目
|
|
|
|
|
if (!scanProjectId) { |
|
|
|
|
this.showCurrentProject(currentProject) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查找扫码的项目
|
|
|
|
|
const scanProject = projectList.find((p: any) => String(p.projectId) === String(scanProjectId)) |
|
|
|
|
|
|
|
|
|
// 扫码的项目未绑定,进入选择流程
|
|
|
|
|
if (!scanProject) { |
|
|
|
|
this.setData({ hasProject: false }) |
|
|
|
|
this.getProjectInfo() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 扫码的项目已绑定,处理换绑逻辑
|
|
|
|
|
this.handleBoundProject(scanProjectId, scanPharmacistId, scanProject, currentProjectId, currentProject) |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
// 接口失败,获取项目列表
|
|
|
|
|
this.setData({ |
|
|
|
|
hasProject: false, |
|
|
|
|
}) |
|
|
|
|
this.setData({ hasProject: false }) |
|
|
|
|
this.getProjectInfo() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 显示当前项目
|
|
|
|
|
showCurrentProject(currentProject: any) { |
|
|
|
|
this.setData({ |
|
|
|
|
isPatient: 1, |
|
|
|
|
projectId: currentProject.projectId, |
|
|
|
|
projectName: currentProject.projectName, |
|
|
|
|
currentProjectName: currentProject.projectName, |
|
|
|
|
hasProject: true, |
|
|
|
|
selectedIndicationName: currentProject.indicationName, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 处理已绑定的扫码项目
|
|
|
|
|
handleBoundProject( |
|
|
|
|
scanProjectId: string, |
|
|
|
|
scanPharmacistId: string, |
|
|
|
|
scanProject: any, |
|
|
|
|
currentProjectId: number, |
|
|
|
|
currentProject: any |
|
|
|
|
) { |
|
|
|
|
const isDifferentProject = String(scanProjectId) !== String(currentProjectId) |
|
|
|
|
const needBind = scanPharmacistId && !this.hasBindPharmacist |
|
|
|
|
|
|
|
|
|
// 需要换绑
|
|
|
|
|
if (needBind) { |
|
|
|
|
if (isDifferentProject) { |
|
|
|
|
// 当前项目与扫码项目不一致,先切换项目再绑定
|
|
|
|
|
this.switchProjectAndBind(scanProjectId, scanPharmacistId, scanProject.indicationId) |
|
|
|
|
} else { |
|
|
|
|
// 已经是当前项目,直接进行绑定
|
|
|
|
|
this.bindPharmacist(scanProjectId, scanPharmacistId, scanProject.indicationId) |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 只是切换项目
|
|
|
|
|
if (isDifferentProject) { |
|
|
|
|
this.switchProject(scanProjectId) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 已经是当前项目,直接显示
|
|
|
|
|
this.showCurrentProject(currentProject) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 换绑(建立新的绑定关系)
|
|
|
|
|
bindPharmacist(projectId: string, pharmacistId: string, indicationId: number) { |
|
|
|
|
// 设置标记,防止重复换绑
|
|
|
|
|
this.hasBindPharmacist = true |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '/app/patient/patient/bind-pharmacist', |
|
|
|
|
data: { |
|
|
|
|
projectId: Number(projectId), |
|
|
|
|
pharmacistId: Number(pharmacistId), |
|
|
|
|
indicationId, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.then(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '换绑成功', |
|
|
|
|
icon: 'success', |
|
|
|
|
}) |
|
|
|
|
// 刷新页面数据
|
|
|
|
|
this.checkStatus() |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '换绑失败', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
// 刷新页面数据
|
|
|
|
|
this.checkStatus() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换项目并绑定
|
|
|
|
|
switchProjectAndBind(projectId: string, pharmacistId: string, indicationId: number) { |
|
|
|
|
// 设置标记,防止重复换绑
|
|
|
|
|
this.hasBindPharmacist = true |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '/app/patient/patient/switch-project', |
|
|
|
|
data: { |
|
|
|
|
projectId, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
.then(() => { |
|
|
|
|
// 切换成功后进行绑定
|
|
|
|
|
return wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '/app/patient/patient/bind-pharmacist', |
|
|
|
|
data: { |
|
|
|
|
projectId: Number(projectId), |
|
|
|
|
pharmacistId: Number(pharmacistId), |
|
|
|
|
indicationId, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
.then(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '换绑成功', |
|
|
|
|
icon: 'success', |
|
|
|
|
}) |
|
|
|
|
// 刷新页面数据
|
|
|
|
|
this.checkStatus() |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
title: '操作失败', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
// 刷新页面数据
|
|
|
|
|
this.checkStatus() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 切换项目
|
|
|
|
|
switchProject(projectId: string) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
|