columns.tsx 6.76 KB
import { QuestionCircleOutlined } from '@ant-design/icons';
import { UTag, UTooltip } from '@uj/ui';
import type { DataTableColumnsType } from '@/components';
import type { ChannelNode, WithdrawRow } from '@/api';
import {
  CHANNEL_PROVIDER,
  LIMIT_STORE_FLAG,
  PAY_MODE,
  TRANSFER_STATUS,
  WITHDRAWAL_SOURCE,
  WITHDRAWAL_TYPE,
  findChannelNode,
  optionLabel,
  statusMeta,
} from '@/features/shared/dictionaries';
import { centsToYuan, dateTimeOr, numberOr, textOr } from '@/features/shared/format';

export interface TransferColumnHandlers {
  /** 身份证列:老系统只在有正面照时可点,点开看正反面。 */
  onIdCard: (row: WithdrawRow) => void;
  /** 免责协议列:有地址才显示「协议」,点开是 iframe 弹窗。 */
  onAgreement: (url: string) => void;
}

/**
 * 列顺序、标题与宽度逐字对齐老系统 list.vue 的 tableColumns(31 列)。
 * 两处老系统现算的文案仍在前端算:付款渠道要拿渠道树按 code 递归找名字,
 * 提现类型/方式/来源/服务商按字典下标取,后端加了新枚举时原样回显而不是显示空白。
 */
export function buildTransferColumns(
  channelNodes: ChannelNode[],
  handlers: TransferColumnHandlers,
): DataTableColumnsType<WithdrawRow> {
  const link = (enabled: boolean) => (enabled ? 'uj-link' : undefined);
  return [
    {
      title: '提现单号',
      dataIndex: 'outSettleOrderId',
      line: 1,
      width: 200,
      render: (value) => textOr(value),
    },
    {
      title: '积分时段归属',
      dataIndex: 'pointsPeriodTypeDesc',
      line: 1,
      width: 200,
      render: (value) => textOr(value),
    },
    {
      title: '提现类型',
      dataIndex: 'transferType',
      width: 120,
      render: (value) => optionLabel(WITHDRAWAL_TYPE, value) || '—',
    },
    {
      title: '限制门店',
      dataIndex: 'limitStoreFlag',
      width: 100,
      render: (value) => optionLabel(LIMIT_STORE_FLAG, value) || '—',
    },
    {
      title: '手动标签',
      dataIndex: 'manualTagPath',
      line: 1,
      width: 180,
      render: (value) => textOr(value),
    },
    {
      title: '主营品牌',
      dataIndex: 'mainBrandName',
      line: 1,
      width: 180,
      render: (value) => textOr(value),
    },
    { title: '省份', dataIndex: 'provinceName', width: 120, render: (value) => textOr(value) },
    {
      title: '提现方式',
      dataIndex: 'mode',
      width: 100,
      render: (value) => optionLabel(PAY_MODE, value) || '—',
    },
    { title: '客户名称', dataIndex: 'customerName', width: 150, render: (value) => textOr(value) },
    {
      title: '客户手机号',
      dataIndex: 'customerPhone',
      width: 140,
      render: (value) => <span className="uj-code">{textOr(value)}</span>,
    },
    {
      title: '所属门店',
      dataIndex: 'merchantName',
      line: 1,
      width: 220,
      // 老列表把门店编号拼在名字后面,筛选项里也是同一个拼法。
      render: (_value, row) =>
        textOr(row.merchantName ? `${row.merchantName}(${row.merchantId ?? ''})` : ''),
    },
    {
      // 老系统在这一列的表头挂了个问号提示,内容照搬。
      title: (
        <UTooltip title="申请积分提现时,获取所属门店关联的最新平台方">
          <span className="uj-points-header-hint">
            平台方
            <QuestionCircleOutlined />
          </span>
        </UTooltip>
      ),
      dataIndex: 'realityMerchantName',
      line: 1,
      width: 190,
      render: (value) => textOr(value),
    },
    {
      title: '提现积分',
      dataIndex: 'integralAmount',
      width: 100,
      render: (value) => numberOr(value),
    },
    {
      title: '提现金额',
      dataIndex: 'payAmount',
      width: 110,
      render: (value) => <span className="uj-code">{centsToYuan(value)}</span>,
    },
    { title: '收款人姓名', dataIndex: 'name', width: 110, render: (value) => textOr(value) },
    {
      title: '收款人身份证',
      dataIndex: 'idCardNo',
      width: 200,
      render: (value, row) => (
        <span
          className={link(!!row.idCardFront)}
          onClick={() => row.idCardFront && handlers.onIdCard(row)}
        >
          {textOr(value)}
        </span>
      ),
    },
    {
      title: '收款银行卡号',
      dataIndex: 'recvBankCardNo',
      width: 230,
      render: (value) => <span className="uj-code">{textOr(value)}</span>,
    },
    {
      title: '收款银行',
      dataIndex: 'recvBank',
      line: 1,
      width: 150,
      render: (value) => textOr(value),
    },
    { title: '收款手机号', dataIndex: 'mobile', width: 130, render: (value) => textOr(value) },
    {
      title: '微信openid',
      dataIndex: 'customerOpenId',
      width: 130,
      render: (value) => textOr(value),
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 120,
      render: (value) => {
        const meta = statusMeta(TRANSFER_STATUS, value);
        if (!meta) return numberOr(value);
        return (
          <UTag color={meta.color} style={{ borderRadius: 6 }}>
            {meta.label}
          </UTag>
        );
      },
    },
    {
      title: '申请时间',
      dataIndex: 'createdDate',
      width: 170,
      render: (value) => dateTimeOr(value),
    },
    {
      title: '来源',
      dataIndex: 'withdrawalSource',
      width: 140,
      render: (value) => optionLabel(WITHDRAWAL_SOURCE, value) || '—',
    },
    {
      title: '付款渠道',
      dataIndex: 'channel',
      width: 160,
      render: (_value, row) => textOr(findChannelNode(channelNodes, row.channel)?.name),
    },
    {
      title: '付款主体',
      dataIndex: 'paymentEntityName',
      line: 1,
      width: 200,
      render: (value) => textOr(value),
    },
    {
      title: '代征主体',
      dataIndex: 'levyName',
      line: 1,
      width: 200,
      render: (value) => textOr(value),
    },
    { title: '付款时间', dataIndex: 'payDate', width: 170, render: (value) => dateTimeOr(value) },
    {
      title: '服务商',
      dataIndex: 'channelProvider',
      width: 120,
      render: (value) => optionLabel(CHANNEL_PROVIDER, value) || '—',
    },
    {
      title: '到账时间',
      dataIndex: 'receiptDate',
      width: 170,
      render: (value) => dateTimeOr(value),
    },
    {
      title: '结算金额/元',
      dataIndex: 'settleAmount',
      width: 130,
      render: (value) => <span className="uj-code">{centsToYuan(value)}</span>,
    },
    {
      title: '免责协议',
      dataIndex: 'disclaimerAgreementUrl',
      width: 110,
      render: (value) =>
        value ? (
          <span className={link(true)} onClick={() => handlers.onAgreement(String(value))}>
            协议
          </span>
        ) : (
          '—'
        ),
    },
  ];
}