const app = getApp() Page({ data: { popupShow: false, popupType: 'inhibitors', popupParams: {}, recordId: '', period: '', recordDate: '', drugId: '', drugName: '', type: '', dosage: '', dosageUnit: '', dosageUnitName: '', dosageUnitIndex: 0, drugUnitList: [] as any, dict: { drugTypeList: {}, drugUnitList: {}, drugList: {}, }, }, onLoad(options) { console.log('DEBUGPRINT[71]: index.ts:29: options=', options) this.setData({ period: options.period, }) app.waitLogin({ type: 1 }).then(() => { this.getDict() if (options.id) { this.getDetail(options.id) } }) }, getDict() { wx.ajax({ method: 'GET', url: '?r=wtx/treatment/get-dict', data: {}, }).then((res) => { this.setData({ dict: res, drugUnitList: Object.entries(res.drugUnitList).map(([key, value]) => { console.log('DEBUGPRINT[75]: index.ts:45: key=', key) return { id: key, value, } }), }) }) }, getDetail(id: string) { wx.ajax({ method: 'GET', url: '?r=wtx/immune/get-detail', data: { recordId: id }, }).then((res) => { this.setData({ ...res, }) }) }, handleDrug() { const { dict } = this.data this.setData({ popupShow: true, popupType: 'inhibitors', popupParams: { close: true, list: dict.drugList, }, }) }, handleSelect(e) { const { id } = e.currentTarget.dataset this.setData({ type: id, }) }, handleChange(e: any) { const index = e.detail.value const { drugUnitList } = this.data const { id, value } = drugUnitList[index] this.setData({ dosageUnit: id, dosageUnitName: value, dosageUnitIndex: index, }) }, handlePopupOk(e) { const { popupType } = this.data if (popupType === 'inhibitors') { const { id, name, content } = e.detail this.setData({ drugId: id, drugName: name === '其他' ? content : name, }) } this.setData({ popupShow: false, }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, handleSubmit() { const { recordId, period, recordDate, drugId, drugName, type, dosage, dosageUnit } = this.data wx.ajax({ method: 'POST', url: '?r=wtx/immune/save-record', data: { recordId, period, recordDate, drugId, drugName, type, dosage, dosageUnit, }, }).then(() => { this.handleBack() }) }, handleDel() { const { recordId } = this.data wx.ajax({ method: 'GET', url: '?r=wtx/immune/del', data: { recordId }, }).then(() => { this.handleBack() }) }, handleBack() { wx.navigateBack() }, }) export {}