fields.ts 4.24 KB
import type { FieldSchema } from '@/components';
import { compactParams, expandDateRanges } from '@/features/shared/format';
import {
  LIMIT_STORE_FLAG,
  PAY_MODE,
  POINTS_PERIOD,
  TRANSFER_STATUS,
  WITHDRAWAL_SOURCE,
  WITHDRAWAL_TYPE,
  statusOptions,
  withAll,
} from '@/features/shared/dictionaries';
import type { DictOption } from '@/api';

/**
 * 提现列表的筛选区。
 *
 * 字段名逐字对齐老系统 showFormData(提交给接口的就是这些 key),顺序也保持原样;
 * 三个时间区间在表单里各是一个区间,提交前才展开成接口的起止字段。
 */

/** 老系统这三个区间都用 00:00:01 起、23:59:59 止,见 getParams()。 */
const DATE_RANGES = [
  { from: 'applyDateStr', start: 'applyDateStart', end: 'applyDateEnd' },
  { from: 'payTimeStr', start: 'payDateStart', end: 'payDateEnd' },
  { from: 'receiptDateStr', start: 'receiptDateStart', end: 'receiptDateEnd' },
];

/** 手动标签:老系统用级联选到任意一级,接口只认那个节点的 id。 */
export function toTransferParams(values: Record<string, unknown>): Record<string, unknown> {
  return compactParams(expandDateRanges({ ...values }, DATE_RANGES));
}

export interface TransferFieldDeps {
  /** 渠道树顶层节点:付款渠道筛选就是这一层(老系统把级联注释掉了,只剩平铺下拉)。 */
  channels: DictOption[];
  /** 付款主体不是独立接口,而是所选渠道下的子节点去重。 */
  entities: DictOption[];
  merchants: DictOption[];
  brands: DictOption[];
  provinces: DictOption[];
  /** 标签树摊平成「一级 / 二级」这种路径文案,选中任意层级都能筛。 */
  tags: DictOption[];
}

export function buildTransferFields(
  deps: TransferFieldDeps,
): FieldSchema<Record<string, unknown>>[] {
  return [
    {
      name: 'outSettleOrderId',
      label: '提现单号',
      type: 'input',
      placeholder: '请输入提现单号',
      inputProps: { maxLength: 25 },
      essential: true,
    },
    {
      name: 'customerName',
      label: '客户名称',
      type: 'input',
      placeholder: '请输入客户名称',
      inputProps: { maxLength: 20 },
      essential: true,
    },
    {
      name: 'customerPhone',
      label: '手机号',
      type: 'input',
      placeholder: '请输入手机号',
      inputProps: { maxLength: 11 },
    },
    {
      name: 'name',
      label: '收款人姓名',
      type: 'input',
      placeholder: '请输入收款人姓名',
      inputProps: { maxLength: 20 },
    },
    {
      name: 'status',
      label: '状态',
      type: 'select',
      options: withAll(statusOptions(TRANSFER_STATUS)),
      essential: true,
    },
    { name: 'applyDateStr', label: '申请时间', type: 'dateRange', essential: true },
    { name: 'payTimeStr', label: '付款时间', type: 'dateRange' },
    { name: 'channel', label: '付款渠道', type: 'select', options: withAll(deps.channels) },
    {
      name: 'paymentEntityCode',
      label: '付款主体',
      type: 'select',
      options: withAll(deps.entities),
    },
    { name: 'merchantIds', label: '所属门店', type: 'selectMultiple', options: deps.merchants },
    { name: 'receiptDateStr', label: '到账时间', type: 'dateRange' },
    { name: 'transferType', label: '提现类型', type: 'select', options: withAll(WITHDRAWAL_TYPE) },
    { name: 'mode', label: '提现方式', type: 'select', options: withAll(PAY_MODE) },
    {
      name: 'withdrawalSource',
      label: '来源',
      type: 'select',
      options: withAll(WITHDRAWAL_SOURCE),
    },
    { name: 'realityMerchantName', label: '平台方', type: 'input', placeholder: '请输入平台方' },
    {
      name: 'limitStoreFlagQuery',
      label: '限制门店',
      type: 'select',
      options: withAll(LIMIT_STORE_FLAG),
    },
    { name: 'mainBrandIds', label: '主营品牌', type: 'selectMultiple', options: deps.brands },
    { name: 'provinceCodes', label: '省份', type: 'selectMultiple', options: deps.provinces },
    {
      name: 'transferOutTagIdQuery',
      label: '手动标签项',
      type: 'select',
      options: withAll(deps.tags),
    },
    {
      name: 'pointsPeriodType',
      label: '积分时段归属',
      type: 'select',
      options: withAll(POINTS_PERIOD),
    },
  ];
}