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.
173 lines
4.9 KiB
173 lines
4.9 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
id: 0, |
|
visitDate: '', |
|
nextVisitDate: '', |
|
displayIgG4Value: '' as string | number | null, |
|
medicationsLabel: '', |
|
oralHormoneDosageMg: '' as string | number | null, |
|
immunosuppressantLabel: '', |
|
reminderEnabled: 2, |
|
imageGroups: [] as { type: string; label: string; list: string[] }[], |
|
change: 0, |
|
|
|
// 枚举 |
|
medicationsMap: {} as Record<number, string>, |
|
immunosuppressantMap: {} as Record<number, string>, |
|
imageTypeLabels: {} as Record<string, string>, |
|
}, |
|
|
|
onLoad(options: any) { |
|
app.waitLogin().then(() => { |
|
app.mpBehavior({ PageName: 'PG_PatientRecordDetail', detailId: String(options.id) }) |
|
this.getEnums().then(() => { |
|
if (options.id) { |
|
this.setData({ id: Number(options.id) }) |
|
this.getDetail() |
|
this.getReminderConfig() |
|
} |
|
}) |
|
}) |
|
}, |
|
onShow() { |
|
if (typeof this.__loaded === 'undefined') { |
|
this.__loaded = true |
|
return |
|
} |
|
this.getDetail() |
|
this.getReminderConfig() |
|
}, |
|
|
|
// ========== API ========== |
|
|
|
getEnums(): Promise<void> { |
|
return wx |
|
.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/medical-visit/get-enums', |
|
}) |
|
.then((res: any) => { |
|
if (!res) return |
|
const medicationsMap: Record<number, string> = {} |
|
for (const item of res.medicationsUsed || []) { |
|
medicationsMap[item.value] = item.label |
|
} |
|
const immunosuppressantMap: Record<number, string> = {} |
|
for (const item of res.immunosuppressantName || []) { |
|
immunosuppressantMap[item.value] = item.label |
|
} |
|
const imageTypeLabels: Record<string, string> = {} |
|
for (const item of res.imageType || []) { |
|
imageTypeLabels[item.value] = item.label |
|
} |
|
this.setData({ medicationsMap, immunosuppressantMap, imageTypeLabels }) |
|
}) |
|
}, |
|
|
|
getDetail() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/medical-visit/detail', |
|
data: { id: this.data.id }, |
|
}).then((res: any) => { |
|
if (!res) return |
|
const { medicationsMap, immunosuppressantMap, imageTypeLabels } = this.data |
|
const medicationsLabel = (res.medicationsUsed || []) |
|
.map((id: number) => { |
|
if (id === 99 && res.medicationsUsedOtherText) return `其他:${res.medicationsUsedOtherText}` |
|
if (id === 99) return '' |
|
return medicationsMap[id] |
|
}) |
|
.filter(Boolean) |
|
.join('、') |
|
const immunosuppressantLabel = (res.immunosuppressantName || []) |
|
.map((id: number) => { |
|
if (id === 99 && res.immunosuppressantNameOtherText) return `其他:${res.immunosuppressantNameOtherText}` |
|
if (id === 99) return '' |
|
return immunosuppressantMap[id] |
|
}) |
|
.filter(Boolean) |
|
.join('、') |
|
|
|
const imageGroups: { type: string; label: string; list: string[] }[] = [] |
|
const images = res.images || {} |
|
for (const type of Object.keys(imageTypeLabels)) { |
|
const list = (images[type] || []).map((img: any) => img.maskedImageUrl || img.imageUrl) |
|
if (list.length) { |
|
imageGroups.push({ type, label: imageTypeLabels[type], list }) |
|
} |
|
} |
|
|
|
this.setData({ |
|
visitDate: res.visitDate || '', |
|
nextVisitDate: res.nextVisitDate || '', |
|
displayIgG4Value: res.displayIgG4Value, |
|
medicationsLabel, |
|
oralHormoneDosageMg: res.oralHormoneDosageMg, |
|
immunosuppressantLabel, |
|
imageGroups, |
|
change: res.change, |
|
}) |
|
}) |
|
}, |
|
|
|
getReminderConfig() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/medical-visit/get-reminder-config', |
|
}).then((res: any) => { |
|
if (!res) return |
|
this.setData({ reminderEnabled: res.reminderEnabled || 2 }) |
|
}) |
|
}, |
|
|
|
saveReminderConfig(e: any) { |
|
const val = e.detail.value ? 1 : 2 |
|
this.setData({ reminderEnabled: val }) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=igg4/medical-visit/save-reminder-config', |
|
data: { reminderEnabled: val }, |
|
}) |
|
}, |
|
|
|
// ========== 操作 ========== |
|
|
|
handleDelete() { |
|
wx.showModal({ |
|
title: `删除${this.data.visitDate || ''}记录`, |
|
content: `删除后将无法恢复`, |
|
confirmText: '确认删除', |
|
confirmColor: '#ee0a24', |
|
success: (res) => { |
|
if (!res.confirm) return |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=igg4/medical-visit/delete', |
|
data: { id: this.data.id }, |
|
}).then((res: any) => { |
|
if (!res) return |
|
wx.navigateBack() |
|
}) |
|
}, |
|
}) |
|
}, |
|
|
|
handleEdit() { |
|
wx.navigateTo({ url: `/gift/pages/record/index?id=${this.data.id}` }) |
|
}, |
|
|
|
handlePreviewImage(e: any) { |
|
const { url, type } = e.currentTarget.dataset |
|
const group = this.data.imageGroups.find((g) => g.type === type) |
|
if (!group) return |
|
wx.previewImage({ |
|
current: url, |
|
urls: group.list, |
|
}) |
|
}, |
|
}) |
|
|
|
export {}
|
|
|