<template>
  <ve-bar :data="chartData" :title="title" :settings="chartSettings"/>
</template>

<script>
import { getDayTime } from '@/utils/dateutils'
import { jobStaticsByDept } from '@/api/dataStatics'

export default {
  name: 'JobByStatus',
  data() {
    this.title = {
      text: '30日工单数量统计'
    }
    this.chartSettings = {
      labelMap: {
        'deptName': '权属单位',
        'beforeGet': '待处理',
        'beforeConfirm': '待确认',
        'inHandle': '处理中',
        'over': '已完成'
      },
      stack: {
        'xxx': ['beforeGet', 'beforeConfirm', 'inHandle', 'over']
      }
    }
    return {
      chartData: {
        columns: ['deptName', 'beforeGet', 'beforeConfirm', 'inHandle', 'over'],
        rows: []
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  activated() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const beginTime = getDayTime(new Date().getTime() - 24 * 30 * 60 * 60 * 1000).Format('yyyy-MM-dd hh:mm:ss')
      const endTime = new Date().Format('yyyy-MM-dd hh:mm:ss')
      const listQuery = {
        beginTime: beginTime,
        endTime: endTime
      }
      jobStaticsByDept(listQuery).then(response => {
        this.chartData.rows = response.data
      })
    }
  }
}
</script>
