import { MessageFu } from '@/utils/message' import { Button, Cascader, Checkbox, Form, FormInstance, Input, Modal, Select } from 'antd' import React, { useCallback, useEffect, useRef } from 'react' import styles from './index.module.scss' import MyPopconfirm from '@/components/MyPopconfirm' import { getUserInfoByIdAPI, userSaveAPI } from '@/store/action/Z6user' import { useDispatch, useSelector } from 'react-redux' import { RootState } from '@/store' import { Z5_APIgetList } from '@/store/action/Z5role' import { treeLastIdFindFatherFu } from '../data' import { UserTableAPIType } from '@/types' type Props = { id: any closePage: () => void upTableList: (formOld: UserTableAPIType) => void addTableList: () => void formOld: UserTableAPIType } function UserAdd({ id, closePage, upTableList, addTableList, formOld }: Props) { // 角色 const dispatch = useDispatch() useEffect(() => { dispatch( Z5_APIgetList({ pageNum: 1, pageSize: 99999, searchKey: '' }) ) }, [dispatch]) const { list: roleList } = useSelector((state: RootState) => state.Z5role.tableInfo) // 所属部门 const { treeData } = useSelector((state: RootState) => state.Z4organization) // 设置表单初始数据(区分编辑和新增) const FormBoxRef = useRef(null) const getInfoInAPIFu = useCallback( async (id: number) => { if (treeData && treeData.length) { const res = await getUserInfoByIdAPI(id) const data = res.data const deptId = treeLastIdFindFatherFu(treeData, data.deptId + '', 'id') FormBoxRef.current?.setFieldsValue({ ...data, deptId }) } // console.log("是编辑,在这里发请求拿数据", res); }, [treeData] ) // 没有通过校验 const onFinishFailed = useCallback(() => { // return MessageFu.warning("有表单不符号规则!"); }, []) useEffect(() => { if (id) getInfoInAPIFu(id) else { FormBoxRef.current?.setFieldsValue({}) } }, [getInfoInAPIFu, id]) // 通过校验点击确定 const onFinish = useCallback( async (values: any) => { const obj = { ...values, id: id ? id : null } const deptIdRes = obj.deptId if (deptIdRes) obj.deptId = Number(deptIdRes[deptIdRes.length - 1]) obj.isLeader = obj.isLeader ? 1 : 0 // if (1 + 1 === 2) { // console.log(123, obj) // return // } const res: any = await userSaveAPI(obj) if (res.code === 0) { MessageFu.success(id ? '编辑成功!' : '新增成功!') if (id) upTableList(formOld) else addTableList() closePage() } // console.log("通过校验,点击确定"); }, [addTableList, closePage, formOld, id, upTableList] ) return (
e.target.value.replace(/\s+/g, '')} > e.target.value.replace(/\s+/g, '')} > e.target.value.replace(/\s+/g, '')} >
(e.target.checked ? 1 : 0)} > 设为主管