ApproveTable.tsx 4.81 KB
import type { ColumnsType } from 'antd/es/table';
import { UTag } from '@uj/ui';
import { DataTable, type RowActionSchema } from '@/components';
import type { DataTableProps } from '@/components/DataTable';
import { StatusTag } from '@/components/StatusTag';
import type { ApprovalRow, ApproveTab } from '@/api';
import type { StoreDictionaries } from '@/features/store/dictionaries';
import { dictionaryLabel, formatDateTime, formatMoney } from '@/features/store/formatters';

interface Props extends Omit<DataTableProps<ApprovalRow>, 'columns'> {
  tab: ApproveTab;
  spec?: StoreDictionaries;
  rowActions: RowActionSchema<ApprovalRow>[];
}
export function ApproveTable({ tab, spec, ...props }: Props) {
  const columns: ColumnsType<ApprovalRow> = [
    {
      title: '门店名称',
      dataIndex: 'storeName',
      width: 220,
      fixed: 'left',
      render: (value) => <strong>{value}</strong>,
    },
    {
      title: '门店商户号',
      dataIndex: 'merchantNo',
      width: 140,
      render: (value) => <span className="store-code">{value}</span>,
    },
    {
      title: '产品分类',
      key: 'categories',
      width: 180,
      render: (_, row) => {
        const categories = row.productCategories ?? [];
        const count = row.categoryCount ?? categories.length;
        return (
          <>
            {categories[0] ? (
              <UTag>{dictionaryLabel(spec?.productCategories, categories[0])}</UTag>
            ) : (
              '—'
            )}
            {count > 1 && <span className="store-subtext">等 {count} 个分类</span>}
          </>
        );
      },
    },
    {
      title: '业务场景',
      dataIndex: 'businessScene',
      width: 200,
      render: (value) => <UTag color="blue">{dictionaryLabel(spec?.businessScenes, value)}</UTag>,
    },
  ];
  if (tab === 'todo')
    columns.push(
      {
        title: '运营成本合计',
        dataIndex: 'costTotal',
        width: 150,
        align: 'right',
        render: formatMoney,
      },
      {
        title: '提交人 / 提交时间',
        width: 180,
        render: (_, row) => (
          <>
            {row.submitUserName || '—'}
            <span className="store-subtext">{formatDateTime(row.submitTime)}</span>
          </>
        ),
      },
      {
        title: '停留时长',
        width: 110,
        render: (_, row) => {
          const level =
            row.timeoutLevel ??
            (row.pendingHours != null && row.pendingHours > 48
              ? 'DANGER'
              : row.pendingHours != null && row.pendingHours > 24
                ? 'WARNING'
                : 'NORMAL');
          return (
            <span
              style={{
                color:
                  level === 'DANGER'
                    ? 'var(--uj-error)'
                    : level === 'WARNING'
                      ? 'var(--uj-warning)'
                      : undefined,
              }}
            >
              {row.pendingHours == null ? '—' : `${row.pendingHours} 小时`}
            </span>
          );
        },
      },
    );
  if (tab === 'done')
    columns.push(
      {
        title: '我的动作',
        width: 100,
        render: (_, row) => (
          <UTag
            color={
              row.myAction === 'PASS' ? 'green' : row.myAction === 'REJECT' ? 'red' : undefined
            }
          >
            {row.myActionLabel ||
              ({ PASS: '通过', REJECT: '打回' }[row.myAction ?? ''] ?? row.myAction ?? '—')}
          </UTag>
        ),
      },
      { title: '处理时间', dataIndex: 'handleTime', width: 180, render: formatDateTime },
      {
        title: '处理意见',
        width: 220,
        render: (_, row) => row.handleOpinion || row.rejectReason || '—',
      },
      { title: '记录状态', width: 110, render: (_, row) => <StatusTag status={row.status} /> },
    );
  if (tab === 'mine')
    columns.push(
      { title: '状态', width: 110, render: (_, row) => <StatusTag status={row.status} /> },
      {
        title: '审批进度',
        width: 170,
        render: (_, row) =>
          row.status === 'PENDING'
            ? (row.totalLevel ?? 2) === 1 || row.currentLevel === 2
              ? '待优加财务经理审批'
              : '待优加商务经理审批'
            : row.status === 'REJECTED'
              ? '退回发起人'
              : row.status === 'REVOKED'
                ? '发起人已撤回'
                : row.status === 'APPROVED'
                  ? '已完成'
                  : '—',
      },
      { title: '提交时间', dataIndex: 'submitTime', width: 180, render: formatDateTime },
    );
  return (
    <DataTable<ApprovalRow>
      {...props}
      columns={columns}
      rowKey="listingId"
      scroll={{ x: tab === 'done' ? 1500 : 1410 }}
      actionColumnWidth={200}
      actionColumnFixed="right"
    />
  );
}