import React,{useEffect,useMemo,useState} from 'react'; import { Form, Button, Row, Col, Divider, message,TreeSelect } from 'antd'; import { formItemLayout, btnItemLayout } from '../../../components/crud/FormLayoutProps'; import { createCrudService } from '../../../components/crud/_'; import { getDictService,getDutyTypeService } from '../../../service/SelectValue' import apiurl from '../../../service/apiurl'; import NormalSelect from '../../../components/Form/NormalSelect' import { disable } from 'ol/rotationconstraint'; import { httpget2,xyt_httpget2 } from '../../../utils/request'; const ModalForm = ({ mode, record,onEdit,onSave,close,onCrudSuccess }) => { const [form] = Form.useForm(); const treeData = [ { value: 'parent 1', title: 'parent 1', disable:true, children: [ { value: 'parent 1-0', title: 'parent 1-0', disable:true, children: [ { value: 'leaf1', title: 'leaf1', disable:false, children:[] }, { value: 'leaf2', title: 'leaf2', disable:false, children:[] }, ], }, { value: 'parent 1-1', title: 'parent 1-1', children: [ { value: 'leaf3', title: ( leaf3 ), children:[] }, ], }, ], }, ]; console.log(record); const [value, setValue] = useState({}); const [isHoliday, setIsHoliday] = useState(0) const [deptList, setDeptList] = useState([]) const [deptUserList, setDeptUserList] = useState([]) /** * @description 表单重置 */ const onReset = () => { form.resetFields(); }; const onFinish = (values) => { let params = { isHoliday, rotaDate: record.time, userDtoList:Object.keys(values).map(item => ({ rotaType: item == "1" ? 1 : item == "2" ? 2 : item == "3" ? 3 : 4, userId : values[item] })) } if (mode == "save") { onSave(apiurl.fxzb.zbb.edit,params) } if (mode == "edit") { onEdit(apiurl.fxzb.zbb.edit,params) } } /** * @description 设置放假日 */ const handleHoliday = () => { setIsHoliday(1) form.submit() } // 获取部门数据 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() => { try { const result = await xyt_httpget2(apiurl.rcgl.zbgl.zbb.userList, {pageNum:1,pageSize:999}); 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]) useEffect(() => { if (mode == "edit") { let initialValues = { "1": record.shiftLeader.userId, "2": record.dutyLeader.userId, } console.log(initialValues); form.setFieldsValue(initialValues); } }, [record]) useEffect(() => { getDeptList() // getDeptUser() }, []) return (