|
|
|
|
@ -1,29 +1,7 @@
@@ -1,29 +1,7 @@
|
|
|
|
|
import { debounce } from 'miniprogram-licia' |
|
|
|
|
const dayjs = require('dayjs') |
|
|
|
|
const _app = getApp<IAppOption>() |
|
|
|
|
|
|
|
|
|
const MEDICATIONS_OPTIONS = [ |
|
|
|
|
{ id: 1, label: '没有使用激素', active: false }, |
|
|
|
|
{ id: 2, label: '激素', active: false }, |
|
|
|
|
{ id: 3, label: '免疫抑制剂', active: false }, |
|
|
|
|
{ id: 4, label: '靶向CD19生物制剂(伊奈利珠单抗)', active: false }, |
|
|
|
|
{ id: 5, label: '靶向CD20生物制剂(利妥昔单抗等)', active: false }, |
|
|
|
|
{ id: 99, label: '其他', active: false }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const IMMUNOSUPPRESSANT_OPTIONS = [ |
|
|
|
|
{ id: 1, label: '吗替麦考酚酯(骁悉、麦考芬)', active: false }, |
|
|
|
|
{ id: 2, label: '替唑嘌呤', active: false }, |
|
|
|
|
{ id: 3, label: '环磷酰胺', active: false }, |
|
|
|
|
{ id: 4, label: '来氟米特', active: false }, |
|
|
|
|
{ id: 5, label: '甲氨蝶呤', active: false }, |
|
|
|
|
{ id: 6, label: '环孢素 A', active: false }, |
|
|
|
|
{ id: 7, label: '他克莫司', active: false }, |
|
|
|
|
{ id: 8, label: '艾拉莫德', active: false }, |
|
|
|
|
{ id: 99, label: '其他', active: false }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const HORMONE_DOSAGE_OPTIONS = [1, 2, 4, 6, 8, 0.5] |
|
|
|
|
|
|
|
|
|
const IMAGE_TYPE_MAP: Record<string, string> = { |
|
|
|
|
outpatientRecord: 'outpatientRecord', |
|
|
|
|
labReport: 'labReport', |
|
|
|
|
@ -55,9 +33,9 @@ Page({
@@ -55,9 +33,9 @@ Page({
|
|
|
|
|
immunosuppressantName: [] as number[], |
|
|
|
|
oralHormoneDosage: 0, |
|
|
|
|
customDosage: '', |
|
|
|
|
medicationsOptions: MEDICATIONS_OPTIONS, |
|
|
|
|
immunosuppressantOptions: IMMUNOSUPPRESSANT_OPTIONS, |
|
|
|
|
hormoneDosageOptions: HORMONE_DOSAGE_OPTIONS, |
|
|
|
|
medicationsOptions: [] as { id: number; label: string; active: boolean }[], |
|
|
|
|
immunosuppressantOptions: [] as { id: number; label: string; active: boolean }[], |
|
|
|
|
hormoneDosageOptions: [] as number[], |
|
|
|
|
|
|
|
|
|
// 其他输入
|
|
|
|
|
medicationsUsedOtherText: '', |
|
|
|
|
@ -71,23 +49,30 @@ Page({
@@ -71,23 +49,30 @@ Page({
|
|
|
|
|
toastParams: {} as any, |
|
|
|
|
saving: false, |
|
|
|
|
submitted: false, |
|
|
|
|
|
|
|
|
|
today: dayjs().format('YYYY-MM-DD'), |
|
|
|
|
tomorrow: dayjs().add(1, 'day').format('YYYY-MM-DD'), |
|
|
|
|
|
|
|
|
|
focus: false, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
_saveDraftDebounced: null as any, |
|
|
|
|
|
|
|
|
|
onLoad(options: any) { |
|
|
|
|
_app.waitLogin().then(() => { |
|
|
|
|
_app.permissionVerification(3, 0, '/gift/pages/record/index').then(() => { |
|
|
|
|
_app.mpBehavior({ PageName: 'PG_PatientRecordAdd' }) |
|
|
|
|
}) |
|
|
|
|
this.getEnums().then(() => { |
|
|
|
|
if (options.id) { |
|
|
|
|
this.setData({ draftId: Number(options.id) }) |
|
|
|
|
_app.waitLogin().then(() => { |
|
|
|
|
this.getDetail() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this._saveDraftDebounced = debounce(() => { |
|
|
|
|
this.saveDraft() |
|
|
|
|
this.saveDraft().catch(() => {}) |
|
|
|
|
}, 800) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -99,7 +84,7 @@ Page({
@@ -99,7 +84,7 @@ Page({
|
|
|
|
|
if (this.data.submitted || !this._hasFilledData()) { |
|
|
|
|
wx.disableAlertBeforeUnload() |
|
|
|
|
} else { |
|
|
|
|
wx.enableAlertBeforeUnload({ message: '您有填写信息还未提交' }) |
|
|
|
|
wx.enableAlertBeforeUnload({ message: '已填写信息将被保存为草稿', }) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -114,6 +99,30 @@ Page({
@@ -114,6 +99,30 @@ Page({
|
|
|
|
|
|
|
|
|
|
// ========== API ==========
|
|
|
|
|
|
|
|
|
|
getEnums(): Promise<void> { |
|
|
|
|
return wx |
|
|
|
|
.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '?r=igg4/medical-visit/get-enums', |
|
|
|
|
}) |
|
|
|
|
.then((res: any) => { |
|
|
|
|
if (!res) return |
|
|
|
|
this.setData({ |
|
|
|
|
medicationsOptions: (res.medicationsUsed || []).map((item: any) => ({ |
|
|
|
|
id: item.value, |
|
|
|
|
label: item.label, |
|
|
|
|
active: false, |
|
|
|
|
})), |
|
|
|
|
immunosuppressantOptions: (res.immunosuppressantName || []).map((item: any) => ({ |
|
|
|
|
id: item.value, |
|
|
|
|
label: item.label, |
|
|
|
|
active: false, |
|
|
|
|
})), |
|
|
|
|
hormoneDosageOptions: (res.oralHormoneDosage || []).map((item: any) => item.value), |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
getDetail() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
@ -128,18 +137,18 @@ Page({
@@ -128,18 +137,18 @@ Page({
|
|
|
|
|
igG4Value: res.manualIgG4Value != null ? String(res.manualIgG4Value) : '', |
|
|
|
|
medicationsUsed: res.medicationsUsed || [], |
|
|
|
|
immunosuppressantName: res.immunosuppressantName || [], |
|
|
|
|
medicationsOptions: MEDICATIONS_OPTIONS.map((item) => ({ |
|
|
|
|
medicationsOptions: this.data.medicationsOptions.map((item) => ({ |
|
|
|
|
...item, |
|
|
|
|
active: (res.medicationsUsed || []).includes(item.id), |
|
|
|
|
})), |
|
|
|
|
immunosuppressantOptions: IMMUNOSUPPRESSANT_OPTIONS.map((item) => ({ |
|
|
|
|
immunosuppressantOptions: this.data.immunosuppressantOptions.map((item) => ({ |
|
|
|
|
...item, |
|
|
|
|
active: (res.immunosuppressantName || []).includes(item.id), |
|
|
|
|
})), |
|
|
|
|
oralHormoneDosage: res.oralHormoneDosage || 0, |
|
|
|
|
oralHormoneDosage: res.oralHormoneDosage ? Number(res.oralHormoneDosage) : 0, |
|
|
|
|
recordStatus: res.recordStatus, |
|
|
|
|
customDosage: |
|
|
|
|
res.oralHormoneDosage && !HORMONE_DOSAGE_OPTIONS.includes(res.oralHormoneDosage) |
|
|
|
|
res.oralHormoneDosage && !this.data.hormoneDosageOptions.includes(Number(res.oralHormoneDosage)) |
|
|
|
|
? String(res.oralHormoneDosage) |
|
|
|
|
: '', |
|
|
|
|
medicationsUsedOtherText: res.medicationsUsedOtherText || '', |
|
|
|
|
@ -165,8 +174,8 @@ Page({
@@ -165,8 +174,8 @@ Page({
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
saveDraft(): Promise<any> { |
|
|
|
|
if (this.data.saving) return Promise.resolve() |
|
|
|
|
if (!this.data.visitDate) return Promise.resolve() |
|
|
|
|
if (this.data.saving) return Promise.reject(new Error('saving')) |
|
|
|
|
if (!this.data.visitDate) return Promise.reject(new Error('no visitDate')) |
|
|
|
|
|
|
|
|
|
this.setData({ saving: true }) |
|
|
|
|
|
|
|
|
|
@ -218,7 +227,6 @@ Page({
@@ -218,7 +227,6 @@ Page({
|
|
|
|
|
this.setData({ recordStatus: res.recordStatus }) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.catch(() => {}) |
|
|
|
|
.finally(() => { |
|
|
|
|
this.setData({ saving: false }) |
|
|
|
|
}) |
|
|
|
|
@ -226,6 +234,8 @@ Page({
@@ -226,6 +234,8 @@ Page({
|
|
|
|
|
|
|
|
|
|
autoSave() { |
|
|
|
|
this._updateAlertBeforeUnload() |
|
|
|
|
// 编辑已提交的记录时不在实时保存,提交时统一保存
|
|
|
|
|
if (this.data.recordStatus === 2) return |
|
|
|
|
if (this._saveDraftDebounced) { |
|
|
|
|
this._saveDraftDebounced() |
|
|
|
|
} |
|
|
|
|
@ -255,12 +265,22 @@ Page({
@@ -255,12 +265,22 @@ Page({
|
|
|
|
|
// ========== Step1 事件 ==========
|
|
|
|
|
|
|
|
|
|
handleVisitDateChange(e: WechatMiniprogram.PickerChange) { |
|
|
|
|
this.setData({ visitDate: e.detail.value as string }) |
|
|
|
|
const value = e.detail.value as string |
|
|
|
|
if (value > dayjs().format('YYYY-MM-DD')) { |
|
|
|
|
wx.showToast({ title: '就诊时间不能超过今天', icon: 'none' }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.setData({ visitDate: value }) |
|
|
|
|
this.autoSave() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleNextVisitDateChange(e: WechatMiniprogram.PickerChange) { |
|
|
|
|
this.setData({ nextVisitDate: e.detail.value as string }) |
|
|
|
|
const value = e.detail.value as string |
|
|
|
|
if (value <= dayjs().format('YYYY-MM-DD')) { |
|
|
|
|
wx.showToast({ title: '复诊时间必须在今天之后', icon: 'none' }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.setData({ nextVisitDate: value }) |
|
|
|
|
this.autoSave() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -269,6 +289,10 @@ Page({
@@ -269,6 +289,10 @@ Page({
|
|
|
|
|
this.setData({ toastShow: true, toastType: 'oneWrite', toastParams: {} }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (this.data.recordStatus === 2) { |
|
|
|
|
this.setData({ step: 2 }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.saveDraft().then(() => { |
|
|
|
|
this.setData({ step: 2 }) |
|
|
|
|
}) |
|
|
|
|
@ -278,17 +302,22 @@ Page({
@@ -278,17 +302,22 @@ Page({
|
|
|
|
|
|
|
|
|
|
handleSetData(e: WechatMiniprogram.CustomEvent) { |
|
|
|
|
const imageType = e.currentTarget.dataset.type as string |
|
|
|
|
const file = e.detail[0] |
|
|
|
|
const filesKey = `${imageType}Files` |
|
|
|
|
const currentFiles = (this.data[filesKey as any] as any[]) || [] |
|
|
|
|
const newFile = { |
|
|
|
|
const maxNum = 10 |
|
|
|
|
const remaining = maxNum - currentFiles.length |
|
|
|
|
if (remaining <= 0) { |
|
|
|
|
wx.showToast({ title: '最多上传10张图片', icon: 'none' }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
const newFiles = (e.detail as any[]).slice(0, remaining).map((file) => ({ |
|
|
|
|
imgUrl: file.imgUrl, |
|
|
|
|
fileUrl: file.imgUrl, |
|
|
|
|
type: 'image', |
|
|
|
|
imageType, |
|
|
|
|
} |
|
|
|
|
})) |
|
|
|
|
this.setData({ |
|
|
|
|
[filesKey]: [...currentFiles, newFile], |
|
|
|
|
[filesKey]: [...currentFiles, ...newFiles], |
|
|
|
|
}) |
|
|
|
|
this.autoSave() |
|
|
|
|
}, |
|
|
|
|
@ -330,6 +359,10 @@ Page({
@@ -330,6 +359,10 @@ Page({
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleStep2Prev() { |
|
|
|
|
if (this.data.recordStatus === 2) { |
|
|
|
|
this.setData({ step: 1 }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.saveDraft().then(() => { |
|
|
|
|
this.setData({ step: 1 }) |
|
|
|
|
}) |
|
|
|
|
@ -341,6 +374,10 @@ Page({
@@ -341,6 +374,10 @@ Page({
|
|
|
|
|
this.setData({ toastShow: true, toastType: 'oneWrite', toastParams: {} }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (this.data.recordStatus === 2) { |
|
|
|
|
this.setData({ step: 3 }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.saveDraft().then(() => { |
|
|
|
|
this.setData({ step: 3 }) |
|
|
|
|
}) |
|
|
|
|
@ -349,7 +386,10 @@ Page({
@@ -349,7 +386,10 @@ Page({
|
|
|
|
|
// ========== Step3 事件 ==========
|
|
|
|
|
|
|
|
|
|
handleIgG4Input(e: WechatMiniprogram.Input) { |
|
|
|
|
this.setData({ igG4Value: e.detail.value }) |
|
|
|
|
const value = e.detail.value |
|
|
|
|
// 限制小数点后一位
|
|
|
|
|
const formatted = value.replace(/^(\d+\.\d).*/, '$1').replace(/^\.$/, '0.') |
|
|
|
|
this.setData({ igG4Value: formatted }) |
|
|
|
|
this.autoSave() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
@ -361,11 +401,14 @@ Page({
@@ -361,11 +401,14 @@ Page({
|
|
|
|
|
}) |
|
|
|
|
const usedIds = options.filter((item) => item.active).map((item) => item.id) |
|
|
|
|
const isOtherActive = usedIds.includes(99) |
|
|
|
|
const isHormoneActive = usedIds.includes(2) |
|
|
|
|
this.setData({ |
|
|
|
|
medicationsOptions: options, |
|
|
|
|
medicationsUsed: usedIds, |
|
|
|
|
medicationsOtherShow: isOtherActive, |
|
|
|
|
medicationsUsedOtherText: isOtherActive ? this.data.medicationsUsedOtherText : '', |
|
|
|
|
oralHormoneDosage: isHormoneActive ? this.data.oralHormoneDosage : 0, |
|
|
|
|
customDosage: isHormoneActive ? this.data.customDosage : '', |
|
|
|
|
}) |
|
|
|
|
this.autoSave() |
|
|
|
|
}, |
|
|
|
|
@ -415,6 +458,10 @@ Page({
@@ -415,6 +458,10 @@ Page({
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
handleStep3Prev() { |
|
|
|
|
if (this.data.recordStatus === 2) { |
|
|
|
|
this.setData({ step: 2 }) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.saveDraft().then(() => { |
|
|
|
|
this.setData({ step: 2 }) |
|
|
|
|
}) |
|
|
|
|
@ -443,6 +490,16 @@ Page({
@@ -443,6 +490,16 @@ Page({
|
|
|
|
|
this.submit() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
handleFocus() { |
|
|
|
|
this.setData({ |
|
|
|
|
focus: true, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
handleBlur() { |
|
|
|
|
this.setData({ |
|
|
|
|
focus: false, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// ========== Toast 事件 ==========
|
|
|
|
|
|
|
|
|
|
|