/*
 * @Author: Chengliang 1546584672@qq.com
 * @Date: 2023-09-11 15:33:27
 * @LastEditors: Chengliang 1546584672@qq.com
 * @LastEditTime: 2023-09-15 11:39:05
 * @FilePath: /org-chart-frant/src/pages/statisticsTable.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useEffect, useState, useRef } from 'react';
import * as d3 from 'd3';
import qs from 'qs';
import { Table } from 'antd';
import { getLabel } from '../util/i18n.js';

const StatisticsTable = () => {
  const [loading, setLoading] = useState(true);
  const [dataSource, setDataSource] = useState([]);
  const [columns, setColumns] = useState([]);
  const [labelData, setLabelData] = useState({});

  useEffect(() => {
    d3.json('/api/bs/hrmorganization/orgchart/i18n').then((res) => {
      setLabelData(res.data);
      const columns = [
        {
          title: `${getLabel(547327, res.data)}`,
          dataIndex: 'key',
          key: 'key',
        },
        {
          title: `${getLabel(547517, res.data)}`,
          dataIndex: 'dataIdName',
          key: 'dataIdName',
        },
        {
          title: `${getLabel(547518, res.data)}`,
          dataIndex: 'superIdName',
          key: 'superIdName',
        },
        {
          title: `${getLabel(547519, res.data)}`,
          dataIndex: 'type',
          key: 'type',
          render(value, row, index) {
            if (value == 1) {
              return `${getLabel(547332, res.data)}`;
            } else {
              return `${getLabel(547331, res.data)}`;
            }
          },
        },
        {
          title: `${getLabel(547346, res.data)}`,
          dataIndex: 'onJobNum',
          key: 'onJobNum',
        },
        {
          title: `${getLabel(547345, res.data)}`,
          dataIndex: 'staffNum',
          key: 'staffNum',
        },
        {
          title: `${getLabel(547520, res.data)}`,
          dataIndex: 'creator',
          key: 'creator',
        },
        {
          title: `${getLabel(547521, res.data)}`,
          dataIndex: 'createTime',
          key: 'createTime',
        },
        {
          title: `${getLabel(547522, res.data)}`,
          dataIndex: 'updateTime',
          key: 'updateTime',
        },
      ];
      setColumns(columns);
      selectData();
    });
  }, []);

  const selectData = () => {
    d3.json(`/api/bs/hrmorganization/orgchart/selectStatistics`).then((res) => {
      setDataSource(res.data.result);
      setLoading(false);
    });
  };

  return (
    <>
      <div style={{ padding: '50px' }}>
        <Table
          dataSource={dataSource}
          columns={columns}
          loading={loading}
          pagination={{
            showTotal: (total) =>
              `${getLabel(547523, labelData)} ${dataSource.length} ${getLabel(
                547524,
                labelData,
              )}`,
          }}
        />
        ;
      </div>
    </>
  );
};
export default StatisticsTable;
