zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<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>