const app = getApp() Page({ data: { popupShow: false, popupType: 'preDiagnosisReportDate', // 确认绑定曾经扫码医生 popupParams: {}, fold1: true, fold2: true, fold3: true, fold4: true, fold5: true, fold6: true, fold7: true, fold8: true, fold9: true, fold10: true, // form examId: '', period: '1', 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: {}, }, }, 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(() => { 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) } 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() }) }, handleToggleFold(e: any) { const { fold } = e.currentTarget.dataset this.setData({ [fold]: !this.data[fold], }) }, handleToggleCheck(e: any) { const { check, fold } = e.currentTarget.dataset let foldValue = this.data[fold] if (this.data[check] == 2) { 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() { 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() }) }, handlePrevUpdate() { const pages = getCurrentPages() const currentPage = pages[pages.length - 1] if (currentPage && currentPage.handleUpdate) { currentPage.handleUpdate() } }, setFile(e: any) { console.log('DEBUGPRINT[63]: index.ts:189: e=', e) const { type, key } = e.currentTarget.dataset const { examId, period } = this.data const detail = e.detail || [] let apiArr: any[] = [] const fileList = this.data[key] || [] 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, } fileList.push(params) apiArr.push(this.saveAttachment(params)) }) this.setData({ [key]: fileList, }) Promise.all(apiArr).then((res) => { console.log(res) }) }, saveAttachment(params: any) { return wx.ajax({ method: 'POST', url: '?r=wtx/treatment/save-attachment', data: params, }) }, 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, }) }, }) export {}