([]);
const getErrorInfo = (errors: ErrorField[]) => {
const errorCount = errors.filter((item) => item.errors.length > 0).length;
if (!errors || errorCount === 0) {
return null;
}
const scrollToField = (fieldKey: string) => {
const labelNode = document.querySelector(`label[for="${fieldKey}"]`);
if (labelNode) {
labelNode.scrollIntoView(true);
}
};
const errorList = errors.map((err) => {
if (!err || err.errors.length === 0) {
return null;
}
const key = err.name[0] as string;
return (
scrollToField(key)}>
{err.errors[0]}
{fieldLabels[key as keyof typeof fieldLabels]}
);
});
return (
{
if (trigger && trigger.parentNode) {
return trigger.parentNode as HTMLElement;
}
return trigger;
}}
>
{errorCount}
);
};
const onFinish = async (values: Record) => {
setError([]);
try {
console.log(values);
await submitForm(values);
message.success('提交成功');
} catch {
// console.log
}
};
const onFinishFailed = (errorInfo: any) => {
setError(errorInfo.errorFields);
};
return (
{
if (readOnly) {
return (
);
}
const _dom = dom.filter((item: JSX.Element) => item.key !== 'rest').concat([
]).concat([
]);
return (
{getErrorInfo(error)}
{_dom}
);
},
}}
initialValues={{
budgetType: '1',
regionDictType: '1',
budgetAmount: 0,
currencyCode: 'CNY',
bidSection: [{
bidSectionIndex: 1,
bidSectionName: '',
bidSectionNo: '',
bidSectionBudget: 0,
bidMethod: '',
bidSectionCategory: [{
type: [],
percent: 0,
}],
}],
}}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
labelCol={{ span: 5 }}
wrapperCol={{ span: 19 }}
>
{
formRef.current?.setFieldsValue({
regionDict: undefined,
});
},
}}
/>
{({ bidSection }) => {
// 计算所有标段预算之和
const total = Array.isArray(bidSection)
? bidSection.reduce((sum, item) => sum + (parseFloat(item?.bidSectionBudget) || 0), 0)
: 0;
return (
);
}}
{({ regionDictType }, ...rest) => {
console.log(rest);
return (
<>
{regionDictType === '1' ? (
}
required={false}
colon={false}
rules={[
{
required: true,
validator: (_, value) => {
if (!value || !value.province || !value.city || !value.district) {
return Promise.reject(new Error('请完整选择省市区'));
}
return Promise.resolve();
}
}
]}
>
) : (
}
required={false}
colon={false}
rules={[{ required: true, message: '请选择项目所在行政区域' }]}
options={regionOutsideOptions}
placeholder="请选择行政区域"
fieldProps={{
disabled: readOnly,
}}
/>
)}
>
);
}}
{(fields, { add, remove }) => (
<>
{fields.map(field => (
{field.key !== 0 && }
{({ currencyCode }) => {
return (
<>
{currencyCode}
>
);
}}
{(subFields, { add: addCategory, remove: removeCategory }) => (
<>
{subFields.map(subField => (
{
if (!value || !value[0] || !value[1]) {
return Promise.reject(new Error('请完整选择主要标的类别'));
}
return Promise.resolve();
}
}
]}>
%
removeCategory(subField.name)} disabled={readOnly} />
))}
>
)}
))}
>
)}
{
e.preventDefault();
}}
disabled={readOnly}
/>
{
const isRarOrZipOrDocOrDocxOrPdf = file.type === 'application/x-rar-compressed' ||
file.type === 'application/zip' ||
file.type === 'application/msword' ||
file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ||
file.type === 'application/pdf';
if (!isRarOrZipOrDocOrDocxOrPdf) {
message.error('你只能上传 rar/zip/doc/docx/pdf 文件!');
return Upload.LIST_IGNORE;
}
const isLt20M = file.size / 1024 / 1024 < 20;
if (!isLt20M) {
message.error('文件大小不能超过 20MB!');
return Upload.LIST_IGNORE;
}
return true;
},
}}
/>
);
};
export default ProjectFileCreate;