/* * @Author: code4eat awesomedema@gmail.com * @Date: 2023-03-03 11:30:33 * @LastEditors: code4eat awesomedema@gmail.com * @LastEditTime: 2023-07-28 11:33:30 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ import BMSPagecontainer from '@/components/BMSPageContainer'; import { BMSTable } from '@/components/BMSTable'; import { createFromIconfontCN, MenuOutlined } from '@ant-design/icons'; import { ActionType, arrayMoveImmutable, ProFormSelect, useRefFunction } from '@ant-design/pro-components'; import { ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'; import { ProColumns } from '@ant-design/pro-table'; import { InputNumber, Dropdown, Input, MenuProps, message, Modal, Popconfirm, Space, Form, Table, Tabs } from 'antd'; import { TransferItem, TransferProps } from 'antd/es/transfer'; import React, { Key } from 'react'; import { useEffect, useImperativeHandle, useRef, useState } from 'react'; import { getMedicalGroup, getEmpTableDataFromMedicalGroup, addMedicalGroup, editMedicalGroup, delLeftReportData, addMedicalGroupEmp, updateMedicalGroupEmpInfo, delTableData, getAllUnitList, addGroupItemList, editGroupItemList } from './service'; import './style.less'; import '../../../../utils/zhongtaiB'; import '../../../../utils/zhongtaiA' import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; import { getSecondaryProjectDistriData } from '../secondaryProjectDistribute/service'; const IconFont = createFromIconfontCN({ scriptUrl: '', }); const AddIconFont = createFromIconfontCN({ scriptUrl: '', }); const DragHandle = SortableHandle(() => ( )); let _currentSelectedType: { groupCode: any; } | undefined = undefined; const SecondaryDistriGroupSet = () => { const [tableDataFilterParams, set_tableDataFilterParams] = useState(); const [typeList, set_typeList] = useState([]); const [showTypeListArr, set_showTypeListArr] = useState([]); const [currentSelectedType, set_currentSelectedType] = useState(undefined); const [tableSelectedKeys, set_tableSelectedKeys] = useState([]); const [selectedAddKeys, set_selectedAddKeys] = useState([]); const [ifShowModal, set_ifShowModal] = useState(false); const [currentEditLeftData, set_currentEditLeftData] = useState(undefined); const [ifEditTable, set_ifEditTable] = useState(false); const [currentTabKey, set_currentTabKey] = useState('1'); const tableRef = useRef(); const [dataSource,set_dataSource] = useState([]); const ref = React.createRef<{ save: any; getSelectedKeys: any }>(); const [tableColumns,set_tableColumns] = useState([]); const [tableDataSearchKeywords,set_tableDataSearchKeywords] = useState(''); const columnOne:ProColumns[] = [ { title: '核算单元名称', ellipsis: true, dataIndex: 'unitName', }, { title: '核算单元代码', dataIndex: 'unitCode', }, { title: '职类', dataIndex: 'unitTypeName', }, { title: '操作', key: 'option', valueType: 'option', render: (_: any, record: any) => { console.log({currentSelectedType}); return [ delTableDataHanfle(record)} > 删除 ] }, }, ]; const columnTwo = [ { title: '排序', dataIndex: 'sort', width: 60, className: 'drag-visible', render: () => , }, { title: '项目名称', ellipsis: true, dataIndex: 'itemName', }, { title: '占比', dataIndex: 'weightPercent', }, { title: '评价方式', dataIndex: 'evaluationName', }, { title: '来源', dataIndex: 'sourceName', } ] const getTableData = async (params?:any)=>{ if(!_currentSelectedType)return false; const { groupCode:secondGroupCode } = _currentSelectedType; let keywords=params?params.keywords:'' if (secondGroupCode) { const resp = await getEmpTableDataFromMedicalGroup(currentTabKey == '1'?{secondGroupCode,unitName:keywords}:{secondGroupCode,itemName:keywords},currentTabKey == '1'?1:2); if (resp) { set_dataSource(resp); } } } const switchChangeHandle = async (checked: boolean, record: any, key: string) => { const result = { ...record, medicalGroupManager: checked ? 1 : 0 } const resp = await updateMedicalGroupEmpInfo(result); if (resp) { tableRef.current?.reload(); } } const delTableDataHanfle = async (record?: { id: number; }) => { const resp = await delTableData(record ? [record.id] : [...tableSelectedKeys]); console.log({currentSelectedType}); if (resp) { set_tableSelectedKeys([]); getTableData(); } } //获取左侧数据 const getPageLeftData = async () => { const resp = await getMedicalGroup(); if (resp) { set_typeList(resp); set_showTypeListArr(resp); } } const updateTable = async (formVal: any, type: 'EDIT' | "ADD" | 'ADD_LEFTDATA' | 'EDIT_LEFTDATA') => { // console.log({formVal,type}); if (type == 'ADD_LEFTDATA') { const resp = await addMedicalGroup({ groupName: formVal.groupName, description: formVal.description, }); if (resp) { getPageLeftData(); } } if (type == 'EDIT_LEFTDATA') { const resp = await editMedicalGroup({ id: formVal.id, groupName: formVal.groupName, description: formVal.description }); if (resp) { getPageLeftData(); } } return true; } const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' | 'ADD_LEFTDATA' | 'EDIT_LEFTDATA' }) => { const getTrriger = () => { if (type == 'ADD') { return 添加 } if (type == 'EDIT') { return 编辑 } if (type == 'ADD_LEFTDATA') { return (
) } if (type == 'EDIT_LEFTDATA') { return 编辑 } } return ( { return updateTable(type == 'EDIT_LEFTDATA' ? { ...record, ...val } : val, type); }} > ) } interface TableSelecterProps extends TransferProps { tableSelecterColumn: any[]; record: any } const tableSelecterUnitColumn: any[] = [ { title: '核算单元名称', dataIndex: 'unitName', }, { title: '职类', dataIndex: 'unitTypeName', }, ]; const addGroupEmpHandle = () => { const ref = React.createRef<{ save: any; getSelectedKeys: any }>(); set_ifShowModal(true); } const TableSelecter = React.forwardRef(({ tableSelecterColumn, record }: TableSelecterProps, ref) => { const [datasource, set_datasource] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]); const [showList, set_showList] = useState([]); //获取表格数据 const getFuncList = async () => { const resp = await getAllUnitList({ secondGroupCode: currentSelectedType.groupCode }); if (resp) { set_datasource(resp); set_showList(resp); } } const onSelectChange = (newSelectedRowKeys: React.Key[]) => { setSelectedKeys([...newSelectedRowKeys]); }; const save = async () => { const result = { secondGroupCode: currentSelectedType.groupCode as string, unitCodeList: selectedKeys }; const resp = await addMedicalGroupEmp(result); if (resp) { message.success('添加成功!'); set_ifShowModal(false); getTableData(); } } useEffect(() => { getFuncList(); }, []) return (
} style={{ marginBottom: 8 }} onChange={(e) => { if (e.target.value.length != 0) { const result = datasource.filter(item => item.unitName.indexOf(e.target.value) != -1); set_showList(result); } else { set_showList(datasource); } }} />
set_ifShowModal(false)}>取消 save()}>{`确认(${selectedKeys.length > 0 && selectedKeys.length})`}
) }); const moreItems: MenuProps['items'] = [ { key: '1', label: , }, { key: '2', label: ( { e.preventDefault(); const resp = await delLeftReportData(currentEditLeftData.id); if (resp) { getPageLeftData(); } }}> 删除 ), } ]; const onTableSelectChange = (newSelectedRowKeys: React.Key[]) => { set_tableSelectedKeys([...newSelectedRowKeys]); }; const updateSecondaryDistriItemSet = async (itemList:any[],type:'ADD'|'EDIT')=>{ if(type == 'ADD'){ const totalWeight = itemList.reduce((prev,cur)=>{ console.log({'prev':prev,'cur.weight':cur.weight}) return (prev)+cur.weight },0); console.log({totalWeight,itemList}); if(totalWeight.toFixed(2) != 1){ message.error('占比总和必须等于1!'); return false } const result = { secondGroupCode:currentSelectedType.groupCode, itemList:itemList.map((a:any)=>({ secondItemCode:a.secondItemCode?a.secondItemCode:a.itemCode, weight:a.weight })) } const resp = await addGroupItemList(result); if(resp){ getTableData(); return true; } return false } if(type == 'EDIT'){ const resp = await editGroupItemList(itemList); if(resp){ getTableData(); } } } const AddItemComponent = () => { const [scoreList, set_scoreList] = useState([]); const [scoreInitList, set_scoreInitList] = useState({}); const addIndicator = () => { const key = Math.random(); const temp = [...scoreList, { tempId: key, id: key, [`secondItemCode${key}`]: '', [`weight${key}`]: '' }]; set_scoreInitList({ ...scoreInitList, [`secondItemCode${key}`]: '', [`weight${key}`]: '' }); set_scoreList([...temp]); } const delGroupIndic = (data: any, index: number) => { let temp = [...scoreList]; let defaultFormData: { [key: string]: any } = {}; const result = temp.filter((a: any) => a.id != data.id); result.forEach((a: any) => { defaultFormData[`secondItemCode${a.id}`] = a.secondItemCode; defaultFormData[`weight${a.id}`] = a.weight; }); set_scoreInitList({ ...defaultFormData }); set_scoreList([...result]); } useEffect(() => { let defaultFormData: { [key: string]: any } = {}; if (true) { const defaultVal = dataSource.map((a: any) => { defaultFormData[`secondItemCode${a.id}`] = a.itemCode; defaultFormData[`weight${a.id}`] = a.weight; return { ...a, tempId: Math.random() } }); set_scoreInitList({ ...defaultFormData }); set_scoreList([...defaultVal]); } },[]); return ( 添加 } onFinish={(val) => { return updateSecondaryDistriItemSet(scoreList,'ADD'); }} modalProps={{ destroyOnClose: true }} > { (
{ scoreList.map((item: any, index: number) => { return (
{ const resp = await getSecondaryProjectDistriData({pageSize:1000,current:1}); if (resp) { return resp.list.map((a: any) => ({ label: a.name, value: a.code })) } return [] }} fieldProps={{ // labelInValue:true, onChange(value, option: any) { // console.log({value,option}); const temp = [...scoreList]; const newArr = temp.map((a: any) => { if (a.id == item.id) { return { ...a, secondItemCode: value, secondItemName: option.label } } return a }); set_scoreList([...newArr]); }, }} /> { //console.log({value,index,indicatorData}); const temp = [...scoreList]; const newArr = temp.map((a: any) => { if (a.id == item.id) { return { ...a, weight: value } } return a }); set_scoreList([...newArr]); }} /> delGroupIndic(item, index)}>
) }) }
addIndicator()}> 增加一行
) }
) } const onTabChange = (activeKey:string) => { set_currentTabKey(activeKey); activeKey == '1'?set_tableColumns(columnOne):set_tableColumns(columnTwo); } const SortableItem = SortableElement((props: any) => ); const SortContainer = SortableContainer((props: any) => ); const onSortEnd = useRefFunction( ({ oldIndex, newIndex }: { oldIndex: number; newIndex: number }) => { if (oldIndex !== newIndex) { const newData = arrayMoveImmutable({ array: [...dataSource], fromIndex: oldIndex, toIndex: newIndex, }).filter((el) => !!el); const updatedSortArr = newData.map((item: any, index: number) => ({ ...item, sort: index })) set_dataSource([...updatedSortArr]); updateSecondaryDistriItemSet(updatedSortArr,'EDIT'); } }, ); const DraggableContainer = (props: any) => ( ); const DraggableBodyRow = (props: any) => { const { className, style, ...restProps } = props; // function findIndex base on Table rowKey props and should always be a right array index const index = dataSource.findIndex( (x) => x.id === restProps['data-row-key'], ); return ; }; useEffect(() => { _currentSelectedType = currentSelectedType; if (currentSelectedType) { set_tableDataFilterParams({ ...tableDataFilterParams, secondGroupCode: currentSelectedType.groupCode }); getTableData(); } }, [currentSelectedType]) useEffect(() => { if (showTypeListArr.length > 0) { set_currentSelectedType(showTypeListArr[0]); //set_tableDataFilterParams({ ...tableDataFilterParams, medicalGroupCode: showTypeListArr[0].code }); } }, [showTypeListArr]); useEffect(()=>{ getPageLeftData(); },[currentTabKey]); useEffect(()=>{ },[tableDataFilterParams]) useEffect(() => { getPageLeftData(); set_tableColumns(columnOne); }, []) return ( [] }} open={ifShowModal} modalProps={{ closable: false, }}>
} style={{ width: 156 }} onChange={(e) => { const result = typeList.filter(item => item.groupName.indexOf(e.target.value) != -1); set_showTypeListArr(result); }} />
{ showTypeListArr.map((item, index) => { return (
{ if (ifEditTable) { //编辑状态还未保存 Modal.confirm({ title: '当前存在编辑未保存,请保存后再操作!', okText: '放弃编辑', cancelText: '继续编辑', onOk(...args) { set_ifEditTable(false); set_currentSelectedType(item); }, }) } else { set_currentSelectedType(item) } }} >
{item.groupName}
{ bool && set_currentEditLeftData(item) }}>
) }) }
检索: getTableData({keywords:tableDataSearchKeywords})} /> } onChange={(e) => { set_tableDataSearchKeywords(e.target.value); if (e.target.value.length == 0) { getTableData({keywords:''}); } }} onPressEnter={(e) => { getTableData({keywords:tableDataSearchKeywords}); }} />
{currentTabKey == '1'? addGroupEmpHandle()}>添加:}
{(currentSelectedType&¤tTabKey) && { return ( delTableDataHanfle()} > 批量删除 ); }} params={tableDataFilterParams} dataSource={dataSource} //request={currentTabKey == '1'?(params, sort, filter) => getTableData(params, sort, filter):undefined} components={currentTabKey == '2' ? { body: { wrapper: DraggableContainer, row: DraggableBodyRow, }, } : undefined} />}
{ tableSelectedKeys.length > 0 && (
已选择{tableSelectedKeys.length}
tableRef.current?.clearSelected && tableRef.current?.clearSelected()}>取消选择 delTableDataHanfle()} > 批量删除
) }
) } export default SecondaryDistriGroupSet;