修改导出部分bug
This commit is contained in:
parent
b5112d6224
commit
fb27bc2fcb
@ -86,7 +86,7 @@ export const EcganalysisparasApi = {
|
||||
return await request.get({ url: `/tblist/ecganalysisparas/getDateStaAndEndData?doctorName=${doctorName}&TimeSta=${startDate}&TimeEnd=${endDate}` })
|
||||
},
|
||||
// 添加导出Excel的方法
|
||||
exportWorkloadExcel: async (startTime:String,endTime:String) => {
|
||||
return await request.download({ url: `/tblist/ecganalysisparas/export-workload-excel?startTime=${startTime}&endTime=${endTime} ` })
|
||||
exportWorkloadExcel: async (doctorName:string,startTime:string,endTime:string) => {
|
||||
return await request.download({ url: `/tblist/ecganalysisparas/export-workload-excel?doctorName=${doctorName}&startTime=${startTime}&endTime=${endTime} ` })
|
||||
},
|
||||
}
|
||||
|
@ -16,6 +16,23 @@
|
||||
</el-button>
|
||||
<el-button style="margin-left: 20px" @click="getdata()">查询</el-button>
|
||||
<el-button style="margin-left: 20px" @click="exportData()">导出</el-button>
|
||||
<el-button style="margin-left: 20px" @click="exportnowData()"
|
||||
>导出{{ Profilevo.doctorname }}工作量</el-button
|
||||
>
|
||||
<el-button style="margin-left: 20px" @click="exportAllData()">导出全部</el-button>
|
||||
<el-select
|
||||
v-model="doctorvalue"
|
||||
clearable
|
||||
placeholder="请选择医生"
|
||||
style="margin-left: 20px; width: 180px"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
</ContentWrap>
|
||||
@ -28,9 +45,12 @@
|
||||
<script setup lang="ts">
|
||||
import * as echarts from 'echarts'
|
||||
import { ref } from 'vue'
|
||||
const doctorvalue = ref('')
|
||||
import download from '@/utils/download'
|
||||
import { EcganalysisparasApi } from '@/api/tblist/ecganalysisparas'
|
||||
import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
|
||||
import { DiagnosisTemplateApi } from '@/api/applyregistration/diagnosisTemplate'
|
||||
import { ElMessage } from 'element-plus'
|
||||
const Profilevo = ref<ProfileVO>({} as ProfileVO) //当前登录人信息
|
||||
const endDate = new Date()
|
||||
const startDate = new Date(endDate.getTime() - 7 * 24 * 3600 * 1000)
|
||||
@ -38,12 +58,63 @@ const Date_value = ref<[Date, Date]>([startDate, endDate])
|
||||
const getlogininfo = async () => {
|
||||
Profilevo.value = await getUserProfile()
|
||||
}
|
||||
async function exportData(){
|
||||
|
||||
const options = ref<Array<{ value: string; label: string }>>([])
|
||||
const getDoctorList = async () => {
|
||||
try {
|
||||
const response = await DiagnosisTemplateApi.getDoctorList()
|
||||
options.value = response.map((doctor) => ({
|
||||
value: doctor.doctorName,
|
||||
label: doctor.doctorName
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('获取医生列表失败:', error)
|
||||
}
|
||||
}
|
||||
async function exportnowData() {
|
||||
try {
|
||||
// 使用固定的起始时间,比如从2000年开始
|
||||
const startDate = '2000-01-01 00:00:00'
|
||||
// 使用当前时间作为结束时间
|
||||
const endDate = `${formatDate(new Date())} 23:59:59`
|
||||
|
||||
// 显示加载提示
|
||||
ElMessage.info('正在导出数据,请稍候...')
|
||||
|
||||
const data = await EcganalysisparasApi.exportWorkloadExcel(
|
||||
Profilevo.value.doctorname,
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
|
||||
// 格式化文件名
|
||||
const fileName = `${Profilevo.value.doctorname}医生 ${formatDate(Date_value.value[0])}-${formatDate(Date_value.value[1])}工作量统计报表.xls`
|
||||
|
||||
download.excel(data, fileName)
|
||||
|
||||
ElMessage.success('导出成功')
|
||||
} catch (error) {
|
||||
console.error('导出失败:', error)
|
||||
ElMessage.error('导出失败,请重试')
|
||||
}
|
||||
}
|
||||
async function exportData() {
|
||||
const startDate = `${formatDate(Date_value.value[0])} 00:00:00`
|
||||
const endDate = `${formatDate(Date_value.value[1])} 23:59:59`
|
||||
const data=await EcganalysisparasApi.exportWorkloadExcel( startDate, endDate)
|
||||
download.excel(data, '工作量统计.xls')
|
||||
}
|
||||
const data = await EcganalysisparasApi.exportWorkloadExcel(
|
||||
Profilevo.value.doctorname,
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
|
||||
// 获取医生名字
|
||||
const doctorName = Profilevo.value.doctorname
|
||||
|
||||
// 格式化文件名
|
||||
const fileName = `${doctorName}医生 ${formatDate(Date_value.value[0])}-${formatDate(Date_value.value[1])}工作量统计报表.xls`
|
||||
|
||||
download.excel(data, fileName)
|
||||
}
|
||||
const defaultTime = ref<[Date, Date]>([
|
||||
new Date(2000, 1, 1, 0, 0, 0),
|
||||
new Date(2000, 2, 1, 23, 59, 59)
|
||||
@ -54,17 +125,17 @@ const disabledDate = (time: Date) => {
|
||||
if (Date_value.value && Date_value.value[0]) {
|
||||
const start = Date_value.value[0]
|
||||
const diff = 7 * 24 * 3600 * 1000
|
||||
|
||||
|
||||
// 如果是选择开始日期
|
||||
if (!Date_value.value[1]) {
|
||||
const today = new Date()
|
||||
return time.getTime() > today.getTime()
|
||||
}
|
||||
|
||||
|
||||
// 如果是选择结束日期
|
||||
return time.getTime() > start.getTime() + diff || time.getTime() < start.getTime()
|
||||
}
|
||||
|
||||
|
||||
// 如果还没有选择任何日期,只限制不能选择未来日期
|
||||
const today = new Date()
|
||||
return time.getTime() > today.getTime()
|
||||
@ -76,7 +147,7 @@ const generateDateArray = (startDate: Date, endDate: Date) => {
|
||||
let currentDate = new Date(startDate)
|
||||
|
||||
while (currentDate <= endDate) {
|
||||
dates.push(formatDate(currentDate)) // 使用 formatDate 函数格式化日期
|
||||
dates.push(formatDate(currentDate)) // 使用 formatDate 函数格式化日期
|
||||
currentDate = new Date(currentDate.setDate(currentDate.getDate() + 1))
|
||||
}
|
||||
return dates
|
||||
@ -92,9 +163,16 @@ const cachedData = ref<any[]>([])
|
||||
async function getdata() {
|
||||
const startDate = `${formatDate(Date_value.value[0])} 00:00:00`
|
||||
const endDate = `${formatDate(Date_value.value[1])} 23:59:59`
|
||||
|
||||
const data = await EcganalysisparasApi.getDateStaAndEndData(Profilevo.value.doctorname, startDate, endDate)
|
||||
cachedData.value = data // 保存数据
|
||||
|
||||
// 判断是否选择了医生
|
||||
const doctorName = doctorvalue.value ? doctorvalue.value : Profilevo.value.doctorname
|
||||
|
||||
const data = await EcganalysisparasApi.getDateStaAndEndData(
|
||||
doctorName, // 使用选择的医生名字或当前登录医生
|
||||
startDate,
|
||||
endDate
|
||||
)
|
||||
cachedData.value = data // 保存数据
|
||||
updateChartWithData(data)
|
||||
}
|
||||
|
||||
@ -102,7 +180,7 @@ async function getdata() {
|
||||
const updateChartWithData = (data: any[]) => {
|
||||
const dateArray = generateDateArray(Date_value.value[0], Date_value.value[1])
|
||||
const countArray = calculateDailyDiagnosisCounts(data, dateArray)
|
||||
|
||||
|
||||
const myChart = echarts.init(document.getElementById('main'))
|
||||
const option = {
|
||||
tooltip: {},
|
||||
@ -112,8 +190,8 @@ const updateChartWithData = (data: any[]) => {
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
name: '诊断数量',
|
||||
minInterval: 1, // 因为是计数,所以最小间隔设为1
|
||||
min: 0, // 从0开始比较合理
|
||||
minInterval: 1, // 因为是计数,所以最小间隔设为1
|
||||
min: 0, // 从0开始比较合理
|
||||
axisLabel: {
|
||||
formatter: '{value}'
|
||||
},
|
||||
@ -139,7 +217,7 @@ const updateChartWithData = (data: any[]) => {
|
||||
// 修改切换图表类型的方法
|
||||
const toggleChartType = () => {
|
||||
chartType.value = chartType.value === 'line' ? 'bar' : 'line'
|
||||
updateChartWithData(cachedData.value) // 使用缓存的数据更新图表
|
||||
updateChartWithData(cachedData.value) // 使用缓存的数据更新图表
|
||||
}
|
||||
|
||||
// 修改 handleDateChange 函数
|
||||
@ -150,8 +228,6 @@ const handleDateChange = (val: [Date, Date]) => {
|
||||
// 如果选择范围超过7天,自动调整结束日期
|
||||
Date_value.value = [val[0], new Date(val[0].getTime() + 7 * 24 * 3600 * 1000 - 1)]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,31 +243,61 @@ const formatDate = (date: Date) => {
|
||||
const calculateDailyDiagnosisCounts = (data: any[], dateArray: string[]) => {
|
||||
// 初始化计数对象
|
||||
const countMap = {}
|
||||
dateArray.forEach(date => {
|
||||
dateArray.forEach((date) => {
|
||||
countMap[date] = 0
|
||||
})
|
||||
|
||||
|
||||
// 统计每天的诊断数量
|
||||
data.forEach(item => {
|
||||
data.forEach((item) => {
|
||||
const date = new Date(item.doctorDiagTime)
|
||||
const dateStr = formatDate(date) // 使用相同的格式化函数
|
||||
const dateStr = formatDate(date) // 使用相同的格式化函数
|
||||
if (countMap[dateStr] !== undefined) {
|
||||
countMap[dateStr]++
|
||||
}
|
||||
})
|
||||
|
||||
return dateArray.map(date => countMap[date])
|
||||
|
||||
return dateArray.map((date) => countMap[date])
|
||||
}
|
||||
|
||||
// 修改 onMounted
|
||||
onMounted(() => {
|
||||
getlogininfo()
|
||||
getDoctorList()
|
||||
// 设置默认时间范围为当前日期往前7天
|
||||
const endDate = new Date()
|
||||
const startDate = new Date(endDate.getTime() - 6 * 24 * 3600 * 1000)
|
||||
Date_value.value = [startDate, endDate]
|
||||
|
||||
})
|
||||
|
||||
// 导出全部数据的方法
|
||||
async function exportAllData() {
|
||||
try {
|
||||
// 使用固定的起始时间,比如从2000年开始
|
||||
const startDate = '2000-01-01 00:00:00'
|
||||
// 使用当前时间作为结束时间
|
||||
const endDate = `${formatDate(new Date())} 23:59:59`
|
||||
|
||||
// 判断是否选择了医生
|
||||
const doctorName = doctorvalue.value ? doctorvalue.value : ''
|
||||
|
||||
// 显示加载提示
|
||||
ElMessage.info('正在导出数据,请稍候...')
|
||||
|
||||
const data = await EcganalysisparasApi.exportWorkloadExcel(doctorName, startDate, endDate)
|
||||
|
||||
// 格式化文件名
|
||||
const fileName = doctorName
|
||||
? `${doctorName}医生全部工作量统计报表.xls`
|
||||
: `全部医生工作量统计报表.xls`
|
||||
|
||||
download.excel(data, fileName)
|
||||
|
||||
ElMessage.success('导出成功')
|
||||
} catch (error) {
|
||||
console.error('导出失败:', error)
|
||||
ElMessage.error('导出失败,请重试')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
Loading…
Reference in New Issue
Block a user