import React, { useState, useEffect, useRef, Component } from "react";
import { connect } from "dva";
import {
  initFilter,
  addRuleAndGroups,
  guid,
  extendInclude,
  extendRule,
  extendOrder,
  extend,
  initQueryFilter,
} from "../../../utils/common";
import { Table, Row, Col, Button, Select, DatePicker, message } from "antd";
class NotificationTaskAnalysis extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      pagination: {},
      showLoading: false,
      retData: [],
    };
  }

  componentDidMount() {
    let currentType = "1";
    if (this.props.formParam != undefined || this.props.formParam != null) {
      currentType = this.props.formParam.type;
    }
    if (currentType == 2) {
      this.state.columns1 = [
        {
          title: "序号",
          render: (text, record, index) => `${index + 1}`,
        },
        {
          title: "班组",
          dataIndex: "NAME1",
        },
        {
          title: "昨天",
          dataIndex: "NAME2",
        },
        {
          title: "今天",
          dataIndex: "NAME3",
        },
        {
          title: "明天",
          dataIndex: "NAME4",
        },
        {
          title: "后天",
          dataIndex: "NAME5",
        },
      ];
      this.loadData1();
    } else {
      this.state.columns1 = [
        {
          title: "序号",
          render: (text, record, index) => `${index + 1}`,
        },
        {
          title: "模块",
          dataIndex: "NAME1",
        },
        {
          title: "表单名称",
          dataIndex: "NAME2",
        },
        {
          title: "待办数",
          dataIndex: "NAME3",
          sorter: (a, b) => a.NAME3 - b.NAME3,
        },
        {
          title: "完成数",
          dataIndex: "NAME4",
          sorter: (a, b) => a.NAME4 - b.NAME4,
        },
        {
          title: "完成率",
          dataIndex: "NAME5",
          sorter: (a, b) => a.NAME5 - b.NAME5,
          render: (text, record) => (
            <span>
              {record.NAME5}
              {"%"}
            </span>
          ),
        },
        {
          title: "及时完成率",
          dataIndex: "NAME6",
          sorter: (a, b) => a.NAME6 - b.NAME6,
          render: (text, record) => (
            <span>
              {record.NAME6}
              {"%"}
            </span>
          ),
        },
        {
          title: "总数",
          dataIndex: "NAME7",
          sorter: (a, b) => a.NAME7 - b.NAME7,
        },
      ];
      this.loadData();
    }
  }
  loadData = () => {
    // const json = initFilter(this.props.login.OrgId);
    // this.state.showLoading = true;
    // json.Parameter1 = new Date().getFullYear() + "-01-01";
    // this.props.dispatch({
    //   type: 'app/getDataByPost',
    //   url: 'BI/BIController/getNotificationTask',
    //   payload: json,
    //   onlyData: false,
    //   onComplete: (ret) => {
    //     if (ret) {
    this.state.showLoading = false;
    let ret = {
      IsSuccessful: true,
      Data: [
        {
          NAME1: "HM123_SHOWPRINT",
          NAME2: "文件发布表",
          NAME3: 382,
          NAME4: 8,
          NAME5: "2.05",
          NAME6: "2.05",
          NAME7: 390,
        },
        {
          NAME1: "PF135",
          NAME2: "今日提醒",
          NAME3: 173,
          NAME4: 188,
          NAME5: "52.08",
          NAME6: "49.03",
          NAME7: 361,
        },
        {
          NAME1: "SE007_INPUTPAGE",
          NAME2: "培训需求用户编辑",
          NAME3: 142,
          NAME4: 1,
          NAME5: "0.70",
          NAME6: "0.70",
          NAME7: 143,
        },
        {
          NAME1: "HM001_SHOWPRINT",
          NAME2: "风险评价计划发布查看",
          NAME3: 141,
          NAME4: 2,
          NAME5: "1.40",
          NAME6: "1.40",
          NAME7: 143,
        },
        {
          NAME1: "FO003_SHOWPRINT",
          NAME2: "班前会议签到",
          NAME3: 64,
          NAME4: 20022,
          NAME5: "99.68",
          NAME6: "96.25",
          NAME7: 20086,
        },
        {
          NAME1: "BS032",
          NAME2: "检查任务制定表编辑",
          NAME3: 49,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 49,
        },
        {
          NAME1: "PF119",
          NAME2: "表单审批",
          NAME3: 25,
          NAME4: 18570,
          NAME5: "99.87",
          NAME6: "96.78",
          NAME7: 18595,
        },
        {
          NAME1: "FO010",
          NAME2: "班组安全活动记录表编辑",
          NAME3: 19,
          NAME4: 269,
          NAME5: "93.40",
          NAME6: "91.67",
          NAME7: 288,
        },
        {
          NAME1: "FO010_SHOWPRINT",
          NAME2: "班组安全活动查看",
          NAME3: 12,
          NAME4: 3155,
          NAME5: "99.62",
          NAME6: "97.85",
          NAME7: 3167,
        },
        {
          NAME1: "FO005_SHOWPRINT",
          NAME2: "岗位当班工作查看",
          NAME3: 12,
          NAME4: 20933,
          NAME5: "99.94",
          NAME6: "94.35",
          NAME7: 20945,
        },
        {
          NAME1: "FO005",
          NAME2: "岗位当班工作记录表编辑",
          NAME3: 11,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 11,
        },
        {
          NAME1: "BS073",
          NAME2: "指定责任单位",
          NAME3: 9,
          NAME4: 1,
          NAME5: "10.00",
          NAME6: "0.00",
          NAME7: 10,
        },
        {
          NAME1: "FO003",
          NAME2: "班前会议自定义编辑",
          NAME3: 8,
          NAME4: 1,
          NAME5: "11.11",
          NAME6: "11.11",
          NAME7: 9,
        },
        {
          NAME1: "FO012",
          NAME2: "岗位交接班记录表编辑",
          NAME3: 6,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 6,
        },
        {
          NAME1: "SC028_SHOWPRINT",
          NAME2: "会议通知",
          NAME3: 5,
          NAME4: 1143,
          NAME5: "99.56",
          NAME6: "90.59",
          NAME7: 1148,
        },
        {
          NAME1: "SC030",
          NAME2: "安委会纪要编辑",
          NAME3: 4,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 4,
        },
        {
          NAME1: "FO017_SHOWPRINT",
          NAME2: "关键许可工作票查看",
          NAME3: 4,
          NAME4: 2333,
          NAME5: "99.83",
          NAME6: "91.57",
          NAME7: 2337,
        },
        {
          NAME1: "FO019_SHOWPRINT",
          NAME2: "安全技术交底表签到",
          NAME3: 3,
          NAME4: 4142,
          NAME5: "99.93",
          NAME6: "94.60",
          NAME7: 4145,
        },
        {
          NAME1: "BS034",
          NAME2: "安全检查编辑",
          NAME3: 3,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 3,
        },
        {
          NAME1: "SE018",
          NAME2: "培训记录编辑",
          NAME3: 3,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 3,
        },
        {
          NAME1: "SE015_SHOWPRINT",
          NAME2: "三级安全教育审阅",
          NAME3: 3,
          NAME4: 45,
          NAME5: "93.75",
          NAME6: "85.42",
          NAME7: 48,
        },
        {
          NAME1: "SC030_SHOWPRINT",
          NAME2: "会议纪要",
          NAME3: 3,
          NAME4: 814,
          NAME5: "99.63",
          NAME6: "94.25",
          NAME7: 817,
        },
        {
          NAME1: "CM030_SHOWPRINT",
          NAME2: "应急装备需求调查表",
          NAME3: 3,
          NAME4: 3,
          NAME5: "50.00",
          NAME6: "0.00",
          NAME7: 6,
        },
        {
          NAME1: "SC028",
          NAME2: "安委会通知编辑",
          NAME3: 2,
          NAME4: 9,
          NAME5: "81.82",
          NAME6: "81.82",
          NAME7: 11,
        },
        {
          NAME1: "CM034",
          NAME2: "应急演练活动记录编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "SE008",
          NAME2: "培训需求调查编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "FO015",
          NAME2: "作业活动记录表编辑(一般)",
          NAME3: 2,
          NAME4: 1,
          NAME5: "33.33",
          NAME6: "33.33",
          NAME7: 3,
        },
        {
          NAME1: "FO013_SHOWPRINT",
          NAME2: "岗位交接单消息查看",
          NAME3: 2,
          NAME4: 9932,
          NAME5: "99.98",
          NAME6: "96.58",
          NAME7: 9934,
        },
        {
          NAME1: "BS032_SHOWPRINT",
          NAME2: "安全检查制表审核表查看",
          NAME3: 2,
          NAME4: 6068,
          NAME5: "99.97",
          NAME6: "93.67",
          NAME7: 6070,
        },
        {
          NAME1: "BS057",
          NAME2: "安全检查编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "SE017_SHOWPRINT",
          NAME2: "培训记录查看",
          NAME3: 2,
          NAME4: 1394,
          NAME5: "99.86",
          NAME6: "85.60",
          NAME7: 1396,
        },
        {
          NAME1: "SE014",
          NAME2: "培训通知编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "SE006",
          NAME2: "安全意识调查编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "BS044",
          NAME2: "隐患整改记录编辑",
          NAME3: 2,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 2,
        },
        {
          NAME1: "SE019_SHOWPRINT",
          NAME2: "培训效果评估表查看",
          NAME3: 1,
          NAME4: 3,
          NAME5: "75.00",
          NAME6: "75.00",
          NAME7: 4,
        },
        {
          NAME1: "BS049",
          NAME2: "确定整改落实人",
          NAME3: 1,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 1,
        },
        {
          NAME1: "BS042_SHOWPRINT",
          NAME2: "隐患通知责任人",
          NAME3: 1,
          NAME4: 196,
          NAME5: "99.49",
          NAME6: "94.42",
          NAME7: 197,
        },
        {
          NAME1: "SE012",
          NAME2: "年度培训计划编辑",
          NAME3: 1,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 1,
        },
        {
          NAME1: "BS042_ACTUALCHECK",
          NAME2: "整改落实人确认",
          NAME3: 1,
          NAME4: 72,
          NAME5: "98.63",
          NAME6: "98.63",
          NAME7: 73,
        },
        {
          NAME1: "FO021",
          NAME2: "作业活动记录表(关键/许可)编辑",
          NAME3: 1,
          NAME4: 0,
          NAME5: "0.00",
          NAME6: "0.00",
          NAME7: 1,
        },
        {
          NAME1: "BS046_SHOWPRINT",
          NAME2: "延期整改申请",
          NAME3: 1,
          NAME4: 1,
          NAME5: "50.00",
          NAME6: "50.00",
          NAME7: 2,
        },
        {
          NAME1: "SE011_SHOWPRINT",
          NAME2: "年度培训计划查看",
          NAME3: 1,
          NAME4: 2,
          NAME5: "66.67",
          NAME6: "33.33",
          NAME7: 3,
        },
        {
          NAME1: "SE018_PAPERPAGE",
          NAME2: "培训记录答题页",
          NAME3: 1,
          NAME4: 15,
          NAME5: "93.75",
          NAME6: "93.75",
          NAME7: 16,
        },
        {
          NAME1: "HM061_SHOWPRINT",
          NAME2: "危险源/风险辨识任务查看",
          NAME3: 0,
          NAME4: 5,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 5,
        },
        {
          NAME1: "HM102",
          NAME2: "职业危害辨识任务表编辑",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "CM036_SHOWPRINT",
          NAME2: "演练效果评估表",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "SE005_SHOWPRINT",
          NAME2: "安全意识调查列表查看",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "HM099_SHOWPRINT",
          NAME2: "职业危害辨识记录查看",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "SE013_SHOWPRINT",
          NAME2: "培训通知查看",
          NAME3: 0,
          NAME4: 1224,
          NAME5: "100.00",
          NAME6: "85.05",
          NAME7: 1224,
        },
        {
          NAME1: "HM063_SHOWPRINT",
          NAME2: "危险源/风险辨识记录表查看",
          NAME3: 0,
          NAME4: 7,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 7,
        },
        {
          NAME1: "BS044_SHOWPRINT",
          NAME2: "隐患整改记录",
          NAME3: 0,
          NAME4: 97,
          NAME5: "100.00",
          NAME6: "85.57",
          NAME7: 97,
        },
        {
          NAME1: "CM028",
          NAME2: "应急物资库编辑",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "0.00",
          NAME7: 1,
        },
        {
          NAME1: "SE009_SHOWPRINT",
          NAME2: "部门培训计划查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "HM121_SHOWPRINT",
          NAME2: "评价结果表查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "BS044_CHECK",
          NAME2: "隐患整改审批",
          NAME3: 0,
          NAME4: 199,
          NAME5: "100.00",
          NAME6: "99.50",
          NAME7: 199,
        },
        {
          NAME1: "BS034_VIEW",
          NAME2: "安全检查查看",
          NAME3: 0,
          NAME4: 4207,
          NAME5: "100.00",
          NAME6: "94.03",
          NAME7: 4207,
        },
        {
          NAME1: "HM111_SHOWPRINT",
          NAME2: "一般任务分析表查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "FO021_SHOWPRINT",
          NAME2: "作业活动记录表(关键和许可)签字",
          NAME3: 0,
          NAME4: 3878,
          NAME5: "100.00",
          NAME6: "97.40",
          NAME7: 3878,
        },
        {
          NAME1: "HM002",
          NAME2: "风险评价计划发布编辑",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "CM034_SHOWPRINT",
          NAME2: "应急演练活动记录查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "BS074_SHOWPRINT",
          NAME2: "隐患通知编辑",
          NAME3: 0,
          NAME4: 3,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 3,
        },
        {
          NAME1: "CM023_SHOWPRINT",
          NAME2: "应急响应评估",
          NAME3: 0,
          NAME4: 3,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 3,
        },
        {
          NAME1: "SC030_SHOWPRINTPER",
          NAME2: "纪要决议落实",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "HM101_SHOWPRINT",
          NAME2: "职业危害辨识任务查看",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "BS006_VIEW",
          NAME2: "隐患上报查看",
          NAME3: 0,
          NAME4: 88,
          NAME5: "100.00",
          NAME6: "92.05",
          NAME7: 88,
        },
        {
          NAME1: "FO008_SHOWPRINT",
          NAME2: "作业方案讨论记录查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "BS073_SHOWPRINT",
          NAME2: "手动上报-指定责任单位",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "HM087_SHOWPRINT",
          NAME2: "作业任务识别分析表查看",
          NAME3: 0,
          NAME4: 6,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 6,
        },
        {
          NAME1: "HM104_SHOWPRINT",
          NAME2: "作业任务识别查看",
          NAME3: 0,
          NAME4: 4,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 4,
        },
        {
          NAME1: "CM018_SHOWPRINT",
          NAME2: "潜在紧急事件",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "0.00",
          NAME7: 1,
        },
        {
          NAME1: "SE007_SHOWPRINT",
          NAME2: "培训需求调查查看",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "CM032_SHOWPRINT",
          NAME2: "应急装备需求调查汇总",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "50.00",
          NAME7: 2,
        },
        {
          NAME1: "BS049_SHOWPRINT",
          NAME2: "指定整改落实人",
          NAME3: 0,
          NAME4: 86,
          NAME5: "100.00",
          NAME6: "90.70",
          NAME7: 86,
        },
        {
          NAME1: "HM062",
          NAME2: "危险源/风险辨识任务编辑",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "HM042_SHOWPRINT",
          NAME2: "年度风险评价计划审核表查看",
          NAME3: 0,
          NAME4: 3,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 3,
        },
        {
          NAME1: "CM002_SHOWPRINT",
          NAME2: "年度应急演练计划",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "HM064",
          NAME2: "危险源/风险辨识记录表编辑",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
        {
          NAME1: "FO015_SHOWPRINT",
          NAME2: "作业活动记录表(一般)",
          NAME3: 0,
          NAME4: 12829,
          NAME5: "100.00",
          NAME6: "98.88",
          NAME7: 12829,
        },
        {
          NAME1: "SE021_SHOWPRINT",
          NAME2: "培训效果评估调查表查看",
          NAME3: 0,
          NAME4: 252,
          NAME5: "100.00",
          NAME6: "99.60",
          NAME7: 252,
        },
        {
          NAME1: "HM107_SHOWPRINT",
          NAME2: "许可作业分析表查看",
          NAME3: 0,
          NAME4: 2,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 2,
        },
        {
          NAME1: "CM031_SHOWPRINT",
          NAME2: "应急装备需求调查表",
          NAME3: 0,
          NAME4: 1,
          NAME5: "100.00",
          NAME6: "100.00",
          NAME7: 1,
        },
      ],
      TotalCount: 0,
      MessageType: 0,
    };
    ret.Data.sort((a, b) => {
      if (a.NAME3 > b.NAME3) {
        return -1;
      } else if (a.NAME3 < b.NAME3) {
        return 1;
      } else {
        return 0;
      }
    });
    this.setState({
      retData: ret.Data,
    })
    // this.state.retData = ret.Data;
    //     }
    //   }
    // })
  };
  loadData1 = () => {
    const json = initFilter(this.props.login.OrgId);
    this.state.showLoading = true;
    this.props.dispatch({
      type: "app/getDataByPost",
      url: "BI/BIController/getScheduling",
      payload: json,
      onlyData: false,
      onComplete: (ret) => {
        if (ret) {
          this.state.showLoading = false;
          this.state.retData = ret.Data;
        }
      },
    });
  };

  onChange = (type, value) => {
    this.setState({
      [type]: value,
    });
  };
  paginationConfig = {
    // pageSizeOptions: ["10", "20", "50", "100"],
    pageSize: 50,
    // showSizeChanger: true,
    size: "small",
  };
  render() {
    return (
      <div
        style={{
          backgroundColor: "white",
          width: "1200px",
          top: "0",
          bottom: "0",
          left: "0",
          right: "0",
          margin: "auto",
          borderStyle: "solid",
          borderColor: "#ccc",
          borderWidth: "1px",
        }}
      >
        <h1
          style={{ textAlign: "center", marginTop: "30px", fontWeight: "bold" }}
        >
          待办统计
        </h1>
        <hr
          style={{
            border: "1px dashed #ccc",
            marginBottom: "20px",
            marginTop: "20px",
          }}
        ></hr>
        <Row gutter={10} style={{ marginTop: "14px" }}>
          <Col span={1}></Col>
          <Col span={22} style={{ height: "100%" }}>
            <div
              className="dashboard-div-style"
              style={{ boxShadow: "0px 0px 10px rgba(0,0,0,.15)" }}
            >
              <Table
                dataSource={this.state.retData}
                columns={this.state.columns1}
                pagination={this.paginationConfig}
                bordered
                loading={this.state.showLoading}
                size="small"
                rowKey="1"
              />
            </div>
          </Col>
          <Col span={1}></Col>
        </Row>
        <br />
      </div>
    );
  }
}
export default connect(({ login, app }) => ({ login, app }))(
  NotificationTaskAnalysis
);
