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.
408 lines
9.5 KiB
408 lines
9.5 KiB
import Toast from "@vant/weapp/toast/toast"; |
|
const app = getApp<IAppOption>(); |
|
|
|
Page({ |
|
data: { |
|
show1: false, |
|
show2: false, |
|
|
|
isInvite: false, |
|
|
|
deptList: [] as any, |
|
labelList: [] as any, |
|
|
|
images: [] as any, |
|
description: "", |
|
audios: [] as any, |
|
files: [] as any, |
|
deptId: "", |
|
labelIds: [] as any, |
|
|
|
DoctorLevel: 1, |
|
|
|
caseId: "", |
|
|
|
edit: true, |
|
DeleteAttachmentIds: [] as any, |
|
}, |
|
onLoad(options) { |
|
app.waitLogin().then(async () => { |
|
this.getVisit(); |
|
this.getInviteDoctorList(); |
|
app.getUserInfo(this, (res) => { |
|
this.setData({ |
|
DoctorLevel: res.DoctorLevel, |
|
}); |
|
}); |
|
await this.getDoctorDict(); |
|
if (options.id) { |
|
this.setData({ |
|
caseId: options.id, |
|
}); |
|
this.getDetail(); |
|
} |
|
}); |
|
}, |
|
getVisit() { |
|
wx.ajax({ |
|
method: "GET", |
|
url: "?r=takeda/case/is-visit", |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
edit: res === 2, |
|
}); |
|
}); |
|
}, |
|
postVisit() { |
|
wx.ajax({ |
|
method: "POST", |
|
url: "?r=takeda/case/visit", |
|
data: {}, |
|
}); |
|
}, |
|
getDetail() { |
|
wx.ajax({ |
|
method: "GET", |
|
url: "?r=takeda/case/get-case-detail", |
|
data: { |
|
caseId: this.data.caseId, |
|
}, |
|
}).then((res) => { |
|
this.setData({ |
|
images: res.caseImages, |
|
description: res.description, |
|
audios: res.caseAudios, |
|
files: res.caseFiles, |
|
deptId: res.caseDeptId[0] || "", |
|
labelIds: res.caseLabels.map((item) => item.labelId), |
|
labelList: this.data.deptList.find((item) => item.value === res.caseDeptId[0])?.options || [], |
|
}); |
|
}); |
|
}, |
|
getDoctorDict() { |
|
return wx |
|
.ajax({ |
|
method: "GET", |
|
url: "?r=takeda/reg/doctor-dict", |
|
data: {}, |
|
}) |
|
.then((res) => { |
|
this.setData({ |
|
deptList: res.DoctorSpecialtyLabel, |
|
}); |
|
}); |
|
}, |
|
getInviteDoctorList() { |
|
wx.ajax({ |
|
method: "GET", |
|
url: "?r=takeda/case/get-invite-doctor-list", |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
isInvite: Boolean(res.list.length), |
|
}); |
|
}); |
|
}, |
|
handlePhoto(e) { |
|
const detail = e.detail; |
|
const { images, edit } = this.data; |
|
if (edit) { |
|
this.postVisit(); |
|
this.setData({ |
|
edit: false, |
|
}); |
|
} |
|
this.setData({ |
|
images: [ |
|
...images, |
|
{ |
|
name: detail.name, |
|
url: detail.fileUrl, |
|
isRepeat: 2, |
|
hash: "", |
|
}, |
|
], |
|
}); |
|
this.imageVerify(detail.fileUrl); |
|
}, |
|
handleDelPhoto(e: any) { |
|
const { index } = e.currentTarget.dataset; |
|
const { images, DeleteAttachmentIds } = this.data; |
|
if (images[index].attachmentId) { |
|
DeleteAttachmentIds.push(images[index].attachmentId); |
|
} |
|
this.setData({ |
|
images: this.data.images.filter((_, i) => i !== Number(index)), |
|
DeleteAttachmentIds, |
|
}); |
|
}, |
|
imageVerify(url: string) { |
|
const { images, DeleteAttachmentIds } = this.data; |
|
const LastImagesHash: any = []; |
|
images.forEach((item) => { |
|
if (item.hash) { |
|
LastImagesHash.push(item.hash); |
|
} |
|
}); |
|
wx.ajax({ |
|
method: "POST", |
|
url: "?r=takeda/common/image-verify", |
|
data: { |
|
ImageUrl: url, |
|
LastImagesHash, |
|
DeleteAttachmentIds, |
|
}, |
|
}).then((res) => { |
|
const index = images.findIndex((item) => item.url === url); |
|
const imageItem = images[index]; |
|
if (res.Hash) { |
|
imageItem.hash = res.Hash; |
|
} |
|
if (res.code === 1001) { |
|
wx.showToast({ |
|
title: res.msg, |
|
icon: "none", |
|
}); |
|
imageItem.repeat = true; |
|
} |
|
this.setData({ |
|
images, |
|
}); |
|
}); |
|
}, |
|
handleAudio(e) { |
|
this.setData({ |
|
audios: [ |
|
...this.data.audios, |
|
{ |
|
name: e.detail.name, |
|
url: e.detail.fileUrl, |
|
duration: e.detail.duration, |
|
isRepeat: 2, |
|
}, |
|
], |
|
}); |
|
}, |
|
handleDelAudio(e) { |
|
wx.showModal({ |
|
title: "确认删除?", |
|
confirmColor: "#00B4C5", |
|
cancelColor: "#141515", |
|
success: (res) => { |
|
if (res.confirm) { |
|
const { index } = e.currentTarget.dataset; |
|
this.setData({ |
|
audios: this.data.audios.filter((_, i) => i !== Number(index)), |
|
}); |
|
} |
|
}, |
|
}); |
|
}, |
|
handleFile(e) { |
|
this.setData({ |
|
files: [ |
|
...this.data.files, |
|
{ |
|
fileType: e.detail.fileType, |
|
name: e.detail.name, |
|
url: e.detail.fileUrl, |
|
size: e.detail.size, |
|
isRepeat: 2, |
|
videoUrl: e.detail.videoUrl, |
|
duration: e.detail.duration, |
|
}, |
|
], |
|
}); |
|
}, |
|
handleDelFile(e) { |
|
wx.showModal({ |
|
title: "确认删除?", |
|
confirmColor: "#00B4C5", |
|
cancelColor: "#141515", |
|
success: (res) => { |
|
if (res.confirm) { |
|
const { index } = e.currentTarget.dataset; |
|
this.setData({ |
|
files: this.data.files.filter((_, i) => i !== Number(index)), |
|
}); |
|
} |
|
}, |
|
}); |
|
}, |
|
handlePreviewFile(e) { |
|
const { index } = e.currentTarget.dataset; |
|
const item = this.data.files[index]; |
|
wx.downloadFile({ |
|
url: item.url, |
|
success(res) { |
|
wx.openDocument({ |
|
filePath: res.tempFilePath, |
|
showMenu: true, |
|
fail() { |
|
wx.showToast({ |
|
title: "该文件无法预览", |
|
icon: "none", |
|
}); |
|
}, |
|
}); |
|
}, |
|
}); |
|
}, |
|
handlePreviewName(e) { |
|
const { index } = e.currentTarget.dataset; |
|
const item = this.data.files[index]; |
|
wx.showModal({ |
|
title: "文件名", |
|
content: item.name, |
|
confirmColor: "#00B4C5", |
|
cancelColor: "#141515", |
|
showCancel: false, |
|
confirmText: "关闭", |
|
}); |
|
}, |
|
handleDownloadFile(e) { |
|
const { index } = e.currentTarget.dataset; |
|
const item = this.data.files[index]; |
|
wx.downloadFile({ |
|
url: item.url, |
|
success(res) { |
|
if (res.statusCode === 200) { |
|
wx.hideLoading(); |
|
const tempFilePath = res.tempFilePath; |
|
const FileSystemManager = wx.getFileSystemManager(); |
|
FileSystemManager.saveFile({ |
|
tempFilePath, |
|
success() { |
|
wx.showToast({ |
|
title: "下载成功", |
|
icon: "none", |
|
mask: true, |
|
}); |
|
}, |
|
fail() { |
|
wx.showToast({ |
|
title: "下载失败,请重新尝试", |
|
icon: "none", |
|
mask: true, |
|
}); |
|
}, |
|
}); |
|
} |
|
}, |
|
}); |
|
}, |
|
handleDept(e) { |
|
const { params } = e.currentTarget.dataset; |
|
this.setData({ |
|
deptId: params.value, |
|
labelList: params.options, |
|
labelIds: [], |
|
}); |
|
}, |
|
handleLabel(e) { |
|
const { params } = e.currentTarget.dataset; |
|
const labelIds = this.data.labelIds; |
|
const newLabelId = labelIds.includes(params.value) |
|
? labelIds.filter((item: any) => item !== params.value) |
|
: [...labelIds, params.value]; |
|
this.setData({ |
|
labelIds: newLabelId, |
|
}); |
|
}, |
|
|
|
formatParams() { |
|
const { images, description, audios, files, deptId, labelIds } = this.data; |
|
return { |
|
images: JSON.stringify(images), |
|
description, |
|
audios: JSON.stringify(audios), |
|
files: JSON.stringify(files), |
|
deptId, |
|
labelIds: JSON.stringify(labelIds), |
|
}; |
|
}, |
|
onClose() { |
|
this.setData({ |
|
show1: false, |
|
}); |
|
}, |
|
handleCache() { |
|
const { caseId, images, description, audios, files, deptId, labelIds } = this.data; |
|
if (!images.length && !description && !audios.length && !files.length && !deptId && !labelIds.length) { |
|
wx.showToast({ |
|
title: "请完善信息", |
|
icon: "none", |
|
}); |
|
return; |
|
} |
|
const params = this.formatParams(); |
|
const url = caseId ? "?r=takeda/case/save-case" : "?r=takeda/case/create-case"; |
|
wx.ajax({ |
|
method: "POST", |
|
url, |
|
data: { |
|
...params, |
|
isSubmit: 0, |
|
caseId, |
|
}, |
|
}).then(() => { |
|
wx.navigateBack(); |
|
}); |
|
}, |
|
handleInvite() { |
|
const params = this.formatParams(); |
|
const { deptId, labelIds, images } = this.data; |
|
if (images.length === 0) { |
|
wx.showToast({ |
|
title: "请上传病历图片", |
|
icon: "none", |
|
}); |
|
return; |
|
} |
|
if (deptId && !labelIds.length) { |
|
wx.showToast({ |
|
title: "请选择标签", |
|
icon: "none", |
|
}); |
|
return; |
|
} |
|
wx.navigateTo({ |
|
url: `/module1/pages/setCaseDoctor/index`, |
|
success: (res) => { |
|
res.eventChannel.emit("acceptDataFromOpenerPage", { |
|
caseId: this.data.caseId, |
|
params, |
|
}); |
|
}, |
|
}); |
|
}, |
|
handleNoInvite() { |
|
Toast("您还没有合作医生,无法邀请医生讨论病历,可暂时存为草稿"); |
|
}, |
|
handleSave() {}, |
|
handleSubmit() {}, |
|
handleBack() { |
|
const { images, description, audios, files, deptId, labelIds } = this.data; |
|
if (!images.length && !description && !audios.length && !files.length && !deptId && !labelIds.length) { |
|
wx.navigateBack() |
|
return; |
|
} |
|
wx.showModal({ |
|
confirmColor: "#00B4C5", |
|
cancelColor: "#141515", |
|
title: "您的病历还未保存,是否要存为草稿?", |
|
confirmText: "存为草稿", |
|
cancelText: "退出", |
|
success: (res) => { |
|
if (res.confirm) { |
|
this.handleCache(); |
|
} else { |
|
wx.navigateBack(); |
|
} |
|
}, |
|
}); |
|
}, |
|
}); |
|
|
|
export {};
|
|
|