import React, { useState, useEffect, useRef, Component } from 'react'
import { connect } from 'dva'
import { initFilter, addRuleAndGroups, guid, extendInclude, extendRule, extendOrder, extend } from "../../../utils/common"
import { Table, Row, Col, Button, Select,DatePicker ,Form,Spin,message} from 'antd';
import echarts from 'echarts';
import moment from 'moment'
import { IFComponent } from '@woowalker/feui';
import DropDownPagination from '../../common/DropDownPaginationEx'
import XLSX from 'xlsx';
const { Option } = Select;
class BI010FormRunAnalysis extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      startTime:moment(this.getDate(), 'YYYY-MM-DD 00:00:00'),//moment(new Date()).add(-1, "month").format('YYYY-MM-DD 00:00:00'),
      endTime:moment(this.getEndDate(), 'YYYY-MM-DD 23:59:59'),
      pagination: {},
      departData:[],
      retData:[],
      columns:[
        {
            width: "100px",
            title: '模块',
            dataIndex: 'MOUDLE_NAME',
            key: 'MOUDLE_NAME',
            render:(value,record,index)=>{
                const obj={
                    children:value,
                    props:{}
                };
                let arr=this.state.retData.filter((res)=>{
                    return res.MOUDLE_NAME==record.MOUDLE_NAME;
                });
                if(index==0 || this.state.retData[index-1].MOUDLE_NAME!=record.MOUDLE_NAME)
                {
                    obj.props.rowSpan=arr.length;
                }else{
                    obj.props.rowSpan=0;
                }
                return obj;
            },
          },
          {
            width: "200px",
            title: '任务',
            dataIndex: 'FORM_NAME',
            key: 'FORM_NAME'
          },
          {
            width: "80px",
            title: '总任务数',
            dataIndex: 'TOTAL_QTY',
            key: 'TOTAL_QTY'
          },
          {
            width: "80px",
            title: '正常已办',
            dataIndex: 'FINISH_QTY',
            key: 'FINISH_QTY'
          },
          {
            width: "80px",
            title: '超时已办',
            dataIndex: 'OVER_FINISH_QTY',
            key: 'OVER_FINISH_QTY'
          },
          {
            width: "80px",
            title: '未完成',
            dataIndex: 'UNFINISH_QTY',
            key: 'UNFINISH_QTY',
          },
          {
            width: "80px",
              title: '完成率',
              dataIndex: 'FINISH_RATE',
              key: 'FINISH_RATE',
            },
            {
              width: "80px",
            title: '及时完成率',
            dataIndex: 'NORMAL_FINISH_RATE',
            key: 'NORMAL_FINISH_RATE',
          },
            {
                width: "100px",
              title: '备注',
              dataIndex: 'REMARK',
              key: 'REMARK',
            }
    ]
    };
  };

  componentDidMount() {
    this.getBaseInfoData();
  };
  //获取数据
  getBaseInfoData = () => {
   let allData= [{
      MOUDLE_NAME : "标准化创建",
FORM_NAME :"制度创建",
NUM : 1,
TOTAL_QTY : 0,
FINISH_QTY : 0,
OVER_FINISH_QTY : 0,
UNFINISH_QTY : 0,
FINISH_RATE : "0%",
NORMAL_FINISH_RATE : "0%",
REMARK:'',
    },{
      MOUDLE_NAME : "标准化创建",
      FORM_NAME :"责任制创建",
      NUM : 2,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "标准化创建",
      FORM_NAME :"岗位安全操作规程和指导书",
      NUM : 3,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "标准化创建",
      FORM_NAME :"应急预案修订记录",
      NUM : 4,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "方针与目标",
      FORM_NAME :"安全生产方针调查",
      NUM : 5,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "方针与目标",
      FORM_NAME :"公司安全生产目标与指标制定",
      NUM : 6,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "方针与目标",
      FORM_NAME :"部门车间班组安全生产目标与指标制定",
      NUM : 7,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "方针与目标",
      FORM_NAME :"考核方案审核",
      NUM : 8,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "方针与目标",
      FORM_NAME :"监测与考核记录",
      NUM : 9,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "会议管理",
      FORM_NAME :"普通会议通知",
      NUM : 10,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "会议管理",
      FORM_NAME :"安委会通知",
      NUM : 11,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "会议管理",
      FORM_NAME :"普通会议纪要",
      NUM : 12,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "会议管理",
      FORM_NAME :"安委会纪要",
      NUM : 13,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"安全意识调查",
      NUM : 14,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"培训需求调查",
      NUM : 15,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"部门培训计划",
      NUM : 16,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"年度培训计划",
      NUM : 17,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"培训通知",
      NUM : 18,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"培训记录",
      NUM : 19,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"三级安全教育卡",
      NUM : 20,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "安全教育培训",
      FORM_NAME :"培训效果评估表",
      NUM : 21,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "法律法规",
      FORM_NAME :"法律法规与其他要求",
      NUM : 22,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "法律法规",
      FORM_NAME :"法律法规需求分析表",
      NUM : 23,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "法律法规",
      FORM_NAME :"获取清单",
      NUM : 24,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "安全生产组织保障",
      FORM_NAME :"安全生产责任制签订表",
      NUM : 25,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },
    {
      MOUDLE_NAME : "安全生产组织保障",
      FORM_NAME :"考核记录",
      NUM : 26,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
      MOUDLE_NAME : "安全生产组织保障",
      FORM_NAME :"员工意见征集表",
      NUM : 27,
      TOTAL_QTY : 0,
      FINISH_QTY : 0,
      OVER_FINISH_QTY : 0,
      UNFINISH_QTY : 0,
      FINISH_RATE : "0%",
      NORMAL_FINISH_RATE : "0%",
      REMARK:'',
    },{
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"员工意见上报表",
        NUM : 28,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      },
      {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"员工拒绝事项上报表",
        NUM : 29,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      },
      {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"内部联系记录表",
        NUM : 30,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"外部联系沟通记录",
        NUM : 31,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"外部单位投诉建议",
        NUM : 32,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"认可与奖励上报表",
        NUM : 33,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"工余事件征集",
        NUM : 34,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"工余事件上报及处理表",
        NUM : 35,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      }, {
        MOUDLE_NAME : "安全生产组织保障",
        FORM_NAME :"标准化系统评审意见表",
        NUM : 36,
        TOTAL_QTY : 0,
        FINISH_QTY : 0,
        OVER_FINISH_QTY : 0,
        UNFINISH_QTY : 0,
        FINISH_RATE : "0%",
        NORMAL_FINISH_RATE : "0%",
        REMARK:'',
      },]
    let retDataTemp=[]
    const{retData,startTime,endTime}=this.state
    let time=startTime
    if(startTime === null)
    {
      message.error('请选择开始时间');
    }
    let time2=endTime
    if(endTime === null)
    {
      message.error('请选择结束时间');
    }
    
    {
      time=moment(startTime).format('YYYY-MM-DD HH:mm:ss')
      time2=moment(endTime).format('YYYY-MM-DD HH:mm:ss')
      const json = initFilter(this.props.login.OrgId,this.state.DEPARTMENT_ID,'','','',time,time2)
      //extendOrder(json, "NUM", 0);
      this.props.dispatch({
        type: 'app/getDataByPost',
        url: 'BI/BIStatiscialAnalysisController/GetFormRunSix',//BI/FormRunAnalysis/OrderEntities
        payload: json,
        onlyData: false,
        onComplete: (ret) => {
         
          if(ret && ret.Data)
          {
            let t1 = 0;
            let t2 = 0;
            let t3 = 0;
            let t4 = 0;
            let temp=[];
            for (let i = 0; i < ret.Data.length; i++) {
              t1 = t1 + ret.Data[i].TOTAL_QTY;
              t2 = t2 + ret.Data[i].FINISH_QTY;
              t3 = t3 + ret.Data[i].OVER_FINISH_QTY;
              t4 = t4 + ret.Data[i].UNFINISH_QTY;
              temp.push(ret.Data[i]);
            }
            let t5 = t1===0?"0%": ((t2+t3)/t1 *100).toFixed(0)+"%";
            let t6 =  t1===0?"0%":(t2/t1 *100).toFixed(0)+"%";
            let tempLast={
                MOUDLE_NAME:"",
                FORM_NAME:"合计",
                TOTAL_QTY:t1,
                FINISH_QTY:t2,
                OVER_FINISH_QTY:t3,
                UNFINISH_QTY:t4,FINISH_RATE:t5,
                NORMAL_FINISH_RATE:t6,REMARK:"",NUM:100};
            // temp.push(tempLast);
           
            allData.forEach(t=>{
            let form=temp.filter(t1=>t1.MOUDLE_NAME===t.MOUDLE_NAME && t1.FORM_NAME ===t.FORM_NAME)
            if(form.length>0)
            {
              t.TOTAL_QTY=form[0].TOTAL_QTY
              t.FINISH_QTY=form[0].FINISH_QTY
              t.OVER_FINISH_QTY=form[0].OVER_FINISH_QTY
              t.UNFINISH_QTY=form[0].UNFINISH_QTY
              t.FINISH_RATE=form[0].FINISH_RATE
              t.NORMAL_FINISH_RATE=form[0].NORMAL_FINISH_RATE
            }
            retDataTemp.push(t);
            });
            retDataTemp.push(tempLast);
          }
        
          
          // this.chart1(ret);
          // this.chart2(ret);
        }
      })
    }
    this.setState({retData :retDataTemp?retDataTemp:allData})
  };
  startChange=(value)=>{
    this.setState({
      startTime:value
    })
  };
  endChange=(value)=>{
    this.setState({
      endTime:value
    })
  };
  onSelectDepartment=(departData,record)=>{
    if (departData && departData.data && departData.data.length > 0) {
      this.setState({
        departData: {
          ...this.state.departData,
          // DEPARTMENT_ID: departData.data[0],
          Nav_Department: { NAME: departData.record.NAME }
        },
        DEPARTMENT_ID: departData.data[0],
      })
    }
    else {
      this.setState({
        departData: {
          ...this.state.departData,
          Nav_Department: { NAME: null },
        },
        DEPARTMENT_ID: null,
      })
    };
  }
  getDate=()=>{
    let  date = new Date()
    let  y = date.getFullYear()
    let  m = date.getMonth() + 1
    let  d = date.getDate();
    //  当前日期
    let nowDate = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
    //   一月的时候年份要减一
    //  if(m == 1) {    	
    //     y--
    //     m = 12
    //   }else if(m == 3 && d > 28) {
     
    //     //三月要考虑是否为闰年
    //      m--
    //      if(y%4 == 0 && y%100!=0 || y%400 == 0) {
    //          d = 29
    //      }else {
    //          d-28
    //      }
    //    }else if((m != 12 || m != 8 )&& d == 31) {
            
    //         //31号的月份要考虑上个月是否有31号
    //         m--
    //         d = 30
    //     }else {
    //         m--
    //     }

         // 一个月前的日期(默认月份)
         //let pastDate = y + (m < 10 ? "0" + m : m) + (d < 10 ? "0" + d : d)
         let pastDate = moment(nowDate).add(-1, "day").format('YYYY-MM-DD 00:00:00')
        return pastDate;
}
getEndDate=()=>{
  let  date = new Date()
  let  y = date.getFullYear()
  let  m = date.getMonth() + 1
  let  d = date.getDate();
  //  当前日期
  let nowDate = y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
       let pastDate = moment(nowDate).add(-1, "day").add(23,'hour').add(59,'m').add(59,'s')//format('YYYY-MM-DD 23:59:59')
      return pastDate;
}
onTableBtnExport() {
  console.log(this.state.retData)
  // this.props.dispatch({
  //   type: 'app/getDataByPost',
  //   url: 'BI/BIStatiscialAnalysisController/NpoiExcel',//BI/FormRunAnalysis/OrderEntities
  //   payload: this.state.retData,
  //   onlyData: false,
  //   onComplete: (ret) => {
     
  //   }
  // })
  if (this.state.retData.length == 0) {
    message.warning("没有数据无需导出!");
    return;
  }
  // let sheetFilter = ["MOUDLE_NAME", "FORM_NAME","TOTAL_QTY","FINISH_QTY","OVER_FINISH_QTY","UNFINISH_QTY","FINISH_RATE","NORMAL_FINISH_RATE","REMARK"]
  // let option = {
  //     fileName: '基本信息', // 导出默认文件名
  //     datas: [
  //         {
  //             sheetData: mockData, // 保存至表格的数据
  //             sheetName: '', // excel表格sheet默认名称
  //             sheetFilter: sheetFilter,
  //             sheetHeader: ["模块", "任务","总任务数","正常已办","超时已办","未完成","完成率","及时完成率","备注"], // 表格-表头
  //             columnWidths: ['6', '6', '6','6', '6', '6','6', '6', '6'], // 单元格宽度
  //         },
  //     ]
  // }
  // var toExcel = new ExportJsonExcel(option) // 创建新的模板
  // toExcel.saveExcel() // 保存
      //excel的表头
      const tHeader = ["模块", "任务","总任务数","正常已办","超时已办","未完成","完成率","及时完成率","备注"];
      // 字段和table表格中对应
      const fitlerVal = ["MOUDLE_NAME", "FORM_NAME","TOTAL_QTY","FINISH_QTY","OVER_FINISH_QTY","UNFINISH_QTY","FINISH_RATE","NORMAL_FINISH_RATE","REMARK"];
      const res = this.state.retData.map((v) => fitlerVal.map((j) => v[j]));
      // const jsonWorkSheet = XLSX.utils.json_to_sheet(tHeader,res,"矿山安全生产标准化系统运行情况报表.xlsx");
      const jsonWorkSheet = XLSX.utils.json_to_sheet(res,tHeader);
      jsonWorkSheet.A1.v='模块';
      jsonWorkSheet.B1.v='任务';
      jsonWorkSheet.C1.v='总任务数';
      jsonWorkSheet.D1.v='正常已办';
      jsonWorkSheet.E1.v='超时已办';
      jsonWorkSheet.F1.v='未完成';
      jsonWorkSheet.G1.v='完成率';
      jsonWorkSheet.H1.v='及时完成率';
      jsonWorkSheet.I1.v='备注';
      const sheetName = "矿山安全生产标准化系统运行情况报表";
      const workBook = {
        SheetNames: [sheetName],
        Sheets: {
          [sheetName]: jsonWorkSheet,
        }
      };
      //  const workBook = XLSX.utils.table_to_book("矿山安全生产标准化系统运行情况报表",jsonWorkSheet);
      return XLSX.writeFile(workBook, "矿山安全生产标准化系统运行情况报表.xlsx");
  // let TableWrap = document.getElementById('tableId' + this.props.data.id);
  // let Table = TableWrap.getElementsByTagName('Table')[0];
  // const wb = XLSX.utils.table_to_book(Table);
  // XLSX.writeFile(wb, "矿山安全生产标准化系统运行情况报表.xlsx")
}

  render() {
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
    }
    const {loading} = this.props;
    return (
      <div>
        <Spin spinning={loading.global}>
        <h1 style={{ textAlign: "center" }}>矿山安全生产标准化系统运行情况报表</h1>
        <Row style={{width:"1000px",margin:"auto"}}>
          <Col span={6} style={{ marginLeft: "20px" }}> 
          <Form.Item
                  label={'开始时间：'}
                  {...formItemLayout}
                >
                   <DatePicker showTime 
                  //  defaultValue={moment(this.state.startTime, 'YYYY-MM-DD 00:00:00')}
                   value={this.state.startTime} 
                   format="YYYY-MM-DD HH:mm:ss"  onChange={this.startChange}/>
                </Form.Item>
               
          </Col>
         
          <Col span={6} style={{ marginLeft: "20px" }}>
          <Form.Item
                  label={'结束时间：'}
                  {...formItemLayout}
                >
                   <DatePicker showTime 
                    // defaultValue={moment(this.state.endTime, 'YYYY-MM-DD 23:59:59')}
                   value={this.state.endTime}
                   format="YYYY-MM-DD HH:mm:ss"  onChange={this.endChange}/>
                </Form.Item>
           </Col>
          <Col span={6} style={{ marginLeft: "20px" }}>
          <Form.Item
                  label={'选择部门：'}
                  {...formItemLayout}
                >
                   <DropDownPagination inputDataApi={'FM/Department/OrderPaged'} fieldName={'Nav_Department.NAME'}
                    data={this.state.departData} onSelect={this.onSelectDepartment} onFilter={({ params }) => {
                      params.OrderType = 1
                      params.OrgId = this.state.departData ? this.state.departData.ORG_ID : this.props.login.OrgId
                      // extendRule(params, 'DEPARTMENT_TYPE', 1, 0)
                    }} 
                    style={{width:'300px'}}
                    />
                </Form.Item>
           </Col>
          <Col span={1} style={{ marginLeft: "20px" }}><Button type='primary' onClick={() => this.getBaseInfoData()}>查询</Button></Col>
          <Col span={1} style={{ marginLeft: "50px" }}><Button icon="export" onClick={() => this.onTableBtnExport()}>导出</Button></Col>
        </Row>
        <Row style={{ marginTop: "14px" }}>
          <div id="exportToExcel">
          <Table style={{ width:"1000px",margin:"auto",alignContent:"center",backgroundColor:"white"}}
                dataSource={this.state.retData}
                columns={this.state.columns}
                pagination={false}
                bordered
                loading={this.state.showLoading}
                size="small"
                rowKey="2"
              />
          </div>
              
        </Row>
        {/* <Row>
        <h5 style={{ textAlign: "center" }}>数据统计截止到{this.state.modifyTime}</h5>
        </Row> */}
        </Spin>
      </div>
    )
  }
}
export default connect(({ login, app,loading }) => ({ login, app,loading }))(BI010FormRunAnalysis)
