"use client"; import { Button, Form, Input, Select, DatePicker, Radio, message, Modal, Cascader, InputNumber } from "antd"; import { useState, useMemo } from "react"; import { useStaff } from "@nice/client"; import { areaOptions } from './area-options'; const { TextArea } = Input; const StaffInfoWrite = () => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const { create, useCustomFields } = useStaff(); const { data: fields, isLoading: fieldsLoading } = useCustomFields(); // 按分组组织字段 const fieldGroups = useMemo(() => { if (!fields) return {}; return fields.reduce((groups: any, field: any) => { const group = field.group || '其他信息'; if (!groups[group]) { groups[group] = []; } groups[group].push(field); return groups; }, {}); }, [fields]); const renderField = (field: any) => { switch (field.type) { case 'text': return ; case 'number': return ; case 'date': return ; case 'select': // 检查 field.options 是否存在且有数据 if (field.options && field.options.length > 0) { return ; case 'radio': // 检查 field.options 是否存在且有数据 if (field.options && field.options.length > 0) { return ; } return ; case 'textarea': return ; default: return ; } }; const onFinish = async (values: any) => { try { setLoading(true); const formattedValues = { ...values, birthplace: values.birthplace?.join('/'), }; await create.mutateAsync({ data: formattedValues }); message.success("信息提交成功"); } catch (error) { console.error('提交出错:', error); message.error("提交失败,请重试"); } finally { setLoading(false); } }; if (fieldsLoading) { return
加载中...
; } return (

人员信息管理

{/* 信息填报表单 */}
{Object.entries(fieldGroups).map(([groupName, groupFields]) => (

{groupName}

{groupFields.map((field: any) => ( {renderField(field)} ))}
))}
); }; export default StaffInfoWrite;