|
@@ -4,7 +4,7 @@
|
|
|
* @Author: code4eat awesomedema@gmail.com
|
|
|
* @Date: 2022-12-16 09:42:52
|
|
|
* @LastEditors: code4eat awesomedema@gmail.com
|
|
|
- * @LastEditTime: 2023-04-26 16:47:40
|
|
|
+ * @LastEditTime: 2023-04-26 19:33:00
|
|
|
* @FilePath: /BudgetManaSystem/src/pages/budgetMana/monthlySet/index.tsx
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
*/
|
|
@@ -22,9 +22,9 @@ import { DataNode } from 'antd/es/tree';
|
|
|
import expandedIcon from '../../../../../static/treenode_open.png';
|
|
|
import closeIcon from '../../../../../static/treenode_collapse.png';
|
|
|
import { BMSTable } from '@/components/BMSTable';
|
|
|
-import { ActionType, ProColumns} from '@ant-design/pro-components';
|
|
|
+import { ActionType, ProColumns } from '@ant-design/pro-components';
|
|
|
import { createFromIconfontCN } from '@ant-design/icons';
|
|
|
-import { CheckUnitDepMapTableDataType, delTableData,addMapDep, getCheckUnitDepMapTableDataByUnitClass, getMapDepList, getTreeData, getTreeDataRespType } from './service';
|
|
|
+import { CheckUnitDepMapTableDataType, delTableData, addMapDep, getCheckUnitDepMapTableDataByUnitClass, getMapDepList, getTreeData, getTreeDataRespType } from './service';
|
|
|
import { TransferItem, TransferProps } from 'antd/es/transfer';
|
|
|
|
|
|
import difference from 'lodash/difference';
|
|
@@ -65,9 +65,9 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
const [currentSelectedTreeNode, set_currentSelectedTreeNode] = useState<any | undefined>();
|
|
|
|
|
|
const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>(undefined);
|
|
|
- const [tableDataSearchKeywords,set_tableDataSearchKeywords] = useState('');
|
|
|
+ const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState('');
|
|
|
|
|
|
- const [tableData,set_tableData] = useState<CheckUnitDepMapTableDataType[]>([]);
|
|
|
+ const [tableData, set_tableData] = useState<CheckUnitDepMapTableDataType[]>([]);
|
|
|
|
|
|
const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]);
|
|
|
const [searchValue, setSearchValue] = useState('');
|
|
@@ -212,7 +212,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const TableTransfer = React.forwardRef(({ leftColumns, rightColumns, record }:any, ref) => {
|
|
|
+ const TableTransfer = React.forwardRef(({ leftColumns, rightColumns, record }: any, ref) => {
|
|
|
|
|
|
|
|
|
const [targetKeys, setTargetKeys] = useState<string[]>([]);
|
|
@@ -223,12 +223,12 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
const getFuncList = async () => {
|
|
|
const resp = await getMapDepList();
|
|
|
if (resp) {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
const defaultSelctedkeys = tableData.map((item: any) => item.deptCode);
|
|
|
- const hasSelectedData = tableData.map((a:any)=>({deptCode:a.deptCode,deptName:a.deptName,deptType:a.deptType,deptTypeName:a.deptTypeName}))
|
|
|
+ const hasSelectedData = tableData.map((a: any) => ({ deptCode: a.deptCode, deptName: a.deptName, deptType: a.deptType, deptTypeName: a.deptTypeName }))
|
|
|
|
|
|
- set_datasource([...resp,...hasSelectedData]);
|
|
|
+ set_datasource([...resp, ...hasSelectedData]);
|
|
|
|
|
|
setTargetKeys(defaultSelctedkeys);
|
|
|
|
|
@@ -250,9 +250,9 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
const needData = datasource.filter(item => targetKeys.includes(item.deptCode));
|
|
|
|
|
|
const result = {
|
|
|
- unitCode:record.code,
|
|
|
- unitType:record.unitType,
|
|
|
- department:needData
|
|
|
+ unitCode: record.code,
|
|
|
+ unitType: record.unitType,
|
|
|
+ department: needData
|
|
|
};
|
|
|
|
|
|
const resp = await addMapDep(result);
|
|
@@ -261,7 +261,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
message.success('添加成功!');
|
|
|
tableRef.current?.reload();
|
|
|
getTreeReqFunc();
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
@@ -395,7 +395,58 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
|
|
|
const getTreeReqFunc = async () => {
|
|
|
const resp = await getTreeData();
|
|
|
- set_treeData(resp);
|
|
|
+
|
|
|
+ function checkMap(node:any) {
|
|
|
+ if (!node.child || node.child.length === 0) {
|
|
|
+ // 如果当前节点没有子节点,说明是最里层的节点
|
|
|
+ return node.map === false;
|
|
|
+ } else {
|
|
|
+ // 如果当前节点有子节点,递归遍历所有子节点
|
|
|
+ let flag = false; //子节点是否存在false
|
|
|
+ for (let i = 0; i < node.child.length; i++) {
|
|
|
+ if (checkMap(node.child[i])) {
|
|
|
+ // 如果子节点存在 map 为 false,设置当前节点的 map 为 false
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function setParentMapVal(node:any,val:boolean) {
|
|
|
+ if (!node.child) {
|
|
|
+ // 如果当前节点没有子节点,则直接返回
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let item of node.child) {
|
|
|
+ // 递归处理子节点,将子节点的 map 属性改为 false
|
|
|
+ node.map = val,
|
|
|
+ setParentMapVal(item,val);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const newData = resp.map((item: any) => {
|
|
|
+ const flag = checkMap(item);
|
|
|
+ console.log({flag});
|
|
|
+ if(flag){
|
|
|
+ //将所有父级map改为false
|
|
|
+ setParentMapVal(item,false);
|
|
|
+ }else{
|
|
|
+ setParentMapVal(item,true);
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log({ newData });
|
|
|
+
|
|
|
+ set_treeData(newData);
|
|
|
}
|
|
|
|
|
|
const tableDataSearchHandle = (paramName: string) => {
|
|
@@ -409,7 +460,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if(currentSelectedTreeNode&¤tSelectedTreeNode.unitType){
|
|
|
+ if (currentSelectedTreeNode && currentSelectedTreeNode.unitType) {
|
|
|
tableRef.current?.reload();
|
|
|
}
|
|
|
}, [currentSelectedTreeNode]);
|
|
@@ -420,7 +471,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
useEffect(() => {
|
|
|
//初始化左侧树结构数据后
|
|
|
|
|
|
- if(currentSelectedTreeNode)return;
|
|
|
+ if (currentSelectedTreeNode) return;
|
|
|
|
|
|
if (treeData?.length > 0) {
|
|
|
|
|
@@ -465,7 +516,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
{
|
|
|
treeData && treeData.length > 0 && currentSelectedTreeNode && (
|
|
|
<DirectoryTree
|
|
|
- fieldNames={{ title: 'name', key: 'code',children:'child' }}
|
|
|
+ fieldNames={{ title: 'name', key: 'code', children: 'child' }}
|
|
|
rootStyle={{ height: '100%', paddingBottom: 50, overflowY: 'scroll', overflowX: 'hidden' }}
|
|
|
onSelect={onSelect}
|
|
|
onExpand={onExpand}
|
|
@@ -493,7 +544,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
return <div style={{
|
|
|
display: 'flex', flexDirection: 'row',
|
|
|
width: '100%',
|
|
|
- justifyContent:'space-between', alignItems: 'center', height: 32,
|
|
|
+ justifyContent: 'space-between', alignItems: 'center', height: 32,
|
|
|
borderRadius: '4px',
|
|
|
overflow: 'hidden',
|
|
|
color: '#17181A',
|
|
@@ -502,7 +553,7 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
|
|
|
}}>
|
|
|
{title}
|
|
|
- {!nodeData.map&&<span className='point'></span>}
|
|
|
+ {!nodeData.map && <span className='point'></span>}
|
|
|
</div>
|
|
|
}
|
|
|
}
|
|
@@ -527,22 +578,22 @@ const CheckUnitDepMap: React.FC = () => {
|
|
|
<span>检索:</span><Input className='searchInput' allowClear placeholder="请输入科室名称" onChange={(e) => {
|
|
|
set_tableDataSearchKeywords(e.target.value);
|
|
|
if (e.target.value.length == 0) {
|
|
|
- set_tableDataFilterParams({...tableDataFilterParams,deptName:''});
|
|
|
+ set_tableDataFilterParams({ ...tableDataFilterParams, deptName: '' });
|
|
|
}
|
|
|
}} suffix={
|
|
|
<IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('deptName')} />
|
|
|
- }
|
|
|
- onPressEnter={(e) => {
|
|
|
-
|
|
|
- set_tableDataFilterParams({
|
|
|
- ...tableDataFilterParams,
|
|
|
- deptName: (e.target as HTMLInputElement).value
|
|
|
- });
|
|
|
- }}
|
|
|
+ }
|
|
|
+ onPressEnter={(e) => {
|
|
|
+
|
|
|
+ set_tableDataFilterParams({
|
|
|
+ ...tableDataFilterParams,
|
|
|
+ deptName: (e.target as HTMLInputElement).value
|
|
|
+ });
|
|
|
+ }}
|
|
|
/>
|
|
|
</div>
|
|
|
<div className='btnGroup'>
|
|
|
- <span className='add' onClick={()=>addHandle()}>添加</span>
|
|
|
+ <span className='add' onClick={() => addHandle()}>添加</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
{currentSelectedTreeNode && <BMSTable actionRef={tableRef} params={tableDataFilterParams} rowKey='id' columns={tableColumn} request={(params, sort, filter) => getTableData('CHARGE', params, sort, filter)} />}
|