<template>
  <base-list @showHeader="tableHeight=660" @hideHeader="tableHeight=560">
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item>
          <div class="block">
            <el-date-picker
              v-model="CreateDate"
              type="daterange"
              range-separator="至"
              start-placeholder="操作开始日期"
              value-format="yyyy-MM-dd"
              end-placeholder="操作结束日期"
            />
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getData()">搜索</el-button>
        </el-form-item>
      </el-form>
    </template>
    <el-table
      v-loading="loading"
      :data="sData"
      border
      height="660"
      :span-method="arraySpanMethod"
    >
      <el-table-column label="当月工单量合计" prop="SumQty" align="center" />
      <el-table-column label="客户" prop="Name" />
      <el-table-column label="完成工作量" prop="Qty" />
      <el-table-column label="24小时内有效处理量" prop="_24Qty" />
      <el-table-column label="平均完成时长" prop="Avg" />
    </el-table>
  </base-list>
</template>
<script>
import BaseList from '@/components/Xyy/baselist'
import { _getTransferLogAnalysis } from '@/api/transferLog'
export default {
  name: 'TransferLogAnalysis',
  components: { 'base-list': BaseList },
  data() {
    return {
      loading: false,
      sData: [],
      CreateDate: []
    }
  },
  mounted() {
    var end = new Date()
    this.CreateDate = ['2021-06-01', this.DateFormat(end, 'yyyy-MM-dd')]
    this.getData()
  },
  methods: {
    getData() {
      this.loading = true
      _getTransferLogAnalysis({ start: this.CreateDate[0], end: this.CreateDate[1] }).then(r => {
        this.sData = r
      }).finally(r => {
        this.loading = false
      })
    }, DateFormat(d, format) {
      var date = {
        'M+': d.getMonth() + 1,
        'd+': d.getDate(),
        'h+': d.getHours(),
        'm+': d.getMinutes(),
        's+': d.getSeconds(),
        'q+': Math.floor((d.getMonth() + 3) / 3),
        'S+': d.getMilliseconds()
      }
      if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      for (var k in date) {
        if (new RegExp('(' + k + ')').test(format)) {
          format = format.replace(RegExp.$1, RegExp.$1.length == 1
            ? date[k] : ('00' + date[k]).substr(('' + date[k]).length))
        }
      }
      return format
    },
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex === 0) {
          return {
            rowspan: this.sData.length,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    }
  }
}
</script>
