feat(plan): 优化计划书表单交互
- RadioGroup 添加 change 事件发射 - SavingsTemplate 优化模式切换逻辑,使用 watch 自动清空对应字段
Showing
2 changed files
with
37 additions
and
24 deletions
| ... | @@ -13,6 +13,7 @@ | ... | @@ -13,6 +13,7 @@ |
| 13 | :key="option" | 13 | :key="option" |
| 14 | :label="option" | 14 | :label="option" |
| 15 | class="mr-8" | 15 | class="mr-8" |
| 16 | + @change="() => emit('change', option)" | ||
| 16 | > | 17 | > |
| 17 | {{ option }} | 18 | {{ option }} |
| 18 | </nut-radio> | 19 | </nut-radio> |
| ... | @@ -89,7 +90,13 @@ const emit = defineEmits([ | ... | @@ -89,7 +90,13 @@ const emit = defineEmits([ |
| 89 | * @event update:modelValue | 90 | * @event update:modelValue |
| 90 | * @param {string} value - 选中的选项 | 91 | * @param {string} value - 选中的选项 |
| 91 | */ | 92 | */ |
| 92 | - 'update:modelValue' | 93 | + 'update:modelValue', |
| 94 | + /** | ||
| 95 | + * 选项变化事件 | ||
| 96 | + * @event change | ||
| 97 | + * @param {string} value - 选中的选项 | ||
| 98 | + */ | ||
| 99 | + 'change' | ||
| 93 | ]) | 100 | ]) |
| 94 | 101 | ||
| 95 | /** | 102 | /** | ... | ... |
| ... | @@ -79,7 +79,6 @@ | ... | @@ -79,7 +79,6 @@ |
| 79 | label="提取选项" | 79 | label="提取选项" |
| 80 | :options="['指定提取金额', '最高固定提取金额']" | 80 | :options="['指定提取金额', '最高固定提取金额']" |
| 81 | :required="true" | 81 | :required="true" |
| 82 | - @change="onWithdrawalModeChange" | ||
| 83 | class="mb-5" | 82 | class="mb-5" |
| 84 | /> | 83 | /> |
| 85 | 84 | ||
| ... | @@ -181,7 +180,6 @@ | ... | @@ -181,7 +180,6 @@ |
| 181 | * @description GS/GC/FA/LV2 等储蓄型保险产品的计划书录入表单 | 180 | * @description GS/GC/FA/LV2 等储蓄型保险产品的计划书录入表单 |
| 182 | * - 表单字段:性别、出生年月日、是否吸烟、保额、缴费年期 | 181 | * - 表单字段:性别、出生年月日、是否吸烟、保额、缴费年期 |
| 183 | * - 提取计划:指定提取金额(按年岁/按保单年度)、最高固定提取金额 | 182 | * - 提取计划:指定提取金额(按年岁/按保单年度)、最高固定提取金额 |
| 184 | - * - 小程序端币种固定(使用配置中的默认币种) | ||
| 185 | * @author Claude Code | 183 | * @author Claude Code |
| 186 | * @example | 184 | * @example |
| 187 | * <SavingsTemplate | 185 | * <SavingsTemplate |
| ... | @@ -189,7 +187,7 @@ | ... | @@ -189,7 +187,7 @@ |
| 189 | * :config="templateConfig" | 187 | * :config="templateConfig" |
| 190 | * /> | 188 | * /> |
| 191 | */ | 189 | */ |
| 192 | -import { reactive, watch, computed } from 'vue' | 190 | +import { reactive, watch, computed, nextTick } from 'vue' |
| 193 | import Taro from '@tarojs/taro' | 191 | import Taro from '@tarojs/taro' |
| 194 | import PlanFieldName from '../PlanFields/NameInput.vue' | 192 | import PlanFieldName from '../PlanFields/NameInput.vue' |
| 195 | import PlanFieldAgePicker from '../PlanFields/AgePickerGlobal.vue' | 193 | import PlanFieldAgePicker from '../PlanFields/AgePickerGlobal.vue' |
| ... | @@ -321,11 +319,38 @@ watch( | ... | @@ -321,11 +319,38 @@ watch( |
| 321 | */ | 319 | */ |
| 322 | watch( | 320 | watch( |
| 323 | () => form, | 321 | () => form, |
| 324 | - (newVal) => emit('update:modelValue', newVal), | 322 | + (newVal) => { |
| 323 | + emit('update:modelValue', newVal) | ||
| 324 | + }, | ||
| 325 | { deep: true } | 325 | { deep: true } |
| 326 | ) | 326 | ) |
| 327 | 327 | ||
| 328 | /** | 328 | /** |
| 329 | + * 监听提取模式变化,清空对应字段 | ||
| 330 | + */ | ||
| 331 | +watch( | ||
| 332 | + () => form.withdrawal_mode, | ||
| 333 | + (newMode, oldMode) => { | ||
| 334 | + // 每次切换模式时,只清空输入字段(保留模式选择字段) | ||
| 335 | + if (newMode === '最高固定提取金额') { | ||
| 336 | + // 清空"指定提取金额"模式的输入字段 | ||
| 337 | + form.annual_withdrawal_amount = null | ||
| 338 | + form.annual_increase_percentage = null | ||
| 339 | + form.withdrawal_start_age = null | ||
| 340 | + form.withdrawal_period = null | ||
| 341 | + // 立即同步给父组件 | ||
| 342 | + emit('update:modelValue', { ...form }) | ||
| 343 | + } else if (newMode === '指定提取金额') { | ||
| 344 | + // 清空"最高固定提取金额"模式的输入字段 | ||
| 345 | + form.withdrawal_start_age = null | ||
| 346 | + form.withdrawal_period = null | ||
| 347 | + // 立即同步给父组件 | ||
| 348 | + emit('update:modelValue', { ...form }) | ||
| 349 | + } | ||
| 350 | + } | ||
| 351 | +) | ||
| 352 | + | ||
| 353 | +/** | ||
| 329 | * 提取年期选项(从配置读取) | 354 | * 提取年期选项(从配置读取) |
| 330 | * @type {ComputedRef<Array<string>>} | 355 | * @type {ComputedRef<Array<string>>} |
| 331 | */ | 356 | */ |
| ... | @@ -343,25 +368,6 @@ const withdrawalPeriods = computed(() => { | ... | @@ -343,25 +368,6 @@ const withdrawalPeriods = computed(() => { |
| 343 | }) | 368 | }) |
| 344 | 369 | ||
| 345 | /** | 370 | /** |
| 346 | - * 提取模式变化时的处理 | ||
| 347 | - * @param {string} mode - 新的提取模式 | ||
| 348 | - * | ||
| 349 | - * @description 当用户切换提取模式时,清除不相关的字段 | ||
| 350 | - * - 切换到"指定提取金额":保留字段,等待用户选择子选项 | ||
| 351 | - * - 切换到"最高固定金额":清除指定金额相关字段 | ||
| 352 | - */ | ||
| 353 | -const onWithdrawalModeChange = (mode) => { | ||
| 354 | - if (mode === '最高固定提取金额') { | ||
| 355 | - // 最高固定金额模式不需要指定金额的相关字段 | ||
| 356 | - delete form.specified_amount_type | ||
| 357 | - delete form.annual_withdrawal_amount | ||
| 358 | - delete form.annual_increase_percentage | ||
| 359 | - } else if (mode === '指定提取金额') { | ||
| 360 | - // 指定提取金额模式(按年岁),保留现有字段 | ||
| 361 | - } | ||
| 362 | -} | ||
| 363 | - | ||
| 364 | -/** | ||
| 365 | * 百分比输入限制(实时) | 371 | * 百分比输入限制(实时) |
| 366 | * @description 限制百分比输入为有效数值,最多2位小数 | 372 | * @description 限制百分比输入为有效数值,最多2位小数 |
| 367 | * 只允许输入数字和一个小数点 | 373 | * 只允许输入数字和一个小数点 | ... | ... |
-
Please register or login to post a comment