const app = getApp() const dayjs = require('dayjs') Page({ data: { id: '', disabled: false, bottom: 0, InjectionDate: '', InjectionBottles: '', Remark: '', fileList: [], startDate: '2023-06-01', endDate: dayjs().format('YYYY-MM-DD'), toastShow: false, toastType: 'adlProgresss', toastParams: {} as any, }, onLoad(options) { const SystemInfo = app.globalSystemInfo if (SystemInfo) { const { bottom } = SystemInfo.capsulePosition this.setData({ bottom, }) } this.setData({ id: options.id, disabled: Boolean(options.id), }) if (options.id) { app.waitLogin().then((res) => { this.getDetail() }) } }, getDetail() { wx.ajax({ method: 'GET', url: '?r=zd/medication/view', data: { Id: this.data.id, }, }).then((res) => { this.setData({ InjectionDate: res.InjectionDate, InjectionBottles: res.InjectionBottles, Remark: res.Remark, }) }) }, handleSelect(e) { const { value } = e.currentTarget.dataset this.setData({ InjectionBottles: value, }) }, handleSubmit() { const that = this const { id, InjectionDate, InjectionBottles, Remark } = this.data let toast = '' if (!InjectionBottles) { toast = '请选择此次注射瓶数' } if (!InjectionDate) { toast = '请选择注射日期' } if (toast) { wx.showToast({ icon: 'none', title: toast, }) return } const url = id ? '?r=zd/medication/update' : '?r=zd/medication/add' wx.ajax({ method: 'POST', url, data: { Id: id, InjectionDate, InjectionBottles, Remark, }, }).then((res) => { if (res.ScoreInfo) { this.setData({ toastShow: true, toastType: Array.isArray(res.ScoreInfo) ? 'drugProgresssEnd' : 'drugProgresss', toastParams: { ...res.ScoreInfo, Records: res.ScoreInfo.Records?.reverse(), }, }) wx.removeStorageSync('adlResultInfo') } else { wx.showToast({ title: '提交成功', icon: 'none', success() { setTimeout(() => { that.handleBack() }, 2000) }, }) } }) }, handleToastOk() { this.handleToastCancel() }, handleToastCancel() { this.setData({ toastShow: false, }) this.handleBack() }, handleBack() { wx.navigateBack() }, })