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.
435 lines
12 KiB
435 lines
12 KiB
import dayjs from 'dayjs' |
|
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
// 项目列表 |
|
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, |
|
currentProjectId: 0, |
|
currentProjectName: '', |
|
projectIndex: 0, |
|
|
|
// 搜索关键词 |
|
keyword: '', |
|
|
|
// 筛选条件 |
|
jumpStatus: '', // ''-全部,0-未跳转,1-已跳转 |
|
jumpStatusIndex: 0, // picker 选中索引 |
|
jumpStatusLabel: '全部', |
|
jumpStatusOptions: [ |
|
{ value: '', label: '全部' }, |
|
{ value: 0, label: '未跳转' }, |
|
{ value: 1, label: '已跳转' }, |
|
] as Array<{ value: string | number; label: string }>, |
|
enrollStatus: '', // ''-全部,0-未入组,1-已入组 |
|
enrollStatusIndex: 0, // picker 选中索引 |
|
enrollStatusLabel: '全部', |
|
enrollStatusOptions: [ |
|
{ value: '', label: '全部' }, |
|
{ value: 0, label: '未入组' }, |
|
{ value: 1, label: '已入组' }, |
|
] as Array<{ value: string | number; label: string }>, |
|
|
|
jumpStartTime: '', |
|
jumpEndTime: '', |
|
enrollStartTime: '', |
|
enrollEndTime: '', |
|
today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器 |
|
|
|
// 患者列表 |
|
patientList: [] as any[], |
|
totalCount: 0, |
|
|
|
// 分页 |
|
page: 1, |
|
pageSize: 20, |
|
loading: false, |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
|
|
// 弹窗 |
|
popupShow: false, |
|
popupType: '', |
|
popupParams: {}, |
|
}, |
|
onLoad() { |
|
// 药店端患者列表页面,仅允许药店人员访问 |
|
app.waitLogin({ types: [4] }).then(() => { |
|
this.getProjectList() |
|
}) |
|
}, |
|
// 获取项目列表 |
|
getProjectList() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '/app/pharmacist/pharmacist/project-list', |
|
}) |
|
.then((res: any) => { |
|
const list = res.list || [] |
|
const currentProjectId = res.currentProjectId || (list.length > 0 ? list[0].projectId : 0) |
|
const currentProject = list.find((p: any) => p.projectId === currentProjectId) |
|
|
|
this.setData({ |
|
projectList: list, |
|
currentProjectId, |
|
currentProjectName: currentProject?.projectName || '', |
|
projectIndex: list.findIndex((p: any) => p.projectId === currentProjectId), |
|
}) |
|
|
|
// 获取患者列表 |
|
this.getPatientList() |
|
}) |
|
.catch(() => { |
|
// 接口失败,使用默认数据 |
|
this.getPatientList() |
|
}) |
|
}, |
|
// 切换项目 |
|
onProjectChange(e: WechatMiniprogram.CustomEvent) { |
|
const index = e.detail.value |
|
const project = this.data.projectList[index] |
|
if (!project || project.projectId === this.data.currentProjectId) return |
|
|
|
// 调用切换项目接口 |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '/app/pharmacist/pharmacist/switch-project', |
|
data: { |
|
projectId: project.projectId, |
|
}, |
|
}) |
|
.then(() => { |
|
this.setData({ |
|
currentProjectId: project.projectId, |
|
currentProjectName: project.projectName, |
|
projectIndex: index, |
|
// 重置患者列表 |
|
patientList: [], |
|
page: 1, |
|
hasMore: true, |
|
}) |
|
// 刷新患者列表 |
|
this.getPatientList() |
|
}) |
|
.catch(() => { |
|
wx.showToast({ |
|
title: '切换项目失败', |
|
icon: 'none', |
|
}) |
|
}) |
|
}, |
|
// 获取患者列表 |
|
getPatientList() { |
|
if (this.data.loading || !this.data.hasMore) return |
|
|
|
this.setData({ loading: true }) |
|
|
|
// 同时传递跳转时间和入组时间(如果有值) |
|
const { jumpStartTime, jumpEndTime, enrollStartTime, enrollEndTime, jumpStatus, enrollStatus } = this.data |
|
const params: any = { |
|
keyword: this.data.keyword, |
|
page: this.data.page, |
|
pageSize: this.data.pageSize, |
|
} |
|
|
|
// 跳转状态:空字符串表示全部,不传递参数 |
|
if (jumpStatus !== '') { |
|
params.jumpStatus = jumpStatus |
|
} |
|
|
|
// 入组状态:空字符串表示全部,不传递参数 |
|
if (enrollStatus !== '') { |
|
params.enrollStatus = enrollStatus |
|
} |
|
|
|
// 跳转时间 |
|
if (jumpStartTime) params.jumpStartTime = jumpStartTime |
|
if (jumpEndTime) params.jumpEndTime = jumpEndTime |
|
|
|
// 入组时间 |
|
if (enrollStartTime) params.enrollStartTime = enrollStartTime |
|
if (enrollEndTime) params.enrollEndTime = enrollEndTime |
|
|
|
wx.ajax({ |
|
method: 'GET', |
|
url: '/app/pharmacist/pharmacist/patient-list', |
|
data: params, |
|
}) |
|
.then((res: any) => { |
|
const list = (res.list || []).map((item: any) => ({ |
|
...item, |
|
bindTimeFormatted: item.bindTime || '-', |
|
jumpTimeFormatted: item.jumpMaterial.updateTime |
|
? dayjs(item.jumpMaterial.updateTime).format('YYYY-MM-DD HH:mm') |
|
: '', |
|
enrollTimeFormatted: item.enrollMaterial.updateTime |
|
? dayjs(item.enrollMaterial.updateTime).format('YYYY-MM-DD HH:mm') |
|
: '', |
|
// 跳转材料审核状态 |
|
jumpAuditStatus: item.jumpMaterial?.auditStatus ?? -1, |
|
jumpAuditStatusText: item.jumpMaterial?.auditStatusText || '', |
|
jumpRejectReason: item.jumpMaterial?.rejectReason || '', |
|
// 入组材料审核状态 |
|
enrollAuditStatus: item.enrollMaterial?.auditStatus ?? -1, |
|
enrollAuditStatusText: item.enrollMaterial?.auditStatusText || '', |
|
enrollRejectReason: item.enrollMaterial?.rejectReason || '', |
|
})) |
|
const total = res.total || 0 |
|
const currentPage = this.data.page |
|
|
|
this.setData({ |
|
patientList: this.data.page === 1 ? list : [...this.data.patientList, ...list], |
|
totalCount: total, |
|
page: currentPage + 1, |
|
hasMore: list.length >= this.data.pageSize, |
|
loading: false, |
|
pagination: { |
|
count: total, |
|
page: currentPage, |
|
pages: Math.ceil(total / this.data.pageSize) || 1, |
|
}, |
|
}) |
|
}) |
|
.catch(() => { |
|
this.setData({ loading: false }) |
|
}) |
|
}, |
|
// 格式化日期 |
|
formatDate(timestamp: number): string { |
|
const date = new Date(timestamp * 1000) |
|
const year = date.getFullYear() |
|
const month = String(date.getMonth() + 1).padStart(2, '0') |
|
const day = String(date.getDate()).padStart(2, '0') |
|
const hours = String(date.getHours()).padStart(2, '0') |
|
const minutes = String(date.getMinutes()).padStart(2, '0') |
|
const seconds = String(date.getSeconds()).padStart(2, '0') |
|
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}` |
|
}, |
|
// 搜索患者 |
|
handleSearch(e: WechatMiniprogram.CustomEvent) { |
|
this.setData({ |
|
keyword: e.detail.value, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 跳转状态筛选 |
|
handleJumpStatusChange(e: WechatMiniprogram.CustomEvent) { |
|
const index = e.detail.value |
|
const option = this.data.jumpStatusOptions[index] |
|
this.setData({ |
|
jumpStatus: String(option.value), |
|
jumpStatusIndex: index, |
|
jumpStatusLabel: option.label, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 入组状态筛选 |
|
handleEnrollStatusChange(e: WechatMiniprogram.CustomEvent) { |
|
const index = e.detail.value |
|
const option = this.data.enrollStatusOptions[index] |
|
this.setData({ |
|
enrollStatus: String(option.value), |
|
enrollStatusIndex: index, |
|
enrollStatusLabel: option.label, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 跳转开始时间选择 |
|
handleJumpStartTimeChange(e: WechatMiniprogram.CustomEvent) { |
|
const jumpStartTime = e.detail.value |
|
if (this.data.jumpEndTime && jumpStartTime > this.data.jumpEndTime) { |
|
wx.showToast({ |
|
title: '开始时间不能大于结束时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
this.setData({ |
|
jumpStartTime, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 跳转结束时间选择 |
|
handleJumpEndTimeChange(e: WechatMiniprogram.CustomEvent) { |
|
const jumpEndTime = e.detail.value |
|
if (this.data.jumpStartTime && jumpEndTime < this.data.jumpStartTime) { |
|
wx.showToast({ |
|
title: '结束时间不能小于开始时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
this.setData({ |
|
jumpEndTime, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 入组开始时间选择 |
|
handleEnrollStartTimeChange(e: WechatMiniprogram.CustomEvent) { |
|
const enrollStartTime = e.detail.value |
|
if (this.data.enrollEndTime && enrollStartTime > this.data.enrollEndTime) { |
|
wx.showToast({ |
|
title: '开始时间不能大于结束时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
this.setData({ |
|
enrollStartTime, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 入组结束时间选择 |
|
handleEnrollEndTimeChange(e: WechatMiniprogram.CustomEvent) { |
|
const enrollEndTime = e.detail.value |
|
if (this.data.enrollStartTime && enrollEndTime < this.data.enrollStartTime) { |
|
wx.showToast({ |
|
title: '结束时间不能小于开始时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
this.setData({ |
|
enrollEndTime, |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 页面上拉触底事件 |
|
onReachBottom() { |
|
if (this.data.loading || !this.data.hasMore) { |
|
return |
|
} |
|
this.getPatientList() |
|
}, |
|
// 预览提交的材料图片 |
|
handlePreviewMaterial(e: WechatMiniprogram.CustomEvent) { |
|
const { url } = e.currentTarget.dataset |
|
if (!url) { |
|
wx.showToast({ |
|
title: '暂无图片', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
wx.previewImage({ |
|
urls: [url], |
|
current: url, |
|
}) |
|
}, |
|
// 上传材料 |
|
handleUpload(e: WechatMiniprogram.CustomEvent) { |
|
const { id, type } = e.currentTarget.dataset |
|
// 查找患者信息 |
|
const patient = this.data.patientList.find((p: any) => p.id === id) |
|
if (!patient) return |
|
|
|
// 根据点击的按钮判断是跳转材料还是入组材料 |
|
const isJumpMaterial = type === 'jump' |
|
const auditType = isJumpMaterial ? 1 : 2 |
|
const title = isJumpMaterial ? '上传跳转证明材料' : '上传入组证明材料' |
|
|
|
this.setData({ |
|
popupShow: true, |
|
popupType: 'uploadMaterial', |
|
popupParams: { |
|
patientId: patient.patientId, |
|
patientName: patient.patientName, |
|
phone: patient.phone, |
|
projectName: this.data.currentProjectName, |
|
indicationName: patient.indicationName, |
|
auditType, |
|
title, |
|
}, |
|
}) |
|
}, |
|
// 弹窗确认 |
|
handlePopupOk(e: WechatMiniprogram.CustomEvent) { |
|
const { detail } = e |
|
|
|
// 处理上传材料完成 |
|
if (detail && detail.type === 'uploadMaterialComplete') { |
|
const { patientId, auditType, imageUrl } = detail |
|
|
|
wx.showLoading({ title: '提交中...' }) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '/app/pharmacist/pharmacist/submit-material', |
|
data: { |
|
patientId, |
|
imageUrl, |
|
auditType, |
|
}, |
|
}) |
|
.then(() => { |
|
wx.hideLoading() |
|
wx.showToast({ |
|
title: '提交成功', |
|
icon: 'success', |
|
}) |
|
this.setData({ |
|
popupShow: false, |
|
}) |
|
// 刷新列表 |
|
this.setData({ |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}) |
|
.catch(() => { |
|
wx.hideLoading() |
|
wx.showToast({ |
|
title: '提交失败', |
|
icon: 'none', |
|
}) |
|
}) |
|
return |
|
} |
|
|
|
// 其他弹窗类型处理 |
|
this.setData({ |
|
popupShow: false, |
|
}) |
|
// 刷新列表 |
|
this.setData({ |
|
page: 1, |
|
patientList: [], |
|
hasMore: true, |
|
}) |
|
this.getPatientList() |
|
}, |
|
// 弹窗取消 |
|
handlePopupCancel() { |
|
this.setData({ |
|
popupShow: false, |
|
}) |
|
}, |
|
}) |
|
|
|
export {}
|
|
|