diff --git a/admin/src/views/doctor/tongji.vue b/admin/src/views/doctor/tongji.vue index 10955978..030194ec 100644 --- a/admin/src/views/doctor/tongji.vue +++ b/admin/src/views/doctor/tongji.vue @@ -25,9 +25,33 @@ + + + + 前一天 + + + 今天 + + + 后一天 + + + + - 今天 最近7天 最近30天 自定义 @@ -157,10 +181,13 @@ const loading = ref(false) const doctorList = ref([]) const statisticsList = ref([]) const dateRange = ref([]) +const currentDate = ref(new Date().toISOString().split('T')[0]) +const isPrevDayDisabled = ref(false) +const isNextDayDisabled = ref(false) const queryParams = reactive({ doctor_id: '', - time_type: 'today', + time_type: 'week', start_date: '', end_date: '' }) @@ -178,16 +205,20 @@ const getStatistics = async () => { loading.value = true try { const params: any = { - time_type: queryParams.time_type + time_type: 'custom' // 始终使用custom类型,只传时间区间 } if (queryParams.doctor_id) { params.doctor_id = queryParams.doctor_id } - if (queryParams.time_type === 'custom' && dateRange.value && dateRange.value.length === 2) { + if (dateRange.value && dateRange.value.length === 2) { params.start_date = dateRange.value[0] params.end_date = dateRange.value[1] + } else { + // 否则使用currentDate作为查询参数 + params.start_date = currentDate.value + params.end_date = currentDate.value } const res = await getDoctorStatistics(params) @@ -215,12 +246,67 @@ const handleTimeTypeChange = () => { if (queryParams.time_type !== 'custom') { dateRange.value = [] } + + // 根据时间类型更新currentDate + switch (queryParams.time_type) { + case 'week': + currentDate.value = new Date().toISOString().split('T')[0] + break + case 'month': + currentDate.value = new Date().toISOString().split('T')[0] + break + case 'custom': + // 自定义类型不更新currentDate + break + } + + updateDateButtons() +} + +// 更新日期按钮状态 +const updateDateButtons = () => { + const today = new Date().toISOString().split('T')[0] + const thirtyDaysAgo = new Date() + thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30) + const thirtyDaysAgoStr = thirtyDaysAgo.toISOString().split('T')[0] + + // 后一天超过今天则禁用 + isNextDayDisabled.value = currentDate.value >= today + // 前一天超过30天则禁用 + isPrevDayDisabled.value = currentDate.value <= thirtyDaysAgoStr +} + +// 处理前一天 +const handlePrevDay = () => { + const date = new Date(currentDate.value) + date.setDate(date.getDate() - 1) + currentDate.value = date.toISOString().split('T')[0] + updateDateButtons() + getStatistics() +} + +// 处理后一天 +const handleNextDay = () => { + const date = new Date(currentDate.value) + date.setDate(date.getDate() + 1) + currentDate.value = date.toISOString().split('T')[0] + updateDateButtons() + getStatistics() +} + +// 处理今天 +const handleToday = () => { + currentDate.value = new Date().toISOString().split('T')[0] + updateDateButtons() + getStatistics() } const handleReset = () => { queryParams.doctor_id = '' queryParams.time_type = 'today' dateRange.value = [] + currentDate.value = new Date().toISOString().split('T')[0] + updateDateButtons() getStatistics() } @@ -260,6 +346,7 @@ const getStatusType = (status: string | number) => { onMounted(() => { getDoctorList() + updateDateButtons() getStatistics() })