
import React, { useCallback, useMemo } from 'react'
import moment from 'moment';
import { Button, DatePicker } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { getList } from '@/services/org'
import PageTable from '@/components/PageTable'
import { history } from 'umi';

const formatterTime = (val) => {
  return val ? moment(val).format('YYYY-MM-DD HH:mm') : '';
};

export default (props) => {
  // document.title='666'
  const handleClick = () => {
    history.push('/org/edit');
  }
  const AddNew = useMemo(() => (
    <Button type="primary" icon={<PlusOutlined />} onClick={handleClick}>
      新增企业
    </Button>
  ), [])

  const columns = [
    {
      title: '企业名称',
      dataIndex: 'orgName',
      key: 'orgName',
      search: true,
    },
    {
      title: '创建时间',
      dataIndex: 'createDate',
      key: 'createDate',
      search: false,
      render: (t) => formatterTime(t)
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      ellipsis: true,
      render: (_, record) => [
        <Button type="link" key={1} onClick={() => history.push(`/org/edit?id=${record.orgId}`)}>
          详情
        </Button>,
      ],
    },
  ]


  return (
    <PageHeaderWrapper>
      <PageTable
        columns={columns}
        request={getList}
        options={false}
        toolBarRender={() => [AddNew]}
        rowKey="orgId"
      />
    </PageHeaderWrapper>
  )
}
