plan-templates.js 13.3 KB
/**
 * 计划书模版配置
 *
 * @description 定义产品 form_sn 到模版组件和配置的映射关系
 * @module config/plan-templates
 * @author Claude Code
 * @created 2026-02-06
 */

/**
 * 计划书模版配置映射
 * @description form_sn 为产品 API 返回的字段,用于标识该产品使用的计划书模版
 *
 * @example
 * // 产品 API 返回
 * {
 *   id: 1,
 *   product_name: "WIOP3E 盈传创富保障计划 3 - 优选版",
 *   form_sn: "life-insurance-wiop3e"  // 对应下面的配置 key
 * }
 */
// 基础提交字段映射(适用于人寿/重疾等通用表单)
const baseSubmitMapping = {
  customer_name: { api_field: 'customer_name' },
  gender: { api_field: 'customer_gender' },
  birthday: { api_field: 'customer_birthday' },
  smoker: { api_field: 'smoking_status' },
  coverage: { api_field: 'annual_premium', transform: 'fen_to_yuan' },
  payment_period: { api_field: 'payment_years' },
  total_amount: { api_field: 'total_premium', transform: 'fen_to_yuan' }
}

// 储蓄类提交字段映射(在基础映射上追加提取计划字段)
const savingsSubmitMapping = {
  ...baseSubmitMapping,
  withdrawal_enabled: { api_field: 'allow_reduce_amount' },
  withdrawal_mode: { api_field: 'withdrawal_option' },
  withdrawal_start_age: { api_field: 'withdrawal_start_age' },
  withdrawal_period: { api_field: 'withdrawal_period' },
  withdrawal_method: { api_field: 'withdrawal_method' },
  annual_withdrawal_amount: { api_field: 'annual_withdrawal_amount', transform: 'fen_to_yuan' },
  annual_increase_percentage: { api_field: 'annual_increase_percentage' }
}

// 储蓄类表单 Schema(渲染 + 校验 + 联动的唯一入口)
const savingsFormSchema = {
  // 基础字段:非提取计划部分
  base_fields: [
    { id: 'customer_name', key: 'customer_name', type: 'name', label: '申请人', placeholder: '请输入申请人', required: true },
    { id: 'gender', key: 'gender', type: 'radio', label: '性别', options: ['男', '女'], required: true },
    { id: 'birthday', key: 'birthday', type: 'date', label: '出生年月日', placeholder: '请选择年月日', required: true },
    { id: 'smoker', key: 'smoker', type: 'radio', label: '是否吸烟', options: ['是', '否'], required: true },
    { id: 'coverage', key: 'coverage', type: 'amount', label: '年缴保费', placeholder: '请输入年缴保费', input_label: '请输入年缴保费金额', required: true, currency_from: 'currency' },
    { id: 'payment_period', key: 'payment_period', type: 'payment_period', label: '缴费年期', required: true, options_from: 'payment_periods' }
  ],
  // 提取计划字段:由 withdrawal_plan 开关控制
  withdrawal_fields: [
    { id: 'withdrawal_enabled', key: 'withdrawal_enabled', type: 'radio', label: '是否希望生成一份允许减少名义金额的提取说明?', options: ['是', '否'], required: true, default: '否' },
    { id: 'withdrawal_mode', key: 'withdrawal_mode', type: 'radio', label: '提取选项', options: ['指定提取金额', '最高固定提取金额'], required: true, default: '指定提取金额', section_title: '款项提取(允许减少名义金额)' },
    { id: 'withdrawal_method', key: 'withdrawal_method', type: 'radio', label: '提取方式', options: ['按年岁'], required: true, default: '按年岁', show_when: [{ field: 'withdrawal_mode', equals: '指定提取金额' }] },
    { id: 'annual_withdrawal_amount', key: 'annual_withdrawal_amount', type: 'amount', label: '每年提取金额', placeholder: '请输入每年提取金额', input_label: '请输入每年提取金额', required: true, currency_from: 'withdrawal_plan.default_currency', show_when: [{ field: 'withdrawal_mode', equals: '指定提取金额' }, { field: 'withdrawal_method', equals: '按年岁' }] },
    { id: 'withdrawal_start_age_by_year', key: 'withdrawal_start_age', type: 'age', label: '由几岁开始', placeholder: '请输入开始提取年龄', required: true, show_when: [{ field: 'withdrawal_mode', equals: '指定提取金额' }] },
    { id: 'withdrawal_period_by_year', key: 'withdrawal_period', type: 'select', label: '提取期(年)', placeholder: '请选择提取期', required: true, options_from: 'withdrawal_plan.withdrawal_periods', show_when: [{ field: 'withdrawal_mode', equals: '指定提取金额' }] },
    { id: 'annual_increase_percentage', key: 'annual_increase_percentage', type: 'percentage', label: '每年递增提取之百分比(%)', placeholder: '请输入递增百分比', required: true, show_when: [{ field: 'withdrawal_mode', equals: '指定提取金额' }, { field: 'withdrawal_method', equals: '按年岁' }] },
    { id: 'withdrawal_start_age_by_fixed', key: 'withdrawal_start_age', type: 'age', label: '按年岁:由几岁开始', placeholder: '请输入开始提取年龄', required: true, show_when: [{ field: 'withdrawal_mode', equals: '最高固定提取金额' }] },
    { id: 'withdrawal_period_by_fixed', key: 'withdrawal_period', type: 'select', label: '提取期(年)', placeholder: '请选择提取期', required: true, options_from: 'withdrawal_plan.withdrawal_periods', show_when: [{ field: 'withdrawal_mode', equals: '最高固定提取金额' }] }
  ],
  // 提取模式切换时的清空逻辑,避免脏字段影响提交
  reset_map: {
    withdrawal_mode: {
      '最高固定提取金额': ['annual_withdrawal_amount', 'annual_increase_percentage', 'withdrawal_start_age', 'withdrawal_period'],
      '指定提取金额': ['withdrawal_start_age', 'withdrawal_period']
    }
  }
}

