import ButtonConfirm from '@/components/ButtomConfirm'; import { RESPONSE_CODE } from '@/constants/enum'; import { postOldInvoicingWhiteListBatchAdd, postOldInvoicingWhiteListPage, postOldInvoicingWhiteListRemove, } from '@/services'; import { PlusOutlined } from '@ant-design/icons'; import { ActionType, ModalForm, ProColumns, ProFormTextArea, ProTable, } from '@ant-design/pro-components'; import { Button, message } from 'antd'; import { useRef } from 'react'; export const waitTimePromise = async (time: number = 100) => { return new Promise((resolve) => { setTimeout(() => { resolve(true); }, time); }); }; export const waitTime = async (time: number = 100) => { await waitTimePromise(time); }; const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', width: 48, }, { title: '订单号', dataIndex: 'mainOrderId', ellipsis: true, }, { title: '添加时间', dataIndex: 'createTime', hideInSearch: true, ellipsis: true, }, { title: '添加人', dataIndex: 'createByName', hideInSearch: true, ellipsis: true, }, { title: '创建时间', valueType: 'dateTimeRange', hideInTable: true, search: { transform: (value) => { if (value) { return { createTimeGe: value[0], createTimeLe: value[1], }; } }, }, }, { title: '操作', valueType: 'option', key: 'option', render: (text, record, _, action) => [ <ButtonConfirm key="delete" className="p-0" title={'确认删除此项吗?'} text="删除" onConfirm={async () => { await postOldInvoicingWhiteListRemove({ query: { mainOrderId: record.mainOrderId, }, }); action?.reload(); }} />, ], }, ]; export default () => { const actionRef = useRef<ActionType>(); return ( <ProTable columns={columns} actionRef={actionRef} cardBordered request={async (params) => { const res = await postOldInvoicingWhiteListPage({ data: params, }); return res.data; }} rowKey="id" search={{ labelWidth: 'auto', }} options={{ setting: { listsHeight: 400, }, }} pagination={{ showSizeChanger: true, // 显示可以选择每页显示条数的下拉菜单 pageSizeOptions: ['10', '20', '50', '100'], // 设置可以选择的每页显示条数选项 }} dateFormatter="string" headerTitle="白名单" toolBarRender={() => [ <ModalForm key="add" title="添加" trigger={ <Button type="primary"> <PlusOutlined /> 添加 </Button> } autoFocusFirstInput modalProps={{ destroyOnClose: true, onCancel: () => console.log('run'), }} submitTimeout={2000} onFinish={async (values) => { const res = await postOldInvoicingWhiteListBatchAdd({ data: values, }); if (res.result === RESPONSE_CODE.SUCCESS) { actionRef.current?.reload(); message.success('添加成功'); return true; } }} > <ProFormTextArea name="orderIdsText" label="订单号" placeholder="请输入订单号,多个用逗号分割" rules={[ { required: true, message: '请输入订单号,多个用逗号分割', }, ]} ></ProFormTextArea> </ModalForm>, ]} /> ); };