<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: tableWidth}'
|
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='bar21' style='width: 100%;height: 400px'></div>
|
</a-tab-pane>
|
<a-tab-pane key='2' tab='分组柱状图' forceRender>
|
<div id='bar22' style='width: 100%;height: 400px'></div>
|
</a-tab-pane>
|
</a-tabs>
|
|
|
</div>
|
<!-- 图表区域-end -->
|
</a-card>
|
</template>
|
|
<script>
|
import * as echarts from 'echarts'
|
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
|
import { getLastMonth, getLastWeek } from '@/utils/util'
|
import moment from 'moment'
|
import { getAction } from '@api/manage'
|
export default {
|
|
name: 'UserUseStat',
|
mixins: [JeecgListMixin],
|
props:{
|
userList: {
|
type: Array,
|
default: () => [],
|
required: true
|
},
|
},
|
created() {
|
this.queryEquList()
|
//默认查询上周数据
|
let lastWeek = getLastMonth(0)
|
this.initQuery(lastWeek.start, lastWeek.end)
|
|
},
|
data(){
|
return{
|
disableMixinCreated: true,
|
equList:[],
|
dateFormat: 'YYYY-MM-DD',
|
selectUnit: 0,
|
unit: ['小时','分钟','秒'],
|
radioStyle: {
|
display: 'block',
|
height: '30px',
|
lineHeight: '30px'
|
},
|
tableWidth: 0,
|
// 表头
|
columns: [
|
],
|
url: {
|
userUse: '/lims/stat/userUse',
|
exportXlsUrl: '/lims/stat/exportUserXls',
|
}
|
}
|
},
|
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)
|
|
},
|
//初始化列
|
initColumns() {
|
|
|
let itemWidth = 160
|
this.columns = []
|
let width = this.$refs.table.$el.offsetWidth
|
let dataWidth = 200 + this.extSource.length * itemWidth
|
|
if (dataWidth > width) {
|
this.tableWidth = dataWidth
|
} else {
|
this.tableWidth = 0
|
itemWidth = (width - 200) / this.extSource.length
|
}
|
|
|
|
this.columns.push({
|
title: '序号',
|
dataIndex: '',
|
key: 'rowIndex',
|
width: 50,
|
align: 'center',
|
fixed: 'left',
|
customRender: function(t, r, index) {
|
return parseInt(index) + 1
|
}
|
})
|
|
this.columns.push({
|
title: '姓名',
|
width: 150,
|
fixed: 'left',
|
dataIndex: 'user',
|
align: 'center',
|
sorter: true,
|
})
|
|
|
this.extSource.forEach(item => {
|
this.columns.push({
|
title: item.name,
|
dataIndex: item.useTime,
|
width: itemWidth,
|
align: 'center',
|
|
})
|
})
|
|
|
|
this.$nextTick(() => {
|
window.dispatchEvent(new Event('resize'))
|
})
|
this.createData()
|
|
},
|
createData(){
|
let xAxis = []
|
let xAxis2 = []
|
let data = []
|
let data2 = []
|
let series2 = []
|
xAxis2.push('product')
|
data2.push(xAxis2)
|
|
|
this.extSource.forEach((item, index, arr) => {
|
const col = item.name
|
xAxis2.push(col)
|
series2.push({ type: 'bar',label: {
|
show: true,
|
position: 'top',
|
valueAnimation: true
|
} });
|
|
this.dataSource.forEach((item, index, arr) => {
|
let value = item[col]
|
|
if(value){
|
if(this.selectUnit == 0){
|
let hour = value/3600;
|
hour = hour.toFixed(2)
|
hour = Number(hour)
|
this.dataSource[index][col] = hour
|
}else if(this.selectUnit == 1){
|
let min = value/60;
|
min = min.toFixed(2)
|
min = Number(min)
|
this.dataSource[index][col] = min
|
}else {
|
let sec = value.toFixed(0)
|
sec = Number(sec)
|
this.dataSource[index][col] = sec
|
|
}
|
}
|
})
|
let array = Array.from(this.dataSource,x=>x[col])
|
let d= {}
|
d.name = col
|
d.type = 'bar'
|
d.stack = 'Ad'
|
d.emphasis = {
|
focus: 'series'
|
}
|
d.data = array;
|
|
data.push(d)
|
})
|
|
this.dataSource.forEach((item)=>{
|
xAxis.push(item.user)
|
|
let array2 = []
|
array2.push(item.user);
|
this.extSource.forEach((it, index, arr) => {
|
array2.push(item[it.name])
|
})
|
data2.push(array2)
|
})
|
|
console.info(data2)
|
console.info(series2)
|
this.initBarChart(xAxis,data)
|
let that = this
|
setTimeout(function() {
|
that.initGroupBarChart(xAxis2,data2,series2)
|
},1000)
|
|
|
|
|
|
},
|
loadData(params) {
|
this.loading = true
|
getAction(this.url.userUse, params).then((res) => {
|
this.loading = false
|
if (res.success) {
|
this.dataSource = res.result
|
this.extSource = res.resultExt
|
console.info(this.dataSource)
|
console.info( this.extSource)
|
this.initColumns()
|
}
|
})
|
},
|
initBarChart(xAxis,data){
|
var chartDom = document.getElementById('bar21');
|
var myChart = echarts.init(chartDom);
|
var option;
|
|
option = {
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: {
|
type: 'shadow'
|
}
|
},
|
toolbox: {
|
show: true,
|
feature: {
|
saveAsImage: {
|
show: true,
|
name: '人员使用统计-堆叠柱状图'
|
}
|
}
|
},
|
legend: {
|
|
},
|
grid: {
|
left: '3%',
|
right: '4%',
|
bottom: '3%',
|
containLabel: true
|
},
|
xAxis: [
|
{
|
type: 'category',
|
data: xAxis,
|
name: '用户',
|
}
|
],
|
yAxis: [
|
{
|
type: 'value',
|
name: '使用时长('+this.unit[this.selectUnit]+')'
|
}
|
],
|
series: data
|
};
|
|
option && myChart.setOption(option,true);
|
|
},
|
initGroupBarChart(xAxis2,data2,series2){
|
console.info(data2)
|
console.info(series2)
|
|
var chartDom = document.getElementById('bar22');
|
var myChart = echarts.init(chartDom);
|
var option;
|
|
option = {
|
legend: {},
|
tooltip: {},
|
toolbox: {
|
show: true,
|
feature: {
|
saveAsImage: {
|
show: true,
|
name: '人员使用统计-分组柱状图'
|
}
|
}
|
},
|
dataset: {
|
source: data2
|
},
|
xAxis: { type: 'category', name: '用户' },
|
yAxis: {
|
name: '使用时长('+this.unit[this.selectUnit]+')'
|
},
|
// Declare several bar series, each will be mapped
|
// to a column of dataset.source by default.
|
series: series2
|
};
|
|
option && myChart.setOption(option,true);
|
|
|
},
|
//查询设备列表
|
queryEquList() {
|
getAction('/limsInstrument/list').then(res => {
|
if (res.success) {
|
this.equList = res.result.records
|
}
|
|
})
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|