export const PLAN_TEMPLATES = {
  // 人寿保险产品 - WIOP3E
  'life-insurance-wiop3e': {
    name: 'WIOP3E 盈传创富保障计划 3 - 优选版',
    component: 'LifeInsuranceTemplate',
    config: {
      currency: 'USD', // 币种:USD/CNY/HKD/EUR
      payment_periods: [
        // 缴费年期选项
        '整付(0-75 岁)',
        '5 年(0-70 岁)',
        '10 年(0-70 岁)'
      ],
      age_range: { min: 0, max: 75 }, // 年龄范围
      insurance_period: '终身', // 保险期间
      submit_mapping: baseSubmitMapping
    }
  },

  // 人寿保险产品 - WIOP3
  'life-insurance-wiop3': {
    name: 'WIOP3 - 盈传创富保障计划 3',
    component: 'LifeInsuranceTemplate',
    config: {
      currency: 'USD',
      payment_periods: [
        '整付(0-75 岁)',
        '5 年(0-70 岁)',
        '10 年(0-70 岁)'
      ],
      age_range: { min: 0, max: 75 },
      insurance_period: '终身',
      submit_mapping: baseSubmitMapping
    }
  },

  // 重疾保险产品 - MPC
  'critical-illness-mpc': {
    name: 'MPC 守护无间重疾',
    component: 'CriticalIllnessTemplate',
    config: {
      currency: 'USD',
      payment_periods: [
        '10 年(15 日 - 65 岁)',
        '20 年(15 日 - 65 岁)',
        '25 年(15 日 - 60 岁)'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      submit_mapping: baseSubmitMapping
    }
  },

  // 重疾保险产品 - MBC PRO
  'critical-illness-mbc-pro': {
    name: 'MBC PRO 活跃人生重疾保 PRO',
    component: 'CriticalIllnessTemplate',
    config: {
      currency: 'USD',
      payment_periods: [
        '10 年(15 日 - 65 岁)',
        '20 年(15 日 - 65 岁)',
        '25 年(15 日 - 60 岁)'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      submit_mapping: baseSubmitMapping
    }
  },

  // 重疾保险产品 - MBC2
  'critical-illness-mbc2': {
    name: 'MBC2 活跃人生重疾保 2',
    component: 'CriticalIllnessTemplate',
    config: {
      currency: 'USD',
      payment_periods: [
        '10 年(15 日 - 65 岁)',
        '20 年(15 日 - 65 岁)',
        '25 年(15 日 - 60 岁)'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      submit_mapping: baseSubmitMapping
    }
  },

  // ====== 储蓄型产品(统一逻辑) ======

  // GS - 宏挚传承保障计划
  'savings-gs': {
    name: '宏挚传承保障计划',
    component: 'SavingsTemplate',
    category: 'savings', // 储蓄型产品
    config: {
      currency: 'USD', // 默认美元
      payment_periods: [
        '整付',
        '3 年',
        '5 年',
        '10 年',
        '15 年',
      ],
      age_range: { min: 0, max: 100 },
      insurance_period: '终身',
      // 提取计划配置
      withdrawal_plan: {
        enabled: true,
        currencies: ['HKD', 'USD', 'CNY'], // 支持的币种
        default_currency: 'USD', // 统一为美元
        withdrawal_modes: ['指定提取金额', '最高固定提取金额'],
        withdrawal_periods: [
          '1年',
          '2年',
          '3年',
          '5年',
          '10年',
          '15年',
          '20年',
          '终身'
        ]
      },
      form_schema: savingsFormSchema,
      submit_mapping: savingsSubmitMapping
    }
  },

  // GC - 宏挚家传保险计划
  'savings-gc': {
    name: '宏挚家传保险计划',
    component: 'SavingsTemplate',
    category: 'savings',
    config: {
      currency: 'USD',
      payment_periods: [
        '整付',
        '3 年',
        '5 年',
      ],
      age_range: { min: 0, max: 100 },
      insurance_period: '终身',
      withdrawal_plan: {
        enabled: true,
        currencies: ['HKD', 'USD', 'CNY'],
        default_currency: 'USD', // 统一为美元
        withdrawal_modes: ['指定提取金额', '最高固定提取金额'],
        withdrawal_periods: [
          '1年',
          '2年',
          '3年',
          '5年',
          '10年',
          '15年',
          '20年',
          '终身'
        ]
      },
      form_schema: savingsFormSchema,
      submit_mapping: savingsSubmitMapping
    }
  },

  // FA - 宏浚传承保障计划
  'savings-fa': {
    name: '宏浚传承保障计划',
    component: 'SavingsTemplate',
    category: 'savings',
    config: {
      currency: 'USD',
      payment_periods: [
        '整付',
        '2 年',
        '5 年',
      ],
      age_range: { min: 0, max: 100 },
      insurance_period: '终身',
      withdrawal_plan: {
        enabled: true,
        currencies: ['HKD', 'USD', 'CNY'],
        default_currency: 'USD', // 统一为美元
        withdrawal_modes: ['指定提取金额', '最高固定提取金额'],
        withdrawal_periods: [
          '1年',
          '2年',
          '3年',
          '5年',
          '10年',
          '15年',
          '20年',
          '终身'
        ]
      },
      form_schema: savingsFormSchema,
      submit_mapping: savingsSubmitMapping
    }
  },

  // LV2 - 赤霞珠终身寿险计划2(储蓄型终身寿险)
  'savings-lv2': {
    name: '赤霞珠终身寿险计划2',
    component: 'SavingsTemplate',
    category: 'savings',
    config: {
      currency: 'USD',
      payment_periods: [
        '5 年',
        '8 年',
        '12 年',
        '15 年',
      ],
      age_range: { min: 0, max: 100 },
      insurance_period: '终身',
      withdrawal_plan: {
        enabled: true,
        currencies: ['HKD', 'USD', 'CNY'],
        default_currency: 'USD', // 统一为美元
        withdrawal_modes: ['指定提取金额', '最高固定提取金额'],
        withdrawal_periods: [
          '1年',
          '2年',
          '3年',
          '5年',
          '10年',
          '15年',
          '20年',
          '终身'
        ]
      },
      form_schema: savingsFormSchema,
      submit_mapping: savingsSubmitMapping
    }
  }
}

/**
 * 全局功能开关
 * @description 用于控制实验性功能或未来扩展功能的开关
 *
 * @example 开启多币种功能:设置 MULTI_CURRENCY_ENABLED = true
 */
export const FEATURE_FLAGS = {
  /**
   * 多币种切换功能
   * @description false: 方案 1 - 固定币种(当前实现)
   *              true: 方案 2 - 支持多币种切换(未来扩展)
   * @type {boolean}
   */
  MULTI_CURRENCY_ENABLED: false
}

/**
 * 币种符号映射
 * @description 币种代码到符号的映射关系
 */
export const CURRENCY_SYMBOLS = {
  CNY: '¥', // 人民币
  USD: '$', // 美元
  HKD: 'HK$', // 港币
  EUR: '€' // 欧元
}

/**
 * 币种完整信息映射
 * @description 币种代码到完整信息的映射(用于多币种模式)
 */
export const CURRENCY_MAP = {
  CNY: { label: '人民币', symbol: '¥', value: 'CNY' },
  USD: { label: '美元', symbol: '$', value: 'USD' },
  HKD: { label: '港币', symbol: 'HK$', value: 'HKD' },
  EUR: { label: '欧元', symbol: '€', value: 'EUR' }
}

/**
 * 根据 form_sn 获取模版配置
 * @param {string} formSn - 产品 API 返回的 form_sn 字段
 * @returns {Object|null} 模版配置对象,未找到返回 null
 *
 * @example
 * const config = getTemplateConfig('life-insurance-wiop3e')
 * // 返回: { name: 'WIOP3E...', component: 'LifeInsuranceTemplate', config: {...} }
 */
export function getTemplateConfig(formSn) {
  if (!formSn) {
    console.warn('[plan-templates] form_sn 为空')
    return null
  }

  const config = PLAN_TEMPLATES[formSn]
  if (!config) {
    console.error(`[plan-templates] 未找到模版配置: ${formSn}`)
    return null
  }

  return config
}

/**
 * 获取币种符号
 * @param {string} currencyCode - 币种代码(CNY/USD/HKD/EUR)
 * @returns {string} 币种符号
 *
 * @example
 * const symbol = getCurrencySymbol('USD') // 返回: '$'
 */
export function getCurrencySymbol(currencyCode) {
  return CURRENCY_SYMBOLS[currencyCode] || '¥'
}