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.
402 lines
9.0 KiB
402 lines
9.0 KiB
import dayjs from 'dayjs' |
|
|
|
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
popupShow: false, |
|
popupType: 'preReportComplete', |
|
popupParams: {}, |
|
|
|
foldAll: true, |
|
|
|
fold1: true, |
|
fold2: true, |
|
fold3: true, |
|
fold4: true, |
|
fold5: true, |
|
fold6: true, |
|
fold7: true, |
|
fold8: true, |
|
fold9: true, |
|
fold10: true, |
|
|
|
// form |
|
examId: '', |
|
period: '1', |
|
|
|
allEndDate: dayjs().format('YYYY-MM-DD'), |
|
|
|
beginDate: '', |
|
endDate: '', |
|
isBloodRoutine: 2, |
|
isBiochemical: 2, |
|
alt: '', |
|
ast: '', |
|
bilirubin: '', |
|
isCFIxActivity: 2, |
|
clottingFactor: '', |
|
isCFIxInhibitor: 2, |
|
cFII: '', |
|
isHepatitisB: 2, |
|
hbsAg: '', |
|
hbvDNA: '', |
|
isHepatitisC: 2, |
|
hcvAntibody: '', |
|
hcvRNA: '', |
|
isHivAntibody: 2, |
|
hiv: '', |
|
isAfp: 2, |
|
afp: '', |
|
isAav: 2, |
|
aav: '', |
|
isOther: 2, |
|
otherInfo: '', |
|
|
|
attachmentList1: [], |
|
attachmentList2: [], |
|
attachmentList3: [], |
|
attachmentList4: [], |
|
attachmentList5: [], |
|
attachmentList6: [], |
|
attachmentList7: [], |
|
attachmentList8: [], |
|
attachmentList9: [], |
|
attachmentList10: [], |
|
|
|
formKeys: [ |
|
'beginDate', |
|
'endDate', |
|
'isBloodRoutine', |
|
'isBiochemical', |
|
'alt', |
|
'ast', |
|
'bilirubin', |
|
'isCFIxActivity', |
|
'clottingFactor', |
|
'isCFIxInhibitor', |
|
'cFII', |
|
'isHepatitisB', |
|
'hbsAg', |
|
'hbvDNA', |
|
'isHepatitisC', |
|
'hcvAntibody', |
|
'hcvRNA', |
|
'isHivAntibody', |
|
'hiv', |
|
'isAfp', |
|
'afp', |
|
'isAav', |
|
'aav', |
|
'isOther', |
|
'otherInfo', |
|
], |
|
|
|
checkNum: 0, |
|
checkList: [ |
|
'isBloodRoutine', |
|
'isBiochemical', |
|
'isCFIxActivity', |
|
'isCFIxInhibitor', |
|
'isHepatitisB', |
|
'isHepatitisC', |
|
'isHivAntibody', |
|
'isAfp', |
|
'isAav', |
|
'isOther', |
|
], |
|
|
|
dict: { |
|
result: {}, |
|
number: {}, |
|
}, |
|
}, |
|
time: null as any, |
|
onLoad(options) { |
|
this.setData({ |
|
examId: options.examid || '', |
|
period: options.period || '1', |
|
}) |
|
if (options.period === '2') { |
|
wx.setNavigationBarTitle({ |
|
title: '我的检查报告', |
|
}) |
|
} |
|
}, |
|
onShow() { |
|
const { formKeys, period } = this.data |
|
const examinationCache = wx.getStorageSync(`examinationCache${period}`) |
|
app.waitLogin().then(() => { |
|
app.mpBehavior({ PageName: 'PG_MYPREDIAGNOSISREPORT_VISIT' }) |
|
this.getDict() |
|
if (examinationCache) { |
|
const reset = formKeys.reduce((pre, cur) => { |
|
pre[cur] = examinationCache[cur] || '' |
|
return pre |
|
}, {}) |
|
this.setData({ |
|
...reset, |
|
}) |
|
this.getCheckNum() |
|
} else { |
|
this.getDetail() |
|
} |
|
}) |
|
}, |
|
onUnload() { |
|
this.updateSave() |
|
}, |
|
onHide() { |
|
this.updateSave() |
|
}, |
|
handleInput(e) { |
|
const { key, length } = e.currentTarget.dataset |
|
const value = e.detail.value |
|
this.setData({ |
|
[`${key}`]: this.validateInput(value, length), |
|
}) |
|
}, |
|
validateInput(val, integerLimit) { |
|
let num = val.toString() |
|
// 清除“数字”和“.”以外的字符 |
|
num = num.replace(/[^\d.]/g, '') |
|
// 只保留第一个.,清除多余的 |
|
num = num.replace(/\.{2,}/g, '.') |
|
// 限制整数位位数 |
|
const index = num.indexOf('.') |
|
if (index !== -1) { |
|
num = num.slice(0, index + integerLimit + 1) |
|
} else { |
|
num = num.slice(0, integerLimit) |
|
} |
|
// 限制小数位位数 |
|
const decimalIndex = num.indexOf('.') |
|
if (decimalIndex !== -1) { |
|
num = num.slice(0, decimalIndex + 3) |
|
} |
|
return num |
|
}, |
|
getDict() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=wtx/treatment/get-dict', |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
dict: res, |
|
}) |
|
}) |
|
}, |
|
getDetail() { |
|
const { examId, formKeys } = this.data |
|
if (!examId) return |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=wtx/treatment/get-examination-info', |
|
data: { |
|
examId: examId, |
|
}, |
|
}).then((res) => { |
|
const reset = formKeys.reduce((pre, cur) => { |
|
pre[cur] = res[cur] || '' |
|
return pre |
|
}, {}) |
|
this.setData({ |
|
...reset, |
|
attachmentList1: res.attachmentList[1] || [], |
|
attachmentList2: res.attachmentList[2] || [], |
|
attachmentList3: res.attachmentList[3] || [], |
|
attachmentList4: res.attachmentList[4] || [], |
|
attachmentList5: res.attachmentList[5] || [], |
|
attachmentList6: res.attachmentList[6] || [], |
|
attachmentList7: res.attachmentList[7] || [], |
|
attachmentList8: res.attachmentList[8] || [], |
|
attachmentList9: res.attachmentList[9] || [], |
|
attachmentList10: res.attachmentList[10] || [], |
|
}) |
|
this.getCheckNum() |
|
}) |
|
}, |
|
handleToggleFoldAll() { |
|
const foldAll = !this.data.foldAll |
|
this.setData({ |
|
foldAll, |
|
fold1: foldAll, |
|
fold2: foldAll, |
|
fold3: foldAll, |
|
fold4: foldAll, |
|
fold5: foldAll, |
|
fold6: foldAll, |
|
fold7: foldAll, |
|
fold8: foldAll, |
|
fold9: foldAll, |
|
fold10: foldAll, |
|
}) |
|
}, |
|
handleToggleFold(e: any) { |
|
const { fold } = e.currentTarget.dataset |
|
this.setData({ |
|
[fold]: !this.data[fold], |
|
}) |
|
}, |
|
handleToggleCheck(e: any) { |
|
app.mpBehavior({ PageName: 'BTN_CHECKED_CLICK' }) |
|
const { check, fold } = e.currentTarget.dataset |
|
let foldValue = this.data[fold] |
|
if (this.data[check] == 2 || !this.data[check]) { |
|
foldValue = false |
|
} |
|
this.setData({ |
|
[check]: this.data[check] == 1 ? 2 : 1, |
|
[fold]: foldValue, |
|
}) |
|
this.updateSave() |
|
this.getCheckNum() |
|
}, |
|
getCheckNum() { |
|
const { checkList } = this.data |
|
let num = 0 |
|
checkList.forEach((item) => { |
|
if (this.data[item] == 1) { |
|
num += 1 |
|
} |
|
}) |
|
this.setData({ |
|
checkNum: num, |
|
}) |
|
}, |
|
handleSelect(e: any) { |
|
const { key, value } = e.currentTarget.dataset |
|
this.setData({ |
|
[key]: value, |
|
}) |
|
this.updateSave() |
|
}, |
|
updateSave(e = null) { |
|
let isBack = false |
|
if (e) { |
|
const { back } = (e as any).currentTarget.dataset |
|
isBack = back == 1 |
|
} |
|
if (isBack && !this.data.beginDate && !this.data.endDate) { |
|
wx.showToast({ |
|
title: '请选择开始和结束日期', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
const { formKeys, period, examId, ...reset } = this.data |
|
const form = formKeys.reduce((pre, cur) => { |
|
pre[cur] = reset[cur] |
|
return pre |
|
}, {}) |
|
const storageKey = `examinationCache${period}` |
|
wx.setStorageSync(storageKey, form) |
|
|
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/treatment/save-examination', |
|
data: { |
|
examId, |
|
period, |
|
...form, |
|
}, |
|
}).then(() => { |
|
wx.removeStorageSync(storageKey) |
|
this.handlePrevUpdate() |
|
if (isBack) { |
|
this.setData({ |
|
popupShow: true, |
|
popupType: 'preReportComplete', |
|
popupParams: {}, |
|
}) |
|
this.time = setTimeout(() => { |
|
wx.navigateBack() |
|
}, 2000) |
|
} |
|
}) |
|
}, |
|
handlePrevUpdate() { |
|
const pages = getCurrentPages() |
|
const currentPage = pages[pages.length - 1] |
|
if (currentPage && currentPage.handleUpdate) { |
|
currentPage.handleUpdate() |
|
} |
|
}, |
|
setFile(e: any) { |
|
const { type, key } = e.currentTarget.dataset |
|
const { examId, period } = this.data |
|
const detail = e.detail || [] |
|
let apiArr: any[] = [] |
|
detail.forEach((item: any) => { |
|
const params: any = { |
|
examId, |
|
period, |
|
type, |
|
fileType: item.fileType, |
|
name: item.name, |
|
url: item.url, |
|
videoUrl: item.videoUrl, |
|
duration: item.duration, |
|
key, |
|
} |
|
apiArr.push(this.saveAttachment(params)) |
|
}) |
|
Promise.all(apiArr).then((res) => { |
|
const fileList = this.data[key] || [] |
|
const sortRes = res.sort((a, b) => a.attachmentId - b.attachmentId) |
|
this.setData({ |
|
[key]: fileList.concat(sortRes), |
|
}) |
|
}) |
|
}, |
|
saveAttachment(params: any) { |
|
return new Promise((resolve) => { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/treatment/save-attachment', |
|
data: params, |
|
}).then((res) => { |
|
resolve({ ...params, attachmentId: res }) |
|
}) |
|
}) |
|
}, |
|
delFile(e: any) { |
|
const { key } = e.currentTarget.dataset |
|
const { index, item } = e.detail |
|
if (item.attachmentId) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/treatment/del-attachment', |
|
data: { |
|
attachmentId: item.attachmentId, |
|
}, |
|
}) |
|
} |
|
const fileList = this.data[key] |
|
const newFileList = fileList.filter((_, i) => i !== index) |
|
this.setData({ |
|
[key]: newFileList, |
|
}) |
|
}, |
|
handleStartDate() { |
|
app.mpBehavior({ PageName: 'BTN_SELECTSTARTTIME_CLICK' }) |
|
}, |
|
handleEndDate() { |
|
app.mpBehavior({ PageName: 'BTN_SELECTENDTIME_CLICK' }) |
|
}, |
|
handleUploadTap() { |
|
app.mpBehavior({ PageName: 'BTN_UPLOADFILE_CLICK' }) |
|
}, |
|
handlePopupCancel() { |
|
if (this.time) { |
|
clearTimeout(this.time) |
|
} |
|
this.handleBack() |
|
}, |
|
handleBack() { |
|
wx.navigateBack() |
|
}, |
|
}) |
|
|
|
export {}
|
|
|