Blame view

src/pages/Invoice/index.tsx 4.08 KB
1
import { INVOICE_COLUMNS, INVOICE_STATUS } from '@/pages/Invoice/constant';
2
import { postServiceInvoiceQueryInvoice } from '@/services';
3
import { enumValueToLabel } from '@/utils';
4
import { getUserInfo } from '@/utils/user';
5
import { EllipsisOutlined } from '@ant-design/icons';
6
7
8
9
10
11
12
13
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';
14
15
import { INVOCING_STATUS, PAYEE_OPTIONS } from '../Order/constant';
import './index.less';
16
17
18
19

const userInfo = getUserInfo();
const InvoicePage = () => {
  const actionRef = useRef<ActionType>();
20
21
  // const [pageSize, setPageSize] = useState(10);
  // const [currentPage, setCurrentPage] = useState(1);
22
23
24
  return (
    <>
      <PageContainer
25
        className="invoice-index"
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        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>,
          ],
        }}
      >
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        <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;
          })}
82
83
          actionRef={actionRef}
          cardBordered
84
85
86
          pagination={{
            pageSize: 10,
          }}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
          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="发票列表"
131
          scroll={{ x: true }}
132
133
134
135
136
137
138
        />
      </PageContainer>
    </>
  );
};

export default InvoicePage;