武田小程序
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.

409 lines
9.5 KiB

8 months ago
import Toast from "@vant/weapp/toast/toast";
8 months ago
const app = getApp<IAppOption>();
Page({
data: {
show1: false,
show2: false,
8 months ago
8 months ago
isInvite: false,
8 months ago
deptList: [] as any,
labelList: [] as any,
8 months ago
images: [] as any,
description: "",
audios: [] as any,
8 months ago
files: [] as any,
8 months ago
deptId: "",
labelIds: [] as any,
8 months ago
DoctorLevel: 1,
8 months ago
caseId: "",
8 months ago
edit: true,
DeleteAttachmentIds: [] as any,
8 months ago
},
8 months ago
onLoad(options) {
app.waitLogin().then(async () => {
8 months ago
this.getVisit();
8 months ago
this.getInviteDoctorList();
app.getUserInfo(this, (res) => {
this.setData({
DoctorLevel: res.DoctorLevel,
});
});
await this.getDoctorDict();
8 months ago
if (options.id) {
this.setData({
caseId: options.id,
});
this.getDetail();
}
});
},
8 months ago
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: {},
});
},
8 months ago
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,
8 months ago
deptId: res.caseDeptId[0] || "",
8 months ago
labelIds: res.caseLabels.map((item) => item.labelId),
labelList: this.data.deptList.find((item) => item.value === res.caseDeptId[0])?.options || [],
8 months ago
});
8 months ago
});
},
getDoctorDict() {
return wx
.ajax({
method: "GET",
url: "?r=takeda/reg/doctor-dict",
data: {},
})
.then((res) => {
this.setData({
deptList: res.DoctorSpecialtyLabel,
});
8 months ago
});
},
8 months ago
getInviteDoctorList() {
wx.ajax({
method: "GET",
url: "?r=takeda/case/get-invite-doctor-list",
data: {},
}).then((res) => {
this.setData({
isInvite: Boolean(res.list.length),
});
8 months ago
});
},
handlePhoto(e) {
const detail = e.detail;
8 months ago
const { images, edit } = this.data;
if (edit) {
this.postVisit();
this.setData({
edit: false,
});
}
8 months ago
this.setData({
images: [
...images,
{
name: detail.name,
url: detail.fileUrl,
isRepeat: 2,
8 months ago
hash: "",
8 months ago
},
],
});
this.imageVerify(detail.fileUrl);
8 months ago
},
handleDelPhoto(e: any) {
8 months ago
const { index } = e.currentTarget.dataset;
const { images, DeleteAttachmentIds } = this.data;
if (images[index].attachmentId) {
DeleteAttachmentIds.push(images[index].attachmentId);
}
8 months ago
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,
});
8 months ago
});
},
handleAudio(e) {
this.setData({
audios: [
...this.data.audios,
{
name: e.detail.name,
url: e.detail.fileUrl,
duration: e.detail.duration,
isRepeat: 2,
},
],
});
9 months ago
},
8 months ago
handleDelAudio(e) {
8 months ago
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)),
});
}
},
8 months ago
});
},
handleFile(e) {
this.setData({
files: [
...this.data.files,
{
8 months ago
fileType: e.detail.fileType,
8 months ago
name: e.detail.name,
url: e.detail.fileUrl,
size: e.detail.size,
isRepeat: 2,
8 months ago
videoUrl: e.detail.videoUrl,
duration: e.detail.duration,
8 months ago
},
],
});
},
8 months ago
handleDelFile(e) {
8 months ago
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)),
});
}
},
8 months ago
});
},
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,
8 months ago
showMenu: true,
8 months ago
fail() {
wx.showToast({
title: "该文件无法预览",
icon: "none",
});
},
});
},
});
},
8 months ago
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: "关闭",
});
},
8 months ago
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,
});
},
});
}
},
});
},
8 months ago
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];
8 months ago
this.setData({
labelIds: newLabelId,
});
},
8 months ago
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() {
8 months ago
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;
}
8 months ago
const params = this.formatParams();
8 months ago
const url = caseId ? "?r=takeda/case/save-case" : "?r=takeda/case/create-case";
8 months ago
wx.ajax({
method: "POST",
8 months ago
url,
8 months ago
data: {
...params,
8 months ago
isSubmit: 0,
caseId,
8 months ago
},
}).then(() => {
wx.navigateBack();
});
},
handleInvite() {
const params = this.formatParams();
8 months ago
const { deptId, labelIds, images } = this.data;
8 months ago
if (images.length === 0) {
wx.showToast({
8 months ago
title: "请上传病历图片",
8 months ago
icon: "none",
});
return;
}
8 months ago
if (deptId && !labelIds.length) {
wx.showToast({
title: "请选择标签",
icon: "none",
});
return;
}
8 months ago
wx.navigateTo({
url: `/module1/pages/setCaseDoctor/index`,
8 months ago
success: (res) => {
8 months ago
res.eventChannel.emit("acceptDataFromOpenerPage", {
8 months ago
caseId: this.data.caseId,
8 months ago
params,
});
},
});
},
8 months ago
handleNoInvite() {
Toast("您还没有合作医生,无法邀请医生讨论病历,可暂时存为草稿");
},
8 months ago
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;
}
8 months ago
wx.showModal({
8 months ago
confirmColor: "#00B4C5",
cancelColor: "#141515",
8 months ago
title: "您的病历还未保存,是否要存为草稿?",
confirmText: "存为草稿",
8 months ago
cancelText: "退出",
8 months ago
success: (res) => {
if (res.confirm) {
this.handleCache();
} else {
wx.navigateBack();
}
},
});
},
8 months ago
});
8 months ago
export {};