import React, { useState, useEffect } from 'react';
import { Modal, Table } from 'antd';
import { connect } from 'dva';
import moment from 'moment';

function UserRptModal(props) {
  const { dispatch, visible, onOk, onCancel, data, filter, loading } = props;
  const columns = [
    {
      title: '用户名称',
      dataIndex: 'c_name',
    },
    {
      title: '员工号',
      dataIndex: 'user_name',
    },
    {
      title: '执行项目人日',
      dataIndex: 'type_project_cnt',
    },
    {
      title: '售前支持',
      dataIndex: 'type_sale_cnt',
    },
    {
      title: '市场品牌',
      dataIndex: 'type_market_cnt',
    },
    {
      title: '日常',
      dataIndex: 'type_normal_cnt',
    },
    {
      title: '标准化',
      dataIndex: 'type_standardize_cnt',
    },
    {
      title: '研发',
      dataIndex: 'type_rd_cnt',
    },
    {
      title: '漏填工时',
      dataIndex: 'type_lost_cnt',
    },
    {
      title: '总计',
      dataIndex: 'total_cnt',
    },
    {
      title: '有效利用率',
      dataIndex: 'usage_percent',
      render: (percent = 0) => (percent * 100).toFixed(2) + '%',
    },
    // {
    //   title: '付费工时数',
    //   dataIndex: 'pay_workload_cnt',
    // },
    // {
    //   title: '付费工时率',
    //   dataIndex: 'pay_workload_percent',
    //   render: (percent = 0) => (percent * 100).toFixed(2) + '%',
    // },
  ];
  const onChangePage = pagination => {
    dispatch({
      type: 'report/queryUserReport',
      payload: {
        ...filter,
        currentPage: pagination.current,
      },
    });
  };
  useEffect(() => {
    if (!filter?.dep_id) return;
    dispatch({
      type: 'report/queryUserReport',
      payload: filter,
    });
  }, [filter]);

  return (
    <Modal title="工时" width="80%" visible={visible} onCancel={onCancel} footer={false}>
      <Table
        columns={columns}
        loading={loading}
        dataSource={data.list}
        pagination={data.pagination}
        onChange={onChangePage}
      ></Table>
    </Modal>
  );
}

export default connect(({ report, loading }) => ({
  data: report.depUser,
  loading: loading.models.report,
}))(UserRptModal);
