医生统计页面增加动态切换天
This commit is contained in:
@@ -25,9 +25,33 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button-group>
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="isPrevDayDisabled"
|
||||
@click="handlePrevDay"
|
||||
>
|
||||
前一天
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="handleToday"
|
||||
>
|
||||
今天
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="isNextDayDisabled"
|
||||
@click="handleNextDay"
|
||||
>
|
||||
后一天
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="时间范围">
|
||||
<el-radio-group v-model="queryParams.time_type" @change="handleTimeTypeChange">
|
||||
<el-radio-button label="today">今天</el-radio-button>
|
||||
<el-radio-button label="week">最近7天</el-radio-button>
|
||||
<el-radio-button label="month">最近30天</el-radio-button>
|
||||
<el-radio-button label="custom">自定义</el-radio-button>
|
||||
@@ -157,10 +181,13 @@ const loading = ref(false)
|
||||
const doctorList = ref<any[]>([])
|
||||
const statisticsList = ref<any[]>([])
|
||||
const dateRange = ref<string[]>([])
|
||||
const currentDate = ref<string>(new Date().toISOString().split('T')[0])
|
||||
const isPrevDayDisabled = ref<boolean>(false)
|
||||
const isNextDayDisabled = ref<boolean>(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()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user