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.
197 lines
4.5 KiB
197 lines
4.5 KiB
import dayjs from 'dayjs' |
|
|
|
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
popupShow: false, |
|
popupType: 'popup2', |
|
popupParams: { |
|
position: 'center', |
|
close: true, |
|
} as any, |
|
|
|
topicShow: false, |
|
replayShow: true, |
|
|
|
id: '', |
|
visitDate: '', |
|
fileList: [] as any[], |
|
isUpdatePrescription: 0, |
|
isUpdateSurgery: 0, |
|
remark: '', |
|
isEdit: false, |
|
|
|
endDate: dayjs().format('YYYY-MM-DD'), |
|
|
|
userInfo: {} as any, |
|
}, |
|
onLoad(options: any) { |
|
if (options.id) { |
|
this.setData({ id: options.id, isEdit: true }) |
|
app.waitLogin({ type: 'any' }).then(() => { |
|
app.getUserInfo().then((res) => { |
|
this.setData({ |
|
userInfo: res, |
|
}) |
|
}) |
|
this.getDetail(options.id) |
|
}) |
|
} else { |
|
app.waitLogin({ type: 'any' }).then(() => { |
|
app.getUserInfo().then((res) => { |
|
this.setData({ |
|
userInfo: res, |
|
}) |
|
}) |
|
}) |
|
} |
|
}, |
|
getDetail(id: string) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=psvt/revisit-record/detail', |
|
data: { id }, |
|
}).then((res: any) => { |
|
if (!res) return |
|
const fileList = (res.images || []).map((url: string) => ({ |
|
url, |
|
fileType: 'image', |
|
name: url, |
|
})) |
|
this.setData({ |
|
visitDate: res.visitDate || '', |
|
fileList, |
|
isUpdatePrescription: res.isUpdatePrescription ?? 0, |
|
isUpdateSurgery: res.isUpdateSurgery ?? 0, |
|
remark: res.remark || '', |
|
}) |
|
}) |
|
}, |
|
onDateChange(e: any) { |
|
const selectedDate = e.detail.value |
|
if (dayjs(selectedDate).isAfter(dayjs(), 'day')) { |
|
wx.showToast({ title: '不能选择未来日期', icon: 'none' }) |
|
return |
|
} |
|
this.setData({ visitDate: selectedDate }) |
|
}, |
|
handleSetData(e: any) { |
|
const { fileList } = this.data |
|
this.setData({ |
|
fileList: [...fileList, ...e.detail], |
|
}) |
|
}, |
|
handleDeleteFile(e: any) { |
|
const { index } = e.detail |
|
const { fileList } = this.data |
|
this.setData({ |
|
fileList: fileList.filter((_, i) => i !== index), |
|
}) |
|
}, |
|
handlePrescriptionChange(e: any) { |
|
const { value } = e.currentTarget.dataset |
|
this.setData({ isUpdatePrescription: value }) |
|
}, |
|
handleSurgeryChange(e: any) { |
|
const { value } = e.currentTarget.dataset |
|
this.setData({ isUpdateSurgery: value }) |
|
}, |
|
onRemarkInput(e: any) { |
|
this.setData({ remark: e.detail.value }) |
|
}, |
|
handleSubmit() { |
|
const { id, visitDate, fileList, isUpdatePrescription, isUpdateSurgery, remark, isEdit, userInfo } = this.data |
|
|
|
if (!visitDate) { |
|
wx.showToast({ title: '请选择复诊日期', icon: 'none' }) |
|
return |
|
} |
|
|
|
const images = fileList.map((item: any) => item.url) |
|
|
|
const data = { |
|
visitDate, |
|
images, |
|
isUpdatePrescription, |
|
isUpdateSurgery, |
|
remark, |
|
} |
|
|
|
wx.showLoading({ title: '保存中' }) |
|
|
|
if (isEdit) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/revisit-record/update', |
|
data: { id: Number(id), ...data }, |
|
}) |
|
.then(() => { |
|
wx.hideLoading() |
|
wx.showToast({ title: '保存成功', icon: 'success' }) |
|
setTimeout(() => { |
|
wx.navigateBack() |
|
}, 1000) |
|
}) |
|
.catch(() => { |
|
wx.hideLoading() |
|
}) |
|
} else { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/revisit-record/create', |
|
data, |
|
}) |
|
.then(() => { |
|
wx.hideLoading() |
|
if (userInfo.isFollow == 1) { |
|
wx.showToast({ title: '保存成功', icon: 'success' }) |
|
setTimeout(() => { |
|
wx.navigateBack() |
|
}, 1000) |
|
} else { |
|
this.setData({ |
|
popupShow: true, |
|
popupType: 'popup2', |
|
popupParams: { |
|
position: 'center', |
|
close: true, |
|
}, |
|
}) |
|
} |
|
}) |
|
.catch(() => { |
|
wx.hideLoading() |
|
}) |
|
} |
|
}, |
|
handlePopupOk() { |
|
const { popupType } = this.data |
|
if (popupType == 'popup2') { |
|
this.setData({ popupShow: false }) |
|
wx.navigateBack() |
|
} |
|
}, |
|
handlePopupCancel() { |
|
const { popupType } = this.data |
|
if (popupType == 'popup2') { |
|
this.setData({ popupShow: false }) |
|
wx.navigateBack() |
|
} |
|
}, |
|
handleWechatWork() { |
|
wx.navigateTo({ |
|
url: '/pages/wechatWork/index', |
|
}) |
|
}, |
|
topicClose() { |
|
this.setData({ |
|
topicShow: false, |
|
}) |
|
}, |
|
handleBack() { |
|
wx.navigateBack() |
|
}, |
|
}) |
|
|
|
export {}
|
|
|