index.tsx 4.02 KB
import ClientDrawer from '@/pages/Client/Components/ClientDrawer';
import { postAdminClientQueryClientPage } from '@/services';
import { EllipsisOutlined } from '@ant-design/icons';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Button, Dropdown } 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 = [
  {
    dataIndex: 'index',
    valueType: 'indexBorder',
    width: 48,
  },
  {
    title: '客户名称',
    dataIndex: 'name',
  },
  {
    title: '单位名称',
    dataIndex: 'companyName',
  },
  {
    title: '单位地址',
    dataIndex: 'companyName',
  },
  {
    title: '联系电话',
    dataIndex: 'phoneNumber',
  },
  {
    title: '客户来源',
    dataIndex: 'sourceText',
  },
  {
    title: '推荐人',
    dataIndex: 'referrers',
  },
  {
    title: '客户需求',
    dataIndex: 'requirements',
  },
  {
    title: '是否已报方案',
    dataIndex: 'hasSchemeText',
  },
  {
    title: '报价时间',
    key: 'since',
    dataIndex: 'quoteDatetime',
    valueType: 'dateTime',
  },
  {
    title: '跟进状态',
    dataIndex: 'tradeStatusText',
  },
  {
    title: '客户等级',
    dataIndex: 'levelText',
  },
  {
    title: '创建时间',
    key: 'since',
    dataIndex: 'createTime',
    valueType: 'dateTime',
  },
  {
    title: '最新跟进时间',
    key: 'since',
    dataIndex: 'latestCommunicationTime',
    valueType: 'dateTime',
  },
  {
    title: '操作',
    valueType: 'option',
    key: 'option',
    render: (text, record, _, action) => [
      <a
        key="editable"
        onClick={() => {
          action?.startEditable?.(record.id);
        }}
      >
        查询详情
      </a>,
      <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
        跟进记录
      </a>,
    ],
  },
];

export default () => {
  const actionRef = useRef<ActionType>();
  return (
    <ProTable
      columns={columns}
      actionRef={actionRef}
      cardBordered
      request={async (params) => {
        const res = await postAdminClientQueryClientPage({
          data: {
            ...params,
          },
        });
        const data = res.data.data;
        return data;
      }}
      editable={{
        type: 'multiple',
      }}
      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;
        },
      }}
      pagination={{
        pageSize: 5,
        onChange: (page) => console.log(page),
      }}
      dateFormatter="string"
      headerTitle="高级表格"
      toolBarRender={() => [
        <ClientDrawer key="button" />,
        <Dropdown
          key="menu"
          menu={{
            items: [
              {
                label: '1st item',
                key: '1',
              },
              {
                label: '2nd item',
                key: '1',
              },
              {
                label: '3rd item',
                key: '1',
              },
            ],
          }}
        >
          <Button>
            <EllipsisOutlined />
          </Button>
        </Dropdown>,
      ]}
    />
  );
};