import { getState } from '@/store'; import { useFormContext } from '@/store/context.js'; export interface FixedSumInsuredValue { value: number; } export interface Liability { id: number; isDeleted: string; isSumInsuredEditable: string; sumInsuredType: string; fixedSumInsuredValue: FixedSumInsuredValue; sumInsuredValueStr: string; planProductId: number; liabilityCode: string; liabilityName: string; liabilityType: string; isOptionalEditable: string; isOptional: string; formKey: string; } interface Rule { type: string; targets: Array; } // 同步改变 const getNewFormData = (list: Array, value: string) => { const data: any = {}; list.forEach((item) => { data[item.formKey] = value; }); return data; }; export const useClauseRules = (rules: Rule[], liability: Liability) => { const form = useFormContext(); const { liabilityCode } = liability; const onChange = (value: string) => { if (!rules?.length) return; rules.forEach((rule) => { const { type, targets } = rule; if (type === 'and') { if (targets.findIndex((target) => target.liabilityCode === liabilityCode) !== -1) { const newData = getNewFormData(targets, value); form.setFieldsValue(newData); } } }); }; return onChange; };