import { CloseCircleOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { Button, Card, Col, Form, Popover, Row, message, Divider, Select, Input, Upload } from 'antd'; import type { FormInstance } from 'antd'; import { history, useLocation } from 'umi'; import type { Location } from 'umi'; import type { FC } from 'react'; import React, { useState, Fragment, useRef } from 'react'; import ProForm, { ProFormSelect, ProFormText, ProFormRadio, ProFormDigit, ProFormDependency, ProFormUploadButton, } from '@ant-design/pro-form'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import { submitForm } from './service'; import styles from './style.less'; import { fundNatureOptions, fundsProviderOptions, budgetTypeOptions, regionDictTypeOptions, regionOutsideOptions, currencyCodeOptions, purchaseTypeEnum, openTenderFormEnum, reviewMethodEnum, organizationFormEnum, tenderAgencyEnum, bidMethodEnum, evaluationMethodEnum, reviewWayEnum, processEnum, subjectTypeOptions, subjectType2Options, } from './dict'; import CitySelect from '@/components/CitySelect'; type InternalNamePath = (string | number)[]; const fieldLabels = { projectName: '项目名称', ProjectBizNo: '项目编号', tendereeOrgId: '项目归属单位', // tendereeId: '项目归属部门', // appManagerId: '项目负责人', appManagerTel: '联系电话', fundNature: '资金性质', // fundsProviderDict: '资金来源', budgetType: '预算类型', // regionDictType: '项目所在行政区域类型', //? regionDict: '项目所在行政区域', //? budgetAmount: '项目预算', currencyCode: '币种', openTenderForm: '招标类型', bidMethodDict: '采购方式', reviewMethod: '资审方式', // bidOrgDict: '组织形式', // tenderAgencyId: '招标代理机构', // }; interface ErrorField { name: InternalNamePath; errors: string[]; } // 主要标的表单控件 const SubjectFormItem = ({ value = [], onChange, disabled = false }: { value?: string[], onChange?: (value: string[]) => void, disabled?: boolean }) => { return ( ) } const normFile = (e: any) => { console.log('Upload event:', e); if (Array.isArray(e)) { return e; } return e?.fileList; }; const ProjectFileCreate: FC> = () => { const { query }: Location = useLocation(); const readOnly = query?.action === 'view'; const id = query?.id; // 文件 id const formRef = useRef(); const [error, setError] = useState([]); 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;