policyTableData.ts 4.23 KB
import type { StoreImportRowDTO } from '@/api/modules/store';

export interface PolicyConfirmRow {
  // 门店信息(4 列)
  storeName: string;
  storeMerchantNo: string;
  businessScene: string;
  productCategory: string;
  // 商务政策(14 列:管理层市场费 ×6 + 一线阳光 ×4 + 一线阳光2 ×4)
  mgmtFee1Mode: string;
  mgmtFee1CalcMethod: string;
  mgmtFee1Value: string;
  mgmtFee2Mode: string;
  mgmtFee2CalcMethod: string;
  mgmtFee2Value: string;
  sunshineOnlinePoints: string;
  sunshineCalcMode: string;
  sunshineCalcMethod: string;
  sunshineValue: string;
  sunshine2OnlinePoints: string;
  sunshine2CalcMode: string;
  sunshine2CalcMethod: string;
  sunshine2Value: string;
  // 运营成本(3 列)
  costDecoration: string;
  costMonthly: string;
  costLabor: string;
}

const BUSINESS_SCENES = ['售后众筹', '精品升级'];
const PRODUCT_CATEGORIES = [
  '车辆美容',
  '精品(集采)',
  '记录仪',
  '其他(众筹)',
  '电子烟(集采)',
  '太阳膜()',
];

function buildRows(): PolicyConfirmRow[] {
  const rows: PolicyConfirmRow[] = [];
  for (const scene of BUSINESS_SCENES) {
    for (const cat of PRODUCT_CATEGORIES) {
      const calcMode = cat === '精品(集采)' ? '按整单计算' : '按品类计算';
      rows.push({
        storeName: '明明崇文4s店A',
        storeMerchantNo: '44211227',
        businessScene: scene,
        productCategory: cat,
        mgmtFee1Mode: calcMode,
        mgmtFee1CalcMethod: '收入',
        mgmtFee1Value: '5%',
        mgmtFee2Mode: calcMode,
        mgmtFee2CalcMethod: '收入',
        mgmtFee2Value: '5%',
        sunshineOnlinePoints: '是',
        sunshineCalcMode: calcMode,
        sunshineCalcMethod: '收入',
        sunshineValue: '5%',
        sunshine2OnlinePoints: '是',
        sunshine2CalcMode: calcMode,
        sunshine2CalcMethod: '收入',
        sunshine2Value: '5%',
        costDecoration: '¥ 200,000',
        costMonthly: '¥ 15,000',
        costLabor: '¥ 30,000',
      });
    }
  }
  return rows;
}

export const mockPolicyRows: PolicyConfirmRow[] = buildRows();

function formatRatio(value: number | undefined | null, unit: string | undefined | null): string {
  if (value === undefined || value === null) return '-';
  if ((unit ?? '').toUpperCase() !== 'RATIO') return String(value);
  // 后端约定:RATIO 单位下,value 本身就是百分比的整数表示
  // 例:1 → 1%,5 → 5%,0.5 → 0.5%(极少数小数百分比场景也直接显示)
  const rounded = Math.round(value * 100) / 100;
  return `${rounded}%`;
}

function formatYesNo(value: number | undefined | null): string {
  if (value === 1) return '是';
  if (value === 0) return '否';
  return '-';
}

function formatMoney(value: number | undefined | null): string {
  if (value === undefined || value === null) return '-';
  return `¥ ${value.toLocaleString('zh-CN')}`;
}

/** 将接口返回的 previewRows 转为 PolicyConfirmRow */
export function convertPreviewRows(preview: StoreImportRowDTO[]): PolicyConfirmRow[] {
  return preview.map((r) => ({
    // 门店信息
    storeName: r.storeName,
    storeMerchantNo: r.merchantNo,
    businessScene: r.businessScene,
    productCategory: r.productCategory,
    // 管理层市场费 1
    mgmtFee1Mode: r.marketFee1CalcMode || '-',
    mgmtFee1CalcMethod: r.marketFee1CalcWay || '-',
    mgmtFee1Value: formatRatio(r.marketFee1Value, r.marketFee1Unit),
    // 管理层市场费 2
    mgmtFee2Mode: r.marketFee2CalcMode || '-',
    mgmtFee2CalcMethod: r.marketFee2CalcWay || '-',
    mgmtFee2Value: formatRatio(r.marketFee2Value, r.marketFee2Unit),
    // 一线阳光 1
    sunshineOnlinePoints: formatYesNo(r.sunshine1OnlinePoint),
    sunshineCalcMode: r.sunshine1CalcMode || '-',
    sunshineCalcMethod: r.sunshine1CalcWay || '-',
    sunshineValue: formatRatio(r.sunshine1Value, r.sunshine1Unit),
    // 一线阳光 2
    sunshine2OnlinePoints: formatYesNo(r.sunshine2OnlinePoint),
    sunshine2CalcMode: r.sunshine2CalcMode || '-',
    sunshine2CalcMethod: r.sunshine2CalcWay || '-',
    sunshine2Value: formatRatio(r.sunshine2Value, r.sunshine2Unit),
    // 运营成本
    costDecoration: formatMoney(r.costDecoration),
    costMonthly: formatMoney(r.costMonthly),
    costLabor: formatMoney(r.costLabor),
  }));
}