2025-06-24 14:49:45 +08:00
|
|
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
|
|
import { Card, Form } from 'antd';
|
2025-06-23 19:15:13 +08:00
|
|
|
import styles from '../supplierTaskManageAdd.less';
|
2025-06-24 14:49:45 +08:00
|
|
|
import SupplierSelector from '@/components/SupplierSelector';
|
2025-06-23 19:15:13 +08:00
|
|
|
|
|
|
|
interface SupplierSelectStepProps {
|
|
|
|
formData: any;
|
|
|
|
onFormDataChange: (data: any) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SupplierItem {
|
2025-06-24 14:49:45 +08:00
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
supplierType: string;
|
|
|
|
[key: string]: any;
|
2025-06-23 19:15:13 +08:00
|
|
|
}
|
|
|
|
|
2025-06-23 21:39:51 +08:00
|
|
|
const SupplierSelectStep = forwardRef<any, SupplierSelectStepProps>(({ formData, onFormDataChange }, ref) => {
|
|
|
|
// 暴露表单方法给父组件
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
|
validateFields: () => {
|
|
|
|
// 这里可以添加自定义验证逻辑
|
|
|
|
return Promise.resolve();
|
|
|
|
},
|
|
|
|
getFieldsValue: () => {
|
|
|
|
return {
|
2025-06-24 14:49:45 +08:00
|
|
|
selectedSuppliers: formData.selectedSuppliers || [],
|
|
|
|
supplierIds: (formData.selectedSuppliers || []).map((supplier: SupplierItem) => ({ id: supplier.id }))
|
2025-06-23 21:39:51 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
setFieldsValue: (values: any) => {
|
|
|
|
if (values.selectedSuppliers) {
|
2025-06-24 14:49:45 +08:00
|
|
|
onFormDataChange({
|
|
|
|
...formData,
|
|
|
|
selectedSuppliers: values.selectedSuppliers
|
|
|
|
});
|
2025-06-23 21:39:51 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2025-06-24 14:49:45 +08:00
|
|
|
// 处理供应商选择
|
|
|
|
const handleSupplierSelect = (suppliers: SupplierItem[]) => {
|
2025-06-23 21:39:51 +08:00
|
|
|
onFormDataChange({
|
2025-06-24 14:49:45 +08:00
|
|
|
...formData,
|
2025-06-23 21:39:51 +08:00
|
|
|
selectedSuppliers: suppliers,
|
2025-06-24 14:49:45 +08:00
|
|
|
supplierIds: suppliers.map(supplier => ({ id: supplier.id }))
|
2025-06-23 21:39:51 +08:00
|
|
|
});
|
2025-06-23 19:15:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.supplierSelectStep}>
|
2025-06-24 14:49:45 +08:00
|
|
|
<Card title="供应商选择" bordered={false} className="inner-card">
|
|
|
|
<SupplierSelector
|
|
|
|
onSelect={handleSupplierSelect}
|
|
|
|
selectedSuppliers={formData.selectedSuppliers || []}
|
|
|
|
/>
|
2025-06-23 19:15:13 +08:00
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
);
|
2025-06-23 21:39:51 +08:00
|
|
|
});
|
2025-06-23 19:15:13 +08:00
|
|
|
|
|
|
|
export default SupplierSelectStep;
|