index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-09-27 16:45:37
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import BMSPagecontainer from '@/components/BMSPageContainer';
  10. import { BMSTable } from '@/components/BMSTable';
  11. import { createFromIconfontCN } from '@ant-design/icons';
  12. import { ActionType, ProForm, ProFormDigit, ProFormInstance, ProFormSelect } from '@ant-design/pro-components';
  13. import { ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Form, Input, InputNumber, message, Modal, Popconfirm, Table, Transfer } from 'antd';
  16. import { DefaultOptionType } from 'antd/es/select';
  17. import { ColumnsType, TableRowSelection } from 'antd/es/table/interface';
  18. import { TransferItem, TransferProps } from 'antd/es/transfer';
  19. import React, { useImperativeHandle } from 'react';
  20. import { useEffect, useRef, useState } from 'react'
  21. import { getManaIndicListData } from '../manaIndicItemSet/service';
  22. import difference from 'lodash/difference';
  23. import { addData, addIndicGroup, addUnitForGroup, delData, editData, getAllUnit, getData } from './service';
  24. import './style.less';
  25. import { omit } from 'lodash';
  26. import { create, all } from 'mathjs'
  27. const config = {
  28. number: 'bignumber',
  29. precision:2
  30. }
  31. const math = create(all, config as any);
  32. const IconFont = createFromIconfontCN({
  33. scriptUrl: '//at.alicdn.com/t/c/font_1927152_gfxzp431jpt.js',
  34. });
  35. const AddIconFont = createFromIconfontCN({
  36. scriptUrl: '//at.alicdn.com/t/c/font_3824256_kzhiq41zywa.js',
  37. });
  38. export default function IndicGroupWeightSet() {
  39. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  40. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  41. const [currentOperateRow, set_currentOperateRow] = useState<any | undefined>(undefined); //当前操作的表格行数据
  42. const tableRef = useRef<ActionType>();
  43. const columns = [
  44. {
  45. title: '分组名称',
  46. dataIndex: 'groupName',
  47. width: 150
  48. },
  49. {
  50. title: '组内单元名称',
  51. dataIndex: 'unitInfoVos',
  52. width: 250,
  53. ellipsis: true,
  54. render: (_: any, record: any) => {
  55. if (record.unitInfoVos && typeof record.unitInfoVos == 'object') {
  56. return record.unitInfoVos.reduce((prev: any, cur: any) => `${prev.length > 0 ? prev + ' | ' : prev}${cur.unitName}`, '')
  57. }
  58. return ''
  59. }
  60. },
  61. {
  62. title: '管理指标',
  63. ellipsis: true,
  64. width: 250,
  65. dataIndex: 'indicatorWeights',
  66. render: (_: any, record: any) => {
  67. if (record.indicatorWeights && typeof record.indicatorWeights == 'object') {
  68. return record.indicatorWeights.reduce((prev: any, cur: any) => `${prev.length > 0 ? prev + ' | ' : prev}${cur.indicatorName}`, '')
  69. }
  70. return ''
  71. }
  72. },
  73. {
  74. title: '总分下限',
  75. dataIndex: 'floor',
  76. width: 80
  77. },
  78. {
  79. title: '总分上限',
  80. dataIndex: 'ceiling',
  81. width: 80
  82. },
  83. {
  84. title: '说明',
  85. dataIndex: 'depiction',
  86. },
  87. {
  88. title: '操作',
  89. key: 'option',
  90. width: 160,
  91. valueType: 'option',
  92. render: (_: any, record: any) => {
  93. return [
  94. <a key={'fuc'} onClick={() => addFuncHandle(record)}>单元</a>,
  95. <UpDataActBtn key={'act_INDICATOR'} record={record} type='INDICATOR' />,
  96. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  97. <Popconfirm
  98. title="是否确认删除?"
  99. key="del"
  100. onConfirm={() => delTableData(record)}
  101. >
  102. <a>删除</a>
  103. </Popconfirm>
  104. ]
  105. },
  106. },
  107. ]
  108. const getTableData = async (params: any) => {
  109. const resp = await getData(params);
  110. if (resp) {
  111. return {
  112. data: resp,
  113. success: true,
  114. }
  115. }
  116. return []
  117. }
  118. const delTableData = async (record: any) => {
  119. const resp = await delData(record.id);
  120. if (resp) {
  121. message.success('操作成功!');
  122. tableRef.current?.reload();
  123. // message.success('操作成功!');
  124. }
  125. }
  126. const updateTable = async (formVal: any, type: 'EDIT' | 'ADD' | 'INDICATOR' | 'UNIT') => {
  127. if (type == 'ADD') {
  128. const resp = await addData({ ...formVal });
  129. if (resp) {
  130. tableRef.current?.reload();
  131. message.success('操作成功!');
  132. }
  133. }
  134. if (type == 'EDIT') {
  135. const resp = await editData({ ...formVal });
  136. if (resp) {
  137. tableRef.current?.reload();
  138. message.success('操作成功!');
  139. }
  140. }
  141. if (type == 'INDICATOR') {
  142. const resp = await addIndicGroup({ ...formVal });
  143. if (resp) {
  144. tableRef.current?.reload();
  145. message.success('操作成功!');
  146. }else{
  147. return false
  148. }
  149. }
  150. return true;
  151. }
  152. interface DataType {
  153. key: string;
  154. title: string;
  155. description: string;
  156. disabled: boolean;
  157. tag: string;
  158. }
  159. interface TableTransferProps extends TransferProps<TransferItem> {
  160. dataSource: DataType[];
  161. leftColumns: ColumnsType<DataType>;
  162. rightColumns: ColumnsType<DataType>;
  163. record: any
  164. }
  165. const transferTableColumn = [
  166. {
  167. title: '核算单元名称',
  168. dataIndex: 'unitName',
  169. key: 'unitName',
  170. },
  171. {
  172. title: '职类',
  173. dataIndex: 'unitType',
  174. key: 'unitType',
  175. render: (_: any, record: any) => {
  176. switch (parseInt(record.unitType)) {
  177. case 1:
  178. return '临床'
  179. break;
  180. case 2:
  181. return '医技'
  182. break;
  183. case 3:
  184. return '护理'
  185. break;
  186. case 6:
  187. return '行政后勤'
  188. break;
  189. default:
  190. break;
  191. }
  192. }
  193. },
  194. ]
  195. const addFuncHandle = (record: any) => {
  196. set_currentOperateRow(record);
  197. const ref = React.createRef<{ save: any; }>();
  198. Modal.confirm({
  199. title: `添加分组核算单元(${record.groupName})`,
  200. icon: <></>,
  201. okText: '确定',
  202. cancelText: '取消',
  203. width: 688,
  204. centered:true,
  205. content: <TableTransfer
  206. ref={ref}
  207. record={record}
  208. leftColumns={transferTableColumn}
  209. rightColumns={transferTableColumn} dataSource={[]}
  210. ></TableTransfer>,
  211. onOk: () => {
  212. return ref.current && ref.current.save();
  213. }
  214. })
  215. }
  216. const TableTransfer = React.forwardRef(({ leftColumns, rightColumns, record, ...restProps }: TableTransferProps, ref) => {
  217. const [_data, _set_data] = useState<any>();
  218. const [targetKeys, setTargetKeys] = useState<string[]>([]);
  219. const [datasource, set_datasource] = useState<any[]>([]);
  220. const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
  221. //获取单元
  222. const getFuncList = async () => {
  223. const resp = await getAllUnit();
  224. if (resp) {
  225. if (record ) {
  226. if(record.unitInfoVos){
  227. const defaultSelctedkeys = record.unitInfoVos.map((item: any) => item.unitCode);
  228. setTargetKeys(defaultSelctedkeys);
  229. }
  230. set_datasource([...resp,...(record.unitInfoVos?record.unitInfoVos.map((a:any)=>({...a,code:a.unitCode})):[])]);
  231. }
  232. }
  233. }
  234. const onChange = (nextTargetKeys: string[]) => {
  235. setTargetKeys(nextTargetKeys);
  236. };
  237. const onSelectChange = (sourceSelectedKeys: string[], targetSelectedKeys: string[]) => {
  238. //console.log('sourceSelectedKeys:', sourceSelectedKeys,'targetSelectedKeys:',targetSelectedKeys);
  239. setSelectedKeys([...sourceSelectedKeys, ...targetSelectedKeys]);
  240. };
  241. useImperativeHandle(ref, () => ({
  242. save: async () => {
  243. const needData = datasource.filter(item => targetKeys.includes(item.code));
  244. const result = needData.map(a=>({unitCode:a.code,unitName:a.unitName}))
  245. const resp = await addUnitForGroup({
  246. id: record.id,
  247. unitInfoVos: result
  248. });
  249. if (resp) {
  250. tableRef.current?.reload();
  251. }
  252. }
  253. }));
  254. useEffect(() => {
  255. getFuncList();
  256. }, [])
  257. return (
  258. <Transfer className='TableTransfer' showSearch
  259. titles={['待选项', '已选项']}
  260. locale={{
  261. itemUnit: '项',
  262. itemsUnit: '项',
  263. searchPlaceholder: '请输入'
  264. }}
  265. onChange={onChange}
  266. onSelectChange={onSelectChange}
  267. dataSource={datasource}
  268. rowKey={record => record.code}
  269. targetKeys={targetKeys}
  270. selectedKeys={selectedKeys}
  271. filterOption={(inputValue, item) => {
  272. return item.unitName!.indexOf(inputValue) !== -1
  273. }}
  274. >
  275. {({
  276. direction,
  277. filteredItems,
  278. onItemSelectAll,
  279. onItemSelect,
  280. selectedKeys: listSelectedKeys,
  281. disabled: listDisabled,
  282. }) => {
  283. // console.log({ filteredItems, listSelectedKeys,direction });
  284. const columns = direction === 'left' ? leftColumns : rightColumns;
  285. const rowSelection: TableRowSelection<TransferItem> = {
  286. getCheckboxProps: (item) => ({ disabled: listDisabled || item.disabled }),
  287. onSelectAll(selected, selectedRows) {
  288. const treeSelectedKeys = selectedRows.map(({ code }) => code);
  289. const diffKeys = selected
  290. ? difference(treeSelectedKeys, listSelectedKeys)
  291. : difference(listSelectedKeys, treeSelectedKeys);
  292. onItemSelectAll(diffKeys as string[], selected);
  293. },
  294. onSelect({ code }, selected) {
  295. onItemSelect(code as string, selected);
  296. },
  297. selectedRowKeys: listSelectedKeys,
  298. };
  299. return (
  300. <BMSTable
  301. rowSelection={rowSelection}
  302. columns={columns as TransferItem[]}
  303. dataSource={filteredItems}
  304. size="small"
  305. rowKey={'code'}
  306. tableAlertRender={false}
  307. pagination={{simple:true,pageSize:9,showTotal:()=>false}}
  308. locale={{ emptyText: '无数据' }}
  309. style={{ pointerEvents: listDisabled ? 'none' : undefined }}
  310. onRow={({ code, disabled: itemDisabled }) => ({
  311. onClick: () => {
  312. if (itemDisabled || listDisabled) return;
  313. onItemSelect(code as string, !listSelectedKeys.includes(code as string));
  314. },
  315. })}
  316. />
  317. );
  318. }}
  319. </Transfer>
  320. )
  321. })
  322. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' | 'INDICATOR' | 'UNIT' }) => {
  323. const [indicatorData, set_indicatorData] = useState<any[]>([]);
  324. const [indicatorIniData,set_indicatorIniData] = useState({});
  325. const formRef = useRef<ProFormInstance>();
  326. const triggerNode = () => {
  327. if (type == 'ADD') {
  328. return <span className='add'>新增</span>
  329. }
  330. if (type == 'EDIT') {
  331. return <a key="edit" >编辑</a>
  332. }
  333. if (type == 'INDICATOR') {
  334. return <a key="INDICATOR" >指标</a>
  335. }
  336. if (type == 'UNIT') {
  337. return <a key="UNIT" >单元</a>
  338. }
  339. }
  340. const title = () => {
  341. if (type == 'ADD') {
  342. return `新增指标分组`
  343. }
  344. if (type == 'EDIT') {
  345. return `编辑指标分组(${record.groupName})`
  346. }
  347. if (type == 'INDICATOR') {
  348. return `分组指标设置(${record.groupName})`
  349. }
  350. if (type == 'UNIT') {
  351. return `单元设置(${record.groupName})`
  352. }
  353. }
  354. const addIndicator = () => {
  355. const key = Math.random();
  356. const temp = [...indicatorData, {tempId:key,id:key,[`indicatorCode${key}`]:'',[`weight${key}`]:''}];
  357. set_indicatorIniData({...indicatorIniData,[`indicatorCode${key}`]:'',[`weight${key}`]:''});
  358. set_indicatorData([...temp]);
  359. }
  360. const delGroupIndic = (data:any,index:number)=>{
  361. let temp = [...indicatorData];
  362. let defaultFormData:{[key:string]:any} = {};
  363. const result = temp.filter((a:any)=>a.id != data.id);
  364. result.forEach((a:any)=>{
  365. defaultFormData[`indicatorCode${a.id}`] = a.indicatorCode;
  366. defaultFormData[`weight${a.id}`] = a.weight;
  367. });
  368. set_indicatorIniData({...defaultFormData});
  369. set_indicatorData([...result]);
  370. }
  371. useEffect(() => {
  372. if (type == 'INDICATOR') {
  373. let defaultFormData:{[key:string]:any} = {};
  374. if(record.indicatorWeights&&record.indicatorWeights.length>0){
  375. const _indicatorWeights = record.indicatorWeights.map((a:any)=>({...a,id:Math.random()}))
  376. const defaultVal = _indicatorWeights.map((a:any)=>{
  377. defaultFormData[`indicatorCode${a.id}`] = a.indicatorCode;
  378. defaultFormData[`weight${a.id}`] = a.weight;
  379. return {...a,tempId:Math.random()}
  380. });
  381. set_indicatorIniData({...defaultFormData});
  382. set_indicatorData([...defaultVal]);
  383. }else{
  384. set_indicatorData([{}]);
  385. }
  386. }
  387. }, [record]);
  388. // useEffect(() => {
  389. // console.log({'change':indicatorData });
  390. // }, [indicatorData]);
  391. return (
  392. <ModalForm
  393. title={title()}
  394. width={356}
  395. className='IndicGroupWeightSet-ModalForm'
  396. initialValues={type == 'EDIT'? { ...record } :type == 'INDICATOR'?{...indicatorIniData}:{}}
  397. formRef={formRef}
  398. trigger={
  399. triggerNode()
  400. }
  401. modalProps={{destroyOnClose:true}}
  402. onFinish={(val) => {
  403. if (type == 'ADD') {
  404. return updateTable({ ...val }, type)
  405. }
  406. if (type == 'EDIT') {
  407. return updateTable({ ...record, ...val }, type)
  408. }
  409. if (type == 'INDICATOR') {
  410. return updateTable({ id: record.id, indicatorWeights: indicatorData.map(a=>({...a,indicatorCode:`${a.indicatorCode}`})) }, type);
  411. }
  412. return Promise.resolve(true);
  413. // if (type == 'UNIT') {
  414. // return { id:record.id,indicatorWeights:indicatorData }
  415. // }
  416. }}
  417. >
  418. {
  419. (type == 'EDIT' || type == 'ADD') && (
  420. <>
  421. <ProFormText
  422. name="groupName"
  423. label="分组名称:"
  424. placeholder="请输入"
  425. fieldProps={{maxLength:8,showCount:true}}
  426. rules={[{ required: true, message: '名称不能为空!' }]}
  427. />
  428. <div style={{display:'flex',flexDirection:'row',width:'320px',justifyContent:'space-between'}}>
  429. <span>总分上下限:</span>
  430. <ProFormDigit name='floor' width={100} placeholder='总分下限' />
  431. <span>-</span>
  432. <ProFormDigit name='ceiling' width={100} placeholder='总分上限' />
  433. </div>
  434. <ProFormTextArea name={'depiction'} label='说明:' />
  435. </>
  436. )
  437. }
  438. {
  439. type == 'INDICATOR' && (
  440. <div>
  441. <div style={{maxHeight:442,overflowY:'scroll'}}>
  442. {
  443. indicatorData.map((item: any, index: number) => {
  444. return (
  445. <div className='item' key={index}>
  446. <ProFormSelect label="管理指标:" width={160}
  447. name={`indicatorCode${item.id}`}
  448. request={async () => {
  449. const resp = await getManaIndicListData({pageSize:500});
  450. if (resp) {
  451. return resp.list.map((a: any) => ({
  452. label: a.name,
  453. value: a.code
  454. }))
  455. }
  456. return []
  457. }}
  458. fieldProps={{
  459. // labelInValue:true,
  460. onChange(value, option:any) {
  461. // console.log({value,option});
  462. const temp = [...indicatorData];
  463. const newArr = temp.map((a:any)=>{
  464. if(a.id == item.id){
  465. return {...a, indicatorCode: value, indicatorName: option.label }
  466. }
  467. return a
  468. });
  469. set_indicatorData([...newArr]);
  470. },
  471. }}
  472. />
  473. <Form.Item name={`weight${item.id}`} label='权重(请输入小数):'>
  474. <InputNumber
  475. style={{width:120,height:24,position:'relative',top:0}}
  476. precision={4}
  477. onChange={(value)=>{
  478. //console.log({value,index,indicatorData});
  479. const temp = [...indicatorData];
  480. const newArr = temp.map((a:any)=>{
  481. if(a.id == item.id){
  482. return {...a,weight:value}
  483. }
  484. return a
  485. });
  486. set_indicatorData([...newArr]);
  487. }}
  488. />
  489. </Form.Item>
  490. {/* <ProFormText label='占比(请输入小数):' name={`weight${item.id}`} width={120} fieldProps={{
  491. onChange(value) {
  492. //console.log({value,index,indicatorData});
  493. const temp = [...indicatorData];
  494. const newArr = temp.map((a:any)=>{
  495. if(a.id == item.id){
  496. return {...a,weight:value}
  497. }
  498. return a
  499. });
  500. console.log({newArr});
  501. set_indicatorData([...newArr]);
  502. },
  503. }} /> */}
  504. <span className='delIcon' onClick={()=>delGroupIndic(item,index)}><IconFont type="iconshanchu" /></span>
  505. </div>
  506. )
  507. })
  508. }
  509. </div>
  510. <div className='addBtn' onClick={() => addIndicator()}>
  511. <AddIconFont type="icon-zengjia" style={{ color: '#3376FE' }} /><span>增加一行</span>
  512. </div>
  513. </div>
  514. )
  515. }
  516. </ModalForm>
  517. )
  518. }
  519. useEffect(() => {
  520. }, [])
  521. return (
  522. <BMSPagecontainer className='IndicGroupWeightSet' title={'指标分组权重设置'}>
  523. <div className='toolBar'>
  524. <div className='filter'>
  525. </div>
  526. <div className='btnGroup' style={{ position: 'absolute', right: 16, top: 16 }}>
  527. <UpDataActBtn record type='ADD' />
  528. </div>
  529. </div>
  530. <div style={{ marginTop: 16 }}>
  531. <BMSTable columns={columns as ProColumns[]} pagination={false} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  532. </div>
  533. </BMSPagecontainer>
  534. )
  535. }