信达小程序
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.
 
 
 

221 lines
5.6 KiB

const app = getApp<IAppOption>()
Page({
data: {
id: '',
isEdit: false,
visitTime: '',
treatmentPlan: [] as string[],
planOptions: [] as any[],
teprotumumabCount: 1,
showUsageCount: false,
nextVisitTime: '',
nextVisitPreset: '',
intervalOptions: [] as any[],
popupShow: false,
popupType: 'popup16',
popupParams: {} as any,
hasChange: false,
},
onLoad(options: any) {
app.waitLogin({ type: [1] }).then(() => {
this.getEnum().then(() => {
if (options.id) {
this.setData({
id: options.id,
isEdit: true,
})
this.getDetail()
}
})
})
},
getEnum() {
return wx.ajax({
method: 'GET',
url: '?r=xd/follow-up-reminder/enum',
}).then((res: any) => {
const tp = res.treatmentPlan || {}
const planOptions = Object.keys(tp).map(key => ({
value: key,
label: tp[key],
isSelected: false,
}))
const nvi = res.nextVisitInterval || {}
const intervalOptions = Object.keys(nvi).map(key => ({
value: key,
label: nvi[key],
}))
this.setData({ planOptions, intervalOptions })
})
},
updatePlanOptions(treatmentPlan: string[]) {
const planOptions = this.data.planOptions.map((opt: any) => ({
...opt,
isSelected: treatmentPlan.includes(opt.value),
}))
const showUsageCount = treatmentPlan.includes('5')
this.setData({ planOptions, showUsageCount })
},
getDetail() {
wx.ajax({
method: 'GET',
url: '?r=xd/follow-up-reminder/detail',
data: { id: this.data.id },
loading: true,
}).then((res: any) => {
const treatmentPlan = res.treatmentPlan ? res.treatmentPlan.split(',') : []
this.setData({
visitTime: res.visitTime || '',
treatmentPlan,
teprotumumabCount: res.teprotumumabCount || 1,
nextVisitTime: res.nextVisitTime || '',
hasChange: false,
})
this.updatePlanOptions(treatmentPlan)
})
},
onVisitDateChange(e: any) {
this.setData({ visitTime: e.detail.value, hasChange: true })
},
onNextDateChange(e: any) {
this.setData({ nextVisitTime: e.detail.value, nextVisitPreset: '', hasChange: true })
},
togglePlan(e: any) {
const value = e.currentTarget.dataset.value
const treatmentPlan = [...this.data.treatmentPlan]
const index = treatmentPlan.indexOf(value)
if (index > -1) {
treatmentPlan.splice(index, 1)
}
else {
treatmentPlan.push(value)
}
this.setData({ treatmentPlan, hasChange: true })
this.updatePlanOptions(treatmentPlan)
},
onStepperChange(e: any) {
this.setData({ teprotumumabCount: e.detail, hasChange: true })
},
onNextPresetChange(e: any) {
const preset = e.currentTarget.dataset.value
const { visitTime } = this.data
if (!visitTime) {
wx.showToast({ title: '请先选择复诊时间', icon: 'none' })
return
}
const date = new Date(visitTime)
if (preset === '21') {
date.setDate(date.getDate() + 21)
}
else if (preset === '30') {
date.setMonth(date.getMonth() + 1)
}
else if (preset === '60') {
date.setMonth(date.getMonth() + 2)
}
const nextVisitTime = this.formatDate(date)
this.setData({ nextVisitPreset: preset, nextVisitTime, hasChange: true })
},
formatDate(date: Date) {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${d}`
},
handleSubmit() {
const { visitTime, treatmentPlan, teprotumumabCount, nextVisitTime, id, isEdit } = this.data
if (!visitTime) {
wx.showToast({ title: '请选择复诊时间', icon: 'none' })
return
}
if (!treatmentPlan.length) {
wx.showToast({ title: '请选择复诊方案', icon: 'none' })
return
}
if (!nextVisitTime) {
wx.showToast({ title: '请选择下次复诊时间', icon: 'none' })
return
}
const data = {
visitTime,
treatmentPlan: treatmentPlan.join(','),
teprotumumabCount,
nextVisitTime,
}
if (isEdit) {
wx.ajax({
method: 'POST',
url: '?r=xd/follow-up-reminder/update',
data: { id, ...data },
loading: true,
}).then(() => {
wx.showToast({ title: '更新成功', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
})
}
else {
wx.ajax({
method: 'POST',
url: '?r=xd/follow-up-reminder/create',
data,
loading: true,
}).then(() => {
wx.showToast({ title: '创建成功', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
})
}
},
handleCancel() {
if (this.data.hasChange) {
this.setData({ popupShow: true, popupType: 'popup16' })
}
else {
wx.navigateBack()
}
},
handleDelete() {
this.setData({ popupShow: true, popupType: 'popup15' })
},
handlePopupOk() {
const { popupType } = this.data
this.setData({ popupShow: false })
if (popupType === 'popup15') {
// 删除确认
wx.ajax({
method: 'POST',
url: '?r=xd/follow-up-reminder/delete',
data: { id: this.data.id },
loading: true,
}).then(() => {
wx.showToast({ title: '删除成功', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
})
}
else {
// 保存记录
this.handleSubmit()
}
},
handlePopupCancel() {
this.setData({ popupShow: false })
wx.navigateBack()
},
})
export {}