plan-templates.js 18.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
/**
 * 计划书模版配置
 *
 * @description 定义产品 form_sn 到模版组件和配置的映射关系
 * @module config/plan-templates
 * @author Claude Code
 * @created 2026-02-06
 * @updated 2026-02-13 - 新增文档解析工具入口
 *
 * --- 快速添加新产品(开发工具) ---
 * 开发环境可使用以下工具快速添加新产品配置:
 * 1. 文档解析工具:/admin/document-parser/index (上传 PDF/Word,AI 自动解析)
 * 2. API 配置工具:/admin/document-parser/config (配置 AI 服务)
 *
 * 使用方式:
 * - 上传产品文档 → AI 自动提取配置 → 生成配置代码 → 复制到此文件
 *
 * --- 手动添加步骤 ---
 * 1. 找到对应的产品分类(人寿/重疾/储蓄)
 * 2. 复制现有配置作为模板
 * 3. 修改 name, currency, payment_periods, age_range 等字段
 * 4. 确保 form_sn 唯一(建议使用产品英文标识 + 版本号)
 */

/**
 * 计划书模版配置映射
 * @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' },
  age: { api_field: 'customer_age' },
  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' }
}

// 人寿/重疾基础表单 Schema(通用保障类)
const protectionFormSchema = {
  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: 'age', key: 'age', type: 'age', label: '年龄', placeholder: '请输入年龄', input_label: '岁', required: false },
    { id: 'birthday', key: 'birthday', type: 'date', label: '出生年月日', placeholder: '请选择年月日', required: false },
    { 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' }
  ]
}

// 储蓄类提交字段映射(在基础映射上追加提取计划字段)
// @updated 2026-02-28 - 移除吸烟字段映射(储蓄类产品不需要)
const savingsSubmitMapping = {
  customer_name: { api_field: 'customer_name' },
  gender: { api_field: 'customer_gender' },
  age: { api_field: 'customer_age' },
  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' },
  withdrawal_enabled: { api_field: 'allow_reduce_amount' },
  withdrawal_mode: { api_field: 'withdrawal_option' },
  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' },
  withdrawal_start_age_specified: { api_field: 'withdrawal_start_age' },
  withdrawal_period_specified: { api_field: 'withdrawal_period' },
  withdrawal_start_age_fixed: { api_field: 'withdrawal_start_age' },
  withdrawal_period_fixed: { api_field: 'withdrawal_period' }
}

// 储蓄类表单 Schema(渲染 + 校验 + 联动的唯一入口)
// @updated 2026-02-15 - 迁移到新的条件规则格式,使用 clear_when_hidden 替代 reset_map
// @updated 2026-02-25 - 年龄与出生年月日二选一填写
// @updated 2026-02-28 - 移除吸烟字段(储蓄类产品不需要)
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: 'age', key: 'age', type: 'age', label: '年龄', placeholder: '请输入年龄', input_label: '岁', required: false },
    { id: 'birthday', key: 'birthday', type: 'date', label: '出生年月日', placeholder: '请选择年月日', required: false },
    { 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 开关控制
  // 新格式说明:
  // - show_when: { field: 'xxx', op: 'eq', value: 'yyy' } 新格式条件
  // - show_when: { field: 'xxx', equals: 'yyy' } 旧格式(向后兼容)
  // - clear_when_hidden: true 隐藏时自动清空字段值
  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: '款项提取(允许减少名义金额)', clear_when_hidden: true },
    // 指定提取金额模式字段
    { id: 'withdrawal_method', key: 'withdrawal_method', type: 'radio', label: '提取方式', options: ['按年岁'], required: true, default: '按年岁', show_when: { field: 'withdrawal_mode', op: 'eq', value: '指定提取金额' }, clear_when_hidden: true },
    { id: 'withdrawal_start_age_specified', key: 'withdrawal_start_age_specified', type: 'age', label: '由几岁开始', placeholder: '请输入开始提取年龄', required: true, show_when: { field: 'withdrawal_mode', op: 'eq', value: '指定提取金额' }, clear_when_hidden: true },
    { id: 'withdrawal_period_specified', key: 'withdrawal_period_specified', type: 'select', label: '提取期(年)', placeholder: '请选择提取期', required: true, options_from: 'withdrawal_plan.withdrawal_periods', show_when: { field: 'withdrawal_mode', op: 'eq', value: '指定提取金额' }, clear_when_hidden: true },
    { 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', op: 'eq', value: '指定提取金额' }, clear_when_hidden: true },
    { id: 'annual_increase_percentage', key: 'annual_increase_percentage', type: 'percentage', label: '每年递增提取之百分比(%)', placeholder: '请输入递增百分比', required: true, show_when: { field: 'withdrawal_mode', op: 'eq', value: '指定提取金额' }, clear_when_hidden: true },
    // 最高固定提取金额模式字段
    { id: 'withdrawal_start_age_fixed', key: 'withdrawal_start_age_fixed', type: 'age', label: '按年岁:由几岁开始', placeholder: '请输入开始提取年龄', required: true, show_when: { field: 'withdrawal_mode', op: 'eq', value: '最高固定提取金额' }, clear_when_hidden: true },
    { id: 'withdrawal_period_fixed', key: 'withdrawal_period_fixed', type: 'select', label: '按年岁:提取期(年)', placeholder: '请选择提取期', required: true, options_from: 'withdrawal_plan.withdrawal_periods', show_when: { field: 'withdrawal_mode', op: 'eq', value: '最高固定提取金额' }, clear_when_hidden: true }
  ]
  // reset_map 已被 clear_when_hidden 替代
  // 当 withdrawal_mode 切换时,不可见的字段会自动清空
}

/**
 * 多阶段提取计划配置
 * @description 用于"宏挚传承保障计划(多阶段)"等支持多阶段提取的产品
 * @updated 2026-02-25 - 新增多阶段提取功能
 */
const multiStageWithdrawalConfig = {
  enabled: true,
  stage_limit: 4,                           // 阶段上限(预留修改空间)
  age_threshold: 12,                        // 年龄阈值(<12岁固定3组,≥12岁可添加)
  withdrawal_periods: [
    '1年', '2年', '3年', '5年',
    '10年', '15年', '20年', '终身',
    '一笔过'                                 // 新增:一次性提取选项
  ],
  percentage_optional: true                 // 递增百分比可选
}

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: '终身', // 保险期间
      form_schema: protectionFormSchema,
      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: '终身',
      form_schema: protectionFormSchema,
      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 岁)',
        '直至65岁'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      form_schema: protectionFormSchema,
      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 岁)',
        '直至65岁'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      form_schema: protectionFormSchema,
      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 岁)',
        '直至65岁'
      ],
      age_range: { min: 0, max: 65 },
      insurance_period: '终身',
      form_schema: protectionFormSchema,
      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
    }
  },

  // GS - 宏挚传承保障计划(多阶段模式)⭐ 新增
  // @description 支持多阶段提取计划,根据年龄控制阶段数量
  // @updated 2026-02-25 - 新增多阶段提取功能
  'savings-gs-multistage': {
    name: '宏挚传承保障计划(多阶段)',
    component: 'SavingsTemplate',
    category: 'savings',
    config: {
      currency: 'USD',
      payment_periods: [
        '整付',
        '3 年',
        '5 年',
        '10 年',
        '15 年',
      ],
      age_range: { min: 0, max: 100 },
      insurance_period: '终身',
      // 多阶段提取计划配置
      multi_stage_withdrawal: multiStageWithdrawalConfig,
      withdrawal_plan: {
        enabled: true,
        currencies: ['HKD', 'USD', 'CNY'],
        default_currency: 'USD',
        // 多阶段模式:支持指定提取金额(多组)和最高固定提取金额(单组)
        withdrawal_modes: ['指定提取金额', '最高固定提取金额'],
        withdrawal_periods: multiStageWithdrawalConfig.withdrawal_periods
      },
      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] || '¥'
}