index.tsx 4.08 KB
import { INVOICE_COLUMNS, INVOICE_STATUS } from '@/pages/Invoice/constant';
import { postServiceInvoiceQueryInvoice } from '@/services';
import { enumValueToLabel } from '@/utils';
import { getUserInfo } from '@/utils/user';
import { EllipsisOutlined } from '@ant-design/icons';
import {
  ActionType,
  PageContainer,
  ProTable,
} from '@ant-design/pro-components';
import { history } from '@umijs/max';
import { Avatar, Button, Dropdown, Tag } from 'antd';
import { useRef } from 'react';
import { INVOCING_STATUS, PAYEE_OPTIONS } from '../Order/constant';
import './index.less';

const userInfo = getUserInfo();
const InvoicePage = () => {
  const actionRef = useRef<ActionType>();
  // const [pageSize, setPageSize] = useState(10);
  // const [currentPage, setCurrentPage] = useState(1);
  return (
    <>
      <PageContainer
        className="invoice-index"
        header={{
          title: '发票管理',
          extra: [
            <Avatar key="0" style={{ verticalAlign: 'middle' }} size="large">
              {userInfo?.username}
            </Avatar>,
            <Tag key="nickName">{userInfo?.nickName}</Tag>,
            <Dropdown
              key="dropdown"
              trigger={['click']}
              menu={{
                items: [
                  {
                    label: '退出登录',
                    key: '1',
                    onClick: () => {
                      localStorage.removeItem('token');
                      history.push('/login');
                    },
                  },
                  // {
                  //   label: '修改密码',
                  //   key: '2',
                  // },
                ],
              }}
            >
              <Button key="4" style={{ padding: '0 8px' }}>
                <EllipsisOutlined />
              </Button>
            </Dropdown>,
          ],
        }}
      >
        <ProTable
          columns={INVOICE_COLUMNS.map((item) => {
            let newItem = { ...item };
            if (item.dataIndex === 'invoiceStatus') {
              newItem.render = (text) => {
                return enumValueToLabel(text.props.text, INVOCING_STATUS);
              };
            }

            if (item.dataIndex === 'status') {
              newItem.render = (text) => {
                return enumValueToLabel(text, INVOICE_STATUS);
              };
            }

            if (item.dataIndex === 'payee') {
              newItem.render = (text) => {
                return enumValueToLabel(text, PAYEE_OPTIONS);
              };
            }
            return newItem;
          })}
          actionRef={actionRef}
          cardBordered
          pagination={{
            pageSize: 10,
          }}
          request={async (params) => {
            const res = await postServiceInvoiceQueryInvoice({
              data: { ...params },
            });
            if (res) {
              return {
                data: res?.data?.data || [],
                total: res?.data?.total || 0,
              };
            }
          }}
          columnsState={{
            persistenceKey: 'pro-table-singe-demos',
            persistenceType: 'localStorage',
            defaultValue: {
              option: { fixed: 'right', disable: true },
            },
            onChange(value) {
              console.log('value: ', value);
            },
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
          }}
          options={{
            setting: {
              listsHeight: 400,
            },
          }}
          form={{
            // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          dateFormatter="string"
          headerTitle="发票列表"
          scroll={{ x: true }}
        />
      </PageContainer>
    </>
  );
};

export default InvoicePage;