import React,{useEffect,useState,useMemo} from 'react'; import { Form, Button, Input, Row, Col, DatePicker, TreeSelect,Image,message,Upload } from 'antd'; import { formItemLayout, btnItemLayout } from '../../../components/crud/FormLayoutProps'; import apiurl from '../../../service/apiurl'; import { httpget2, httppost2,xyt_httpget2 } from '../../../utils/request'; import "./index.less" import moment from 'moment'; const url = "http://223.75.53.141:9102/test.by-lyf.tmp" const { Dragger } = Upload; const ModalForm = ({ mode, record,onEdit,onSave,onCrudSuccess }) => { const [form] = Form.useForm(); const [deptList, setDeptList] = useState([]) const [deptUserList, setDeptUserList] = useState([]) // 获取部门数据 const getDeptList = async() => { try { const result = await xyt_httpget2(apiurl.rcgl.zbgl.zbb.deptlist); if (result.code == 200) { setDeptList(result.data); getDeptUser() } } catch (error) { console.log(error); } } // 获取部门人员数据 const getDeptUser = async(deptId) => { try { const result = await xyt_httpget2(apiurl.rcgl.zbgl.zbb.userList, {pageNum:1,pageSize:9999}); if (result.code == 200) { setDeptUserList(result.rows) } } catch (error) { console.log(error); } } const buildTree = (data, parentId) => { let tree = []; data.forEach((node) => { node.title = node.deptName; node.key = node.deptId; if (node.parentId === parentId) { let children = buildTree(data, node.deptId); if (children.length) { node.children = children; } tree.push(node); } }); return tree; } const handleTreeList = (dept, user) => { const deptArr = dept.map(item => { return { ...item, value: item.deptId, title: item.deptName, disabled: item.userId ? false : true, children: user.filter(u => u.deptId == item.deptId).map(u => ({ ...u, value: u.userId, title: u.nickName })) } }) console.log("deptArr",deptArr); const treelist = buildTree(deptArr,0) return treelist } const treeList = useMemo(() => { if (deptUserList?.length > 0 && deptList?.length > 0) { return handleTreeList(deptList,deptUserList) } else { return [] } },[deptUserList,deptList]) const onFinish = async (values) => { if (mode === 'edit') { values.id = record?.id onEdit(apiurl.rcgl.zbgl.zbrz.edit,values) } if (mode === 'save') { onSave(apiurl.rcgl.zbgl.zbrz.save,values) } } useEffect(() => { getDeptList() // getDeptUser() }, []) return ( <>
dateString} getValueProps={value => ({ value: value ? moment(value) : undefined })} > { mode==='view'?null:( <> ) }
); } export default ModalForm;