rax-medical/src/views/home/time-bar-chart.vue

212 lines
5.4 KiB
Vue
Raw Normal View History

2023-12-21 17:31:28 +08:00
<template>
2024-05-17 12:06:29 +08:00
<div class="chart-box">
<div class="date-btn text-color">
<div class="btn-box">
<el-icon @click="setDate('up')">
<ArrowLeft/>
</el-icon>
<el-date-picker v-model="currentMonth" format="第ww周" type="week" :editable="false" :clearable="false"
@change="getData"/>
<el-icon @click="setDate('down')">
<ArrowRight/>
</el-icon>
</div>
2023-12-21 17:31:28 +08:00
</div>
2024-05-17 12:06:29 +08:00
<div ref="chartDom" class="chart-dom"></div>
</div>
2023-12-21 17:31:28 +08:00
</template>
<script lang='ts' setup>
2024-05-17 12:06:29 +08:00
import {onMounted, ref} from 'vue'
2023-12-21 17:31:28 +08:00
import * as echarts from 'echarts';
2024-05-17 12:06:29 +08:00
import {dateFormater, getCurrentDate, getDays, getFirstDayOfWeek, getWeekDates} from '@/utils/date-util';
import * as medicineApi from "@/api/medicine";
2023-12-21 17:31:28 +08:00
const chartDom = ref()
const currentMonth = ref(new Date())
onMounted(() => {
2024-05-17 12:06:29 +08:00
getData(new Date())
2023-12-21 17:31:28 +08:00
})
// 大于当前时间返回 true
function calcTime(time: any) {
2024-05-17 12:06:29 +08:00
return Boolean(new Date().getTime() < new Date(time).getTime())
2023-12-21 17:31:28 +08:00
}
2024-05-17 12:06:29 +08:00
2023-12-21 17:31:28 +08:00
function initChart(chartData: any) {
2024-05-17 12:06:29 +08:00
const chart = echarts.init(chartDom.value as HTMLElement);
chart.clear();
const option = {
color: ['#006080', '#f8b300'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
formatter: (params: any) => {
let str = dateFormater('yyyy-MM-dd', params[0].axisValue) + '<b style="padding: 0 10px;">' + getCurrentDate(params[0].axisValue) + '</b>'
params.forEach((item: any) => {
str += '<br>'
str += item.marker + item.seriesName + '' + item.value + '小时'
})
return str
}
},
legend: {
right: 0,
data: chartData.dataName
},
grid: {
left: 20,
right: 50,
bottom: 5,
top: 50,
containLabel: true,
},
xAxis: {
name: '日期',
show: true,
type: 'category',
nameTextStyle: {color: '#909399'},
axisLine: {show: true, lineStyle: {color: '#006080', width: 2}},
axisTick: {show: false},
axisLabel: {show: true, color: '#909399', formatter: (value: any) => getCurrentDate(value)},
splitLine: {show: true, lineStyle: {color: 'rgba(212, 130, 1, .05)', width: 1, type: 'solid'}},
data: chartData.xData,
},
yAxis: {
name: '时间',
show: true,
type: 'value',
min: 0,
nameTextStyle: {color: '#909399', align: 'center', verticalAlign: 'top', padding: [0, 0]},
axisLine: {show: true, lineStyle: {color: '#006080', width: 2}},
axisTick: {show: false},
axisLabel: {show: false},
splitLine: {show: false, lineStyle: {color: '#D4E8F0', width: 1, type: 'solid'}},
},
series: [{
name: chartData.dataName[0],
type: 'bar',
label: {
show: true,
rotate: -90,
align: 'left',
verticalAlign: 'center',
position: 'insideTop',
color: '#ffffff',
textBorderColor: '#006080',
textBorderWidth: 3,
formatter: (params: any) => params.value.toFixed(0) + 'h' + Number((params.value % 1).toFixed(1)) * 60 + 'm'
},
data: chartData.data[0]
},
{
name: chartData.dataName[1],
type: 'bar',
label: {
show: true,
rotate: -90,
align: 'left',
verticalAlign: 'center',
position: 'insideTop',
color: '#ffffff',
textBorderColor: '#f8b300',
textBorderWidth: 3,
formatter: (params: any) => params.value.toFixed(0) + 'h' + Number((params.value % 1).toFixed(1)) * 60 + 'm'
2023-12-21 17:31:28 +08:00
},
2024-05-17 12:06:29 +08:00
data: chartData.data[1]
}],
};
chart.setOption(option);
chart.resize();
window.addEventListener('resize', () => {
2023-12-21 17:31:28 +08:00
chart.resize();
2024-05-17 12:06:29 +08:00
});
2023-12-21 17:31:28 +08:00
}
2024-05-17 12:06:29 +08:00
2023-12-21 17:31:28 +08:00
const setDate = (type: string) => {
2024-05-17 12:06:29 +08:00
getData(getDays(currentMonth.value, type === 'up' ? -7 : 7))
2023-12-21 17:31:28 +08:00
}
const getData = (date: any) => {
2024-05-17 12:06:29 +08:00
currentMonth.value = new Date(date)
const dataName = ['麻醉给药时长', '人工给药时长']
const xData: any = []
const data = [[], []] as any
const weekDates = getWeekDates(currentMonth.value)
const start = dateFormater("yyyy-MM-dd", weekDates.start)
const end = dateFormater("yyyy-MM-dd", weekDates.end.setDate(weekDates.end.getDate() + 1))
medicineApi.getSurgeryOtherDuration(start, end).then(res => {
if (res.code == 0) {
res.data.forEach((item: any) => {
xData.push(new Date(item._id))
data[0].push(item.aicount)
data[1].push(item.doccount)
})
2023-12-21 17:31:28 +08:00
}
2024-05-17 12:06:29 +08:00
initChart({dataName, xData, data})
})
2023-12-21 17:31:28 +08:00
}
</script>
<style lang='scss' scoped>
.chart-box {
2024-05-17 12:06:29 +08:00
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
.date-btn {
position: absolute;
width: 150px;
height: 50px;
top: 0;
left: 20px;
2023-12-21 17:31:28 +08:00
display: flex;
2024-05-17 12:06:29 +08:00
z-index: 1;
.btn-box {
height: 30px;
display: flex;
align-items: center;
color: $text2-color;
& > :deep(.el-date-editor) {
font-size: 14px;
.el-input__wrapper {
box-shadow: none;
padding: 0;
.el-input__prefix,
.el-input__suffix {
display: none;
}
2023-12-21 17:31:28 +08:00
2024-05-17 12:06:29 +08:00
.el-input__inner {
cursor: pointer;
width: 100px;
color: $text2-color;
text-align: center;
}
2023-12-21 17:31:28 +08:00
}
2024-05-17 12:06:29 +08:00
}
2023-12-21 17:31:28 +08:00
2024-05-17 12:06:29 +08:00
.el-icon {
cursor: pointer;
}
2023-12-21 17:31:28 +08:00
}
2024-05-17 12:06:29 +08:00
}
.chart-dom {
// width: calc(100% - 180px);
width: 100%;
height: 100%;
}
2023-12-21 17:31:28 +08:00
}</style>