dictionaries.ts 8.82 KB
import type { ChannelNode, DictOption } from '@/api';

/**
 * 积分管理三个菜单用到的全部固定字典。
 *
 * 老系统把这些数组散落在 utils/constants.js 与各页面的 data() 里,
 * 同一个状态在不同页面各抄一份(提现状态 9 项、审批状态 7 项就重复过)。
 * 这里按「一个状态机一份表」收口:value 一律字符串,提交给后端的原值不变;
 * label 与老系统逐字一致,改动只需要对照一张表。
 */

export interface StatusMeta {
  label: string;
  /** antd 徽标色名或十六进制,与设计令牌同源。 */
  color: string;
}

/** 按下标取状态文案:老接口直接返回数字 status。 */
export function statusMeta(table: StatusMeta[], status: unknown): StatusMeta | undefined {
  const index = Number(status);
  return Number.isInteger(index) && index >= 0 && index < table.length ? table[index] : undefined;
}

export function statusOptions(table: StatusMeta[]): DictOption[] {
  return table.map((item, index) => ({ value: String(index), label: item.label }));
}

/** 核销订单的结算状态(接口字段 settlementStatus,0/1)。 */
export const SETTLE_STATUS: DictOption[] = [
  { value: '0', label: '未结算' },
  { value: '1', label: '已结算' },
];

/** 提现方式(接口字段 mode,0/1)。 */
export const PAY_MODE: DictOption[] = [
  { value: '0', label: '银行卡' },
  { value: '1', label: '微信' },
];

/** 提现类型(接口字段 transferType,0/1/2)。批量与一键操作前先校验所选记录同类型。 */
export const WITHDRAWAL_TYPE: DictOption[] = [
  { value: '0', label: '积分提现' },
  { value: '1', label: '普通提现' },
  { value: '2', label: '阳光激励' },
];

/** 提现来源(接口字段 withdrawalSource,0-3)。 */
export const WITHDRAWAL_SOURCE: DictOption[] = [
  { value: '0', label: '车生活助手' },
  { value: '1', label: '系统导入' },
  { value: '2', label: '生意助手员工版' },
  { value: '3', label: '门店助手' },
];

/** 积分时段归属(接口字段 pointsPeriodType,1/2)。 */
export const POINTS_PERIOD: DictOption[] = [
  { value: '1', label: '26年9月前积分' },
  { value: '2', label: '26年9月后积分' },
];

/** 是否限制门店(提交 Y/N,接口字段 limitStoreFlag / limitStoreFlagQuery)。 */
export const LIMIT_STORE_FLAG: DictOption[] = [
  { value: 'Y', label: '是' },
  { value: 'N', label: '否' },
];

/** 服务商编码 → 展示名(接口字段 channelProvider,老列表 formatter 里就这四个值)。 */
export const CHANNEL_PROVIDER: DictOption[] = [
  { value: 'SHENBIANYUN-XH', label: '翔禾' },
  { value: 'SHENBIANYUN-YJ', label: '雅钧' },
  { value: 'SHENBIANYUN-BC', label: '博晟' },
  { value: 'SHENBIANYUN-CJ', label: '晨景' },
];

/**
 * 提现单状态(0-8),对应老系统的 auditStatusStatusList。
 * 颜色逐项对齐老列表的圆点数组,只有一处例外:
 * 老系统把「受理失败」涂成绿色,那是抄错的一行,这里按语义给红。
 */
export const TRANSFER_STATUS: StatusMeta[] = [
  { label: '待审核', color: 'gold' },
  { label: '已审核', color: 'green' },
  { label: '第三方处理', color: 'geekblue' },
  { label: '成功', color: 'green' },
  { label: '失败', color: 'default' },
  { label: '驳回', color: 'red' },
  { label: '受理失败', color: 'red' },
  { label: '批次处理中', color: 'orange' },
  { label: '签约中', color: 'orange' },
];

/**
 * 累计结算金额的统计项(老系统 constants.statisticsTypeList,逐字保留顺序与编码)。
 * 提现列表顶部只展示前 4 项,「查看更多」弹窗展示全部;接口按 key 平铺回金额。
 */
export const SETTLE_STATISTICS: Array<{ key: string; label: string }> = [
  { key: 'yiXuanSettleAmount', label: '熠轩-银行卡' },
  { key: 'zxSettleAmount', label: '中雄-银行卡' },
  { key: 'yunHuoSettleAmount', label: '云获(嘀加)-银行卡' },
  { key: 'yunHuoZYSettleAmount', label: '云获(中赢)-银行卡' },
  { key: 'yunHuoWXSettleAmount', label: '云获(中赢)-微信' },
  { key: 'shenBianYunSettleAmount', label: '身边云-银行卡' },
  { key: 'birdWorkSettleAmount', label: '智鸟-银行卡' },
  { key: 'shenBianYunJXSettleAmount', label: '身边云(江西)-银行卡' },
  { key: 'xinXiangYunSettleAmount', label: '薪享云-银行卡' },
  { key: 'daXiongSettleAmount', label: '大熊-银行卡' },
];

/** 提现列表顶部统计卡固定展示前 4 项(老系统 statisticsTypeList.slice(0, 4))。 */
export const SETTLE_STATISTICS_PREVIEW = 4;

/** 审批批次状态(0-6),对应老系统 constants.statusList + approve.vue 的列渲染。 */
export const APPROVAL_STATUS: StatusMeta[] = [
  { label: '待审批', color: 'default' },
  { label: '审批中', color: 'gold' },
  { label: '审批通过', color: 'green' },
  { label: '审批驳回', color: 'red' },
  { label: '渠道到账', color: 'green' },
  { label: '用户到账', color: 'green' },
  { label: '到账异常', color: 'red' },
];

/** 审批操作记录的动作名(接口字段 operationType,从 1 开始)。 */
export const APPROVAL_OPERATION: Record<number, string> = {
  1: '付款审核',
  2: '批次关闭',
  3: 'OA审批',
  4: '渠道到账',
  5: '渠道付款',
};

/** 提现详情的操作记录:type 决定动作与人称,result 决定结果文案。 */
export const TRANSFER_OPERATION_TYPES = ['审核', '付款', '受理'] as const;
export const TRANSFER_OPERATION_RESULTS = ['通过', '驳回', '失败'] as const;

/** 「审核人 / 付款人 / 受理人」这类由动作派生的标签,老系统按下标取词。 */
export function operationLabel(action: unknown, kind: 'person' | 'time' | 'name'): string {
  const index = Number(action);
  const name = TRANSFER_OPERATION_TYPES[index];
  if (!name) return '';
  return kind === 'person' ? `${name}人` : kind === 'time' ? `${name}时间` : name;
}

/** 用户积分明细三个 tab:channelSource 是接口入参,也是 tab 的 key。 */
export const SCORE_TABS = [
  { key: '2', label: '续保用户', channelSource: 2 },
  { key: '1', label: '阳光激励用户', channelSource: 1 },
  { key: '3', label: '管理层', channelSource: 3 },
] as const;

/**
 * 积分流水的类型筛选,两套候选逐字来自 userDetail.vue 的 infoNameList:
 * 阳光激励(channelSource=1)给全部 11 类,其余渠道只给 4 类。
 * 提交值就是中文本身(老接口的 confId 与 confLabel 同值),换成编码后端不认识。
 */
const SCORE_INFO_NAMES = [
  '积分收益',
  '积分兑换',
  '退款抵扣',
  '撤单抵扣',
  '错单抵扣',
  '手动抵扣',
  '撤销抵扣',
  '售后返还',
  '购物兑换',
  '手动增加',
  '手动扣减',
];
const SCORE_INFO_NAMES_OTHER = ['积分收益', '积分兑换', '购物兑换', '售后返还'];

export function scoreInfoNameOptions(channelSource: string | number): DictOption[] {
  const names = String(channelSource) === '1' ? SCORE_INFO_NAMES : SCORE_INFO_NAMES_OTHER;
  return withAll(names.map((name) => ({ value: name, label: name })));
}

/** 老系统只有阳光激励渠道允许出现「撤销」入口,且仅限无关联单号的手动抵扣流水。 */
export const MANUAL_DEDUCT_INFO_NAME = '手动抵扣';
export function canRevokeScore(
  channelSource: string | number,
  row: { infoName?: string; relateId?: string },
): boolean {
  return String(channelSource) === '1' && row.infoName === MANUAL_DEDUCT_INFO_NAME && !row.relateId;
}

/** 付款渠道列表(老系统 constants.channelList,OA 付款审批用)。 */
export const PAYMENT_CHANNELS: DictOption[] = [
  { value: '智鸟', label: '智鸟-银行卡' },
  { value: '身边云(江西)', label: '身边云(江西)-银行卡' },
];

/**
 * 渠道树按 code 递归取节点(老系统 findChannelByCode)。
 * 老接口的子节点字段名是 child,不是 children。
 */
export function findChannelNode(
  nodes: ChannelNode[] | undefined | null,
  code: unknown,
): ChannelNode | undefined {
  if (!Array.isArray(nodes) || code === undefined || code === null) return;
  for (const node of nodes) {
    if (node.code === code) return node;
    const found = findChannelNode(node.child ?? node.children, code);
    if (found) return found;
  }
  return undefined;
}

/** 按下标取字典文案;命中不了原样回显,避免后端加了新枚举就显示空白。 */
export function optionLabel(options: DictOption[], value: unknown): string {
  if (value === null || value === undefined || value === '') return '';
  const key = String(value);
  return options.find((option) => option.value === key)?.label ?? key;
}

/** 老系统的下拉第一项固定是「全部」(提交空串),现系统筛选项沿用这一约定。 */
export const ALL: DictOption = { value: '', label: '全部' };
export function withAll(options: DictOption[]): DictOption[] {
  return [ALL, ...options];
}