<template>
|
<a-card :bordered='false'>
|
|
<!-- 查询区域 -->
|
<div class='table-page-search-wrapper'>
|
<a-form layout='inline' @keyup.enter.native='search'>
|
<a-row :gutter='24'>
|
<a-col :md='8' :sm='8'>
|
<a-form-item label='时间区间'>
|
<a-range-picker
|
v-model='queryParam.dateRange'
|
format='YYYY-MM-DD'
|
:placeholder="['开始时间', '结束时间']"
|
@change='onDateChange'>
|
</a-range-picker>
|
</a-form-item>
|
</a-col>
|
<a-col :md='8' :sm='8'>
|
<a-form-item label='仪器名称' :labelCol='{span: 5}' :wrapperCol='{span: 18, offset: 1}'>
|
|
<a-select placeholder='请选择仪器名称' v-model='queryParam.instrument'>
|
<a-select-option v-for='(item,index) in equList' :key='index' :value='item.id'>
|
{{ item.name }}
|
</a-select-option>
|
</a-select>
|
|
</a-form-item>
|
</a-col>
|
<a-col :md='8' :sm='8'>
|
<a-form-item label='使用类型' :labelCol='{span: 5}' :wrapperCol='{span: 18, offset: 1}'>
|
|
<a-select placeholder='请选择使用类型' v-model='queryParam.useType'>
|
<a-select-option :value='1'>
|
临时使用
|
</a-select-option>
|
<a-select-option :value='2'>
|
预约使用
|
</a-select-option>
|
</a-select>
|
|
</a-form-item>
|
</a-col>
|
<a-col :md='8' :sm='8'>
|
<a-form-item label='使用人' :labelCol='{span: 5}' :wrapperCol='{span: 18, offset: 1}'>
|
<a-select placeholder='请选择使用人' v-model='queryParam.createBy'>
|
<a-select-option v-for='(item,index) in userList' :key='index' :value='item.username'>
|
{{ item.realname }}
|
</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-col>
|
<span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
|
<a-col :md='8' :sm='24'>
|
<a-button type='primary' @click='search'>查询</a-button>
|
<a-button style='margin-left: 8px' @click='searchReset'>重置</a-button>
|
</a-col>
|
</span>
|
</a-row>
|
</a-form>
|
</div>
|
<!-- 查询区域-END -->
|
|
<!-- 操作按钮区域 -->
|
<div class='table-operator'>
|
<a-button type='primary' icon='download' @click="handleExportXls('设备时长统计')">导出</a-button>
|
</div>
|
|
<!-- table区域-begin -->
|
<div>
|
<div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
|
<i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
|
style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
|
<a style='margin-left: 24px' @click='onClearSelected'>清空</a>
|
<span style='float:right;'>
|
<a-popover title='自定义列' trigger='click' placement='leftBottom'>
|
<template slot='content'>
|
<a-radio-group v-model='selectUnit' @change="onRadioChange">
|
<a-radio :style='radioStyle' :value='0'>
|
小时
|
</a-radio>
|
<a-radio :style='radioStyle' :value='1'>
|
分
|
</a-radio>
|
<a-radio :style='radioStyle' :value='2'>
|
秒
|
</a-radio>
|
</a-radio-group>
|
</template>
|
<a><a-icon type='setting' />设置</a>
|
</a-popover>
|
</span>
|
</div>
|
|
<a-table
|
ref='table'
|
size='middle'
|
:scroll='{x:true}'
|
bordered
|
rowKey='id'
|
:columns='columns'
|
:dataSource='dataSource'
|
:pagination='ipagination'
|
:loading='loading'
|
:rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
|
class='j-table-force-nowrap'
|
@change='handleTableChange'>
|
<template slot="useTime" slot-scope="text,record">
|
<span> {{text + unit[selectUnit]}} </span>
|
</template>
|
|
</a-table>
|
</div>
|
<!-- table区域-end -->
|
|
<!-- 图表区域-begin -->
|
<div>
|
<a-tabs type='card'>
|
<a-tab-pane key='1' tab='柱状图'>
|
<div id='bar' style='width: 100%;height: 400px'></div>
|
</a-tab-pane>
|
<a-tab-pane key='2' tab='折线图' forceRender>
|
<div id='line' style='width: 100%;height: 400px'></div>
|
</a-tab-pane>
|
<a-tab-pane key='3' tab='饼图' forceRender>
|
<div id='pie' style='width: 100%;height: 400px'></div>
|
</a-tab-pane>
|
</a-tabs>
|
|
|
</div>
|
<!-- 图表区域-end -->
|
</a-card>
|
</template>
|
|
<script>
|
import * as echarts from 'echarts'
|
import { getAction } from '@/api/manage'
|
import moment from 'moment'
|
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
|
import { getLastWeek,getLastMonth } from '@/utils/util'
|
|
|
export default {
|
name: 'EquUseStat',
|
mixins: [JeecgListMixin],
|
props:{
|
userList: {
|
type: Array,
|
default: () => [],
|
required: true
|
},
|
},
|
// watch: {
|
// dataSource: {
|
// immediate: true,
|
// handler: function(newValue) {
|
// this.createBarData()
|
// }
|
// }
|
// },
|
data() {
|
return {
|
disableMixinCreated: true,
|
// 表头
|
columns: [
|
{
|
title: '#',
|
dataIndex: '',
|
key: 'rowIndex',
|
width: 60,
|
align: 'center',
|
customRender: function(t, r, index) {
|
return parseInt(index) + 1
|
}
|
},
|
{
|
title: '仪器名称',
|
align: 'center',
|
dataIndex: 'instrument'
|
},
|
{
|
title: '预约使用次数',
|
align: 'center',
|
dataIndex: 'appoUse'
|
|
},
|
{
|
title: '预约使用时长',
|
align: 'center',
|
dataIndex: 'appoUseTimeStr',
|
|
},
|
{
|
title: '临时使用次数',
|
align: 'center',
|
dataIndex: 'tempUse'
|
},
|
{
|
title: '临时使用时长',
|
align: 'center',
|
dataIndex: 'tempUseTimeStr',
|
|
},
|
{
|
title: '总使用时长',
|
align: 'center',
|
dataIndex: 'useTimeStr',
|
}
|
|
],
|
equList: [],
|
dateFormat: 'YYYY-MM-DD',
|
selectUnit: 0,
|
unit: ['小时','分钟','秒'],
|
radioStyle: {
|
display: 'block',
|
height: '30px',
|
lineHeight: '30px'
|
},
|
url: {
|
insUse: '/lims/stat/insUse',
|
exportXlsUrl: '/lims/stat/exportInsXls',
|
}
|
}
|
},
|
created() {
|
this.queryEquList()
|
//默认查询上周数据
|
let lastWeek = getLastMonth(0)
|
this.initQuery(lastWeek.start, lastWeek.end)
|
},
|
methods: {
|
search() {
|
let params = Object.assign({}, this.queryParam)
|
if (params.dateRange) {
|
delete params.dateRange //范围参数不传递后台
|
}
|
this.loadData(params)
|
},
|
searchReset() {
|
this.queryParam = {}
|
//默认查询上周数据
|
let lastWeek = getLastMonth(0)
|
this.initQuery(lastWeek.start, lastWeek.end)
|
},
|
initQuery(start, end) {
|
this.queryParam.createTime_begin = start
|
this.queryParam.createTime_end = end
|
this.queryParam.dateRange = [
|
moment(start, this.dateFormat),
|
moment(end, this.dateFormat)
|
]
|
let params = Object.assign({}, this.queryParam)
|
if (params.dateRange) {
|
delete params.dateRange //范围参数不传递后台
|
}
|
this.$forceUpdate()
|
this.loadData(params)
|
},
|
onDateChange: function(value, dateString) {
|
this.queryParam.createTime_begin = dateString[0]
|
this.queryParam.createTime_end = dateString[1]
|
this.$forceUpdate()
|
},
|
onRadioChange(e) {
|
console.log('radio checked', e.target.value);
|
this.selectUnit = e.target.value
|
|
//重新加载数据
|
let params = Object.assign({}, this.queryParam)
|
if (params.dateRange) {
|
delete params.dateRange //范围参数不传递后台
|
}
|
this.loadData(params)
|
|
},
|
initBarChart(xAxis, data) {
|
var chartDom = document.getElementById('bar')
|
var myChart = echarts.init(chartDom)
|
var option
|
|
option = {
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: {
|
type: 'shadow'
|
}
|
},
|
toolbox: {
|
show: true,
|
feature: {
|
saveAsImage: {
|
show: true,
|
name: '设备时长统计-柱状图'
|
}
|
}
|
},
|
xAxis: {
|
type: 'category',
|
data: xAxis,
|
name: '仪器',
|
axisLabel: { interval: 0, rotate: 30 }
|
},
|
yAxis: {
|
type: 'value',
|
name: '使用时长('+this.unit[this.selectUnit]+')'
|
},
|
series: [
|
{
|
data: data,
|
type: 'bar',
|
label: {
|
show: true,
|
position: 'top',
|
valueAnimation: true
|
}
|
}
|
]
|
}
|
|
option && myChart.setOption(option)
|
|
},
|
initLineChart(xAxis, data) {
|
var chartDom = document.getElementById('line')
|
var myChart = echarts.init(chartDom)
|
var option
|
|
option = {
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: {
|
type: 'shadow'
|
}
|
},
|
toolbox: {
|
show: true,
|
feature: {
|
saveAsImage: {
|
show: true,
|
name: '设备时长统计-折线图'
|
}
|
}
|
},
|
xAxis: {
|
type: 'category',
|
data: xAxis,
|
name: '仪器',
|
axisLabel: { interval: 0, rotate: 30 }
|
},
|
yAxis: {
|
type: 'value',
|
name: '使用时长('+this.unit[this.selectUnit]+')'
|
},
|
series: [
|
{
|
data: data,
|
type: 'line',
|
label: {
|
show: true,
|
position: 'top',
|
valueAnimation: true
|
}
|
}
|
]
|
}
|
|
option && myChart.setOption(option)
|
|
},
|
initPieChart(xAxis, data) {
|
let pdata = []
|
for (let i = 0; i < data.length; i++) {
|
let item = {}
|
item.value = data[i]
|
item.name = xAxis[i]
|
pdata.push(item)
|
}
|
|
var chartDom = document.getElementById('pie')
|
var myChart = echarts.init(chartDom)
|
var option
|
|
option = {
|
tooltip: {
|
trigger: 'item'
|
},
|
toolbox: {
|
show: true,
|
feature: {
|
saveAsImage: {
|
show: true,
|
name: '设备时长统计-饼图'
|
}
|
}
|
},
|
legend: {
|
orient: 'vertical',
|
left: 'left'
|
},
|
series: [
|
{
|
name: '设备时长',
|
type: 'pie',
|
radius: '50%',
|
data: pdata,
|
emphasis: {
|
itemStyle: {
|
shadowBlur: 10,
|
shadowOffsetX: 0,
|
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
}
|
}
|
}
|
]
|
}
|
|
option && myChart.setOption(option)
|
|
},
|
createData() {
|
let xAxis = []
|
let data = []
|
this.scal()
|
this.dataSource.forEach((item, index, arr) => {
|
xAxis.push(item.instrument)
|
data.push(item.useTime)
|
})
|
|
this.initBarChart(xAxis, data)
|
this.initLineChart(xAxis, data)
|
this.initPieChart(xAxis, data)
|
},
|
scal(){
|
for (let i = 0; i < this.dataSource.length; i++) {
|
let item = this.dataSource[i]
|
if (item.useTime && item.useTime > 0) {
|
|
if (this.selectUnit == 0) {
|
this.dataSource[i].useTime = this.dataSource[i].useTime / 60 / 60
|
this.dataSource[i].useTime = this.dataSource[i].useTime.toFixed(2)
|
|
this.dataSource[i].appoUseTime = this.dataSource[i].appoUseTime / 60 / 60
|
this.dataSource[i].appoUseTime = this.dataSource[i].appoUseTime.toFixed(2)
|
|
this.dataSource[i].tempUseTime = this.dataSource[i].tempUseTime / 60 / 60
|
this.dataSource[i].tempUseTime = this.dataSource[i].tempUseTime.toFixed(2)
|
|
} else if (this.selectUnit == 1) {
|
this.dataSource[i].useTime = this.dataSource[i].useTime / 60
|
this.dataSource[i].useTime = this.dataSource[i].useTime.toFixed(2)
|
|
this.dataSource[i].appoUseTime = this.dataSource[i].appoUseTime / 60
|
this.dataSource[i].appoUseTime = this.dataSource[i].appoUseTime.toFixed(2)
|
|
this.dataSource[i].tempUseTime = this.dataSource[i].tempUseTime / 60
|
this.dataSource[i].tempUseTime = this.dataSource[i].tempUseTime.toFixed(2)
|
} else {
|
this.dataSource[i].useTime = this.dataSource[i].useTime.toFixed(0)
|
}
|
|
} else {
|
|
}
|
}
|
},
|
|
|
loadData(params) {
|
this.loading = true
|
getAction(this.url.insUse, params).then((res) => {
|
this.loading = false
|
if (res.success) {
|
this.dataSource = res.result
|
this.createData()
|
}
|
})
|
},
|
|
//查询设备列表
|
queryEquList() {
|
getAction('/limsInstrument/list').then(res => {
|
if (res.success) {
|
this.equList = res.result.records
|
}
|
|
})
|
}
|
},
|
computed: {
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|