setting.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2024-02-21 13:32:53
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-06-12 11:21:53
  6. * @FilePath: /CostAccountingSys/src/pages/costLibraryManagement/projectCostManagement/chargeItemsMana/components/setting.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import { KCIMTable } from '@/components/KCIMTable';
  10. import { ActionType, ModalForm, ProColumns, ProFormCascader, ProFormDigit, ProFormInstance, ProFormSelect, ProFormText } from '@ant-design/pro-components';
  11. import { Tabs } from 'antd';
  12. import { Key, useEffect, useRef, useState } from 'react';
  13. import { Popconfirm, message } from 'antd';
  14. import { addDrawerTableData, addDrugTableData, batchDelDrugTableData, delDrawerTableData, editDrawerTableData, getEmpsByItemCode, getEquipByItemCode, getNoValuationDrugByItemCode, getSpaceByItemCode, getValuationDrugByItemCode } from '../service';
  15. import { getSpaceCostTableData } from '@/pages/costLibraryManagement/basicCostManagement/spaceCostManagement/service';
  16. import { getEquipTableData } from '@/pages/costLibraryManagement/basicCostManagement/equipmentCostManagement/service';
  17. import { getLeftList } from '@/pages/costLibraryManagement/basicCostManagement/personnelClassificationMana/service';
  18. import TableSelecter from './tableSelector';
  19. import { fetchAllDepartments } from '..';
  20. const empColumns = [
  21. {
  22. title: '人员类别',
  23. dataIndex: 'empTypeCodeName',
  24. },
  25. {
  26. title: '数量',
  27. dataIndex: 'num'
  28. },
  29. {
  30. title: '执行时间(min)',
  31. dataIndex: 'executeTime',
  32. },
  33. ];
  34. const equipColumns = [
  35. {
  36. title: '设备编编码',
  37. dataIndex: 'equipmentCode',
  38. },
  39. {
  40. title: '设备名称',
  41. dataIndex: 'equipmentCodeName'
  42. },
  43. {
  44. title: '数量',
  45. dataIndex: 'num',
  46. },
  47. {
  48. title: '执行时间(m)',
  49. dataIndex: 'executeTime',
  50. },
  51. ]
  52. const spaceColumns = [
  53. {
  54. title: '空间编码',
  55. dataIndex: 'spaceCode',
  56. },
  57. {
  58. title: '空间名称',
  59. dataIndex: 'spaceCodeName'
  60. },
  61. {
  62. title: '数量',
  63. dataIndex: 'num',
  64. },
  65. {
  66. title: '执行时间(m)',
  67. dataIndex: 'executeTime',
  68. },
  69. ]
  70. export const Setting = (props: any) => {
  71. const { record, onVisibleChange } = props;
  72. const tableRef = useRef<ActionType>();
  73. const formRef = useRef<ProFormInstance>();
  74. const [columns, set_columns] = useState<any[]>([]);
  75. const [currentTabKey, set_currentTabKey] = useState('1');
  76. const [dataSource, set_dataSource] = useState([]);
  77. const [selectedKeys, setSelectedKeys] = useState<React.Key[]>([]);
  78. const [selectedRows, set_selectedRows] = useState<any[]>([]);
  79. const [tableSelecterVisible, set_tableSelecterVisible] = useState(false);
  80. const [currentEditRow,set_currentEditRow] = useState<any>(undefined);
  81. const valuationColumns = [
  82. {
  83. title: '项目类别',
  84. width: 85,
  85. dataIndex: 'typeName',
  86. },
  87. {
  88. title: '项目代码',
  89. width: 85,
  90. dataIndex: 'code'
  91. },
  92. {
  93. title: '项目名称',
  94. dataIndex: 'name',
  95. },
  96. {
  97. title: '数量',
  98. dataIndex: 'num',
  99. width: 120,
  100. renderText(num:any, record:any) {
  101. return (
  102. <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  103. {
  104. (currentEditRow && currentEditRow.id == record.id) && (
  105. <>
  106. <ProFormDigit
  107. width={80}
  108. noStyle
  109. fieldProps={{
  110. value: num,
  111. onChange(value) {
  112. set_currentEditRow({ ...record,num:value});
  113. },
  114. }}
  115. />
  116. <img onClick={() => updateTable({ ...record,...currentEditRow }, 'EDIT',Number(currentTabKey))} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../../static/confirmIcon.png')} />
  117. </>
  118. )
  119. }
  120. {
  121. (!currentEditRow || (currentEditRow&&currentEditRow.id != record.id)) && (
  122. <>
  123. <div>{num}</div>
  124. <img onClick={() => {set_currentEditRow(record);}} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../../static/editIcon.png')} />
  125. </>
  126. )
  127. }
  128. </div>
  129. )
  130. },
  131. },
  132. ]
  133. const columnsData = (key: number) => [
  134. {
  135. title: '操作',
  136. key: 'option',
  137. width: 160,
  138. valueType: 'option',
  139. render: (_: any, record: any) => {
  140. return [
  141. <UpDataActBtn key={'act'} record={record} type='EDIT' currentTabKey={key} />,
  142. <Popconfirm
  143. title="是否确认删除?"
  144. key="del"
  145. onConfirm={() => delTableData(record)}
  146. >
  147. <a>删除</a>
  148. </Popconfirm>,
  149. ]
  150. },
  151. },
  152. ];
  153. const getTableData = async (tabCode: string) => {
  154. let resp = undefined;
  155. if (tabCode == '1') {
  156. resp = await getEmpsByItemCode(record.code,record.departmentCode);
  157. }
  158. if (tabCode == '2') {
  159. resp = await getEquipByItemCode(record.code,record.departmentCode);
  160. }
  161. if (tabCode == '3') {
  162. resp = await getSpaceByItemCode(record.code,record.departmentCode);
  163. }
  164. if (tabCode == '4') {
  165. resp = await getValuationDrugByItemCode(record.code,record.departmentCode);
  166. }
  167. if (tabCode == '5') {
  168. resp = await getNoValuationDrugByItemCode(record.code,record.departmentCode);
  169. }
  170. set_dataSource(resp);
  171. }
  172. const delTableData = async (record: any) => {
  173. const resp = await delDrawerTableData(record.id, Number(currentTabKey));
  174. if (resp) {
  175. message.success('操作成功!');
  176. //tableRef.current?.reload();
  177. getTableData(`${currentTabKey}`);
  178. // message.success('操作成功!');
  179. }
  180. }
  181. const updateTable = async (formVal: any, type: 'EDIT' | "ADD", currentTabKey: number) => {
  182. let result = undefined;
  183. if (type == 'ADD') {
  184. if (currentTabKey == 1) {
  185. result = {
  186. itemCode: record.code,
  187. empTypeCode: formVal.empType.value,
  188. empTypeCodeName: formVal.empType.label,
  189. num: formVal.num,
  190. executeTime: formVal.executeTime
  191. }
  192. }
  193. if (currentTabKey == 2) {
  194. result = {
  195. itemCode: record.code,
  196. equipmentCode: formVal.equipmentCode,
  197. num: formVal.num,
  198. executeTime: formVal.executeTime
  199. }
  200. }
  201. if (currentTabKey == 3) {
  202. result = {
  203. itemCode: record.code,
  204. spaceCode: formVal.space[formVal.space.length - 1],
  205. num: formVal.num,
  206. spaceCodePath: formVal.spaceCodePath,
  207. executeTime: formVal.executeTime
  208. }
  209. }
  210. const resp = await addDrawerTableData({...result,departmentCode:formVal.departmentCode}, currentTabKey as number);
  211. if (resp) {
  212. //tableRef.current?.reload();
  213. getTableData(`${currentTabKey}`);
  214. message.success('操作成功!');
  215. }
  216. }
  217. if (type == 'EDIT') {
  218. try {
  219. if (currentTabKey == 1) {
  220. result = {
  221. itemCode: record.code,
  222. empTypeCode: formVal.empType.value,
  223. empTypeCodeName: formVal.empType.label,
  224. num: formVal.num,
  225. executeTime: formVal.executeTime
  226. }
  227. }
  228. if (currentTabKey == 2) {
  229. result = {
  230. itemCode: record.code,
  231. equipmentCode: formVal.equipmentCode,
  232. num: formVal.num,
  233. executeTime: formVal.executeTime
  234. }
  235. }
  236. if (currentTabKey == 3) {
  237. result = {
  238. itemCode: record.code,
  239. spaceCode: formVal.spaceCode,
  240. num: formVal.num,
  241. spaceCodePath: formVal.spaceCodePath,
  242. executeTime: formVal.executeTime
  243. }
  244. }
  245. if (currentTabKey == 4||currentTabKey == 5) {
  246. result = {
  247. ...currentEditRow,
  248. }
  249. }
  250. const resp = await editDrawerTableData({ ...result, id: formVal.id,departmentCode:formVal.departmentCode }, currentTabKey);
  251. if (resp) {
  252. //tableRef.current?.reload();
  253. getTableData(`${currentTabKey}`);
  254. message.success('操作成功!');
  255. }
  256. set_currentEditRow(undefined);
  257. } catch (error) {
  258. console.log('编辑保存:', error)
  259. }
  260. }
  261. return true;
  262. }
  263. const UpDataActBtn = ({ record, type, currentTabKey }: { record: any, type: 'EDIT' | 'ADD', currentTabKey: number }) => {
  264. const [cascaderData, set_cascaderData] = useState<any[]>([]);
  265. return (
  266. <ModalForm
  267. title={`${type == 'EDIT' ? '编辑' : '新增'}${currentTabKey == 1 ? '参与人员' : currentTabKey == 2 ? '使用设备' : '使用空间'}`}
  268. width={350}
  269. formRef={formRef}
  270. initialValues={type == 'EDIT' ? {
  271. ...record, empType: record.empTypeCode, space: record.spaceCodePath ? record.spaceCodePath.split(',') : []
  272. } : { kcClassCode: '', kcClassName: '', kcClassPath: '', executeTime: record.executeTime }}
  273. trigger={
  274. type == 'EDIT' ? <a key="edit" >编辑</a> : <a className='add'>新增</a>
  275. }
  276. onFinish={(val) => {
  277. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type, currentTabKey);
  278. }}
  279. modalProps={{ destroyOnClose: true }}
  280. colProps={{ span: 24 }}
  281. grid
  282. >
  283. <ProFormSelect
  284. name="departmentCode"
  285. label="科室:"
  286. placeholder="请输入"
  287. request={fetchAllDepartments}
  288. fieldProps={{labelInValue:false}}
  289. rules={[{ required: false, message: '科室不能为空!' }]}
  290. />
  291. {
  292. currentTabKey == 1 && (
  293. <ProFormSelect
  294. name="empType"
  295. label="人员类别:"
  296. placeholder="请选择"
  297. showSearch
  298. fieldProps={{ labelInValue: true }}
  299. request={async () => {
  300. const resp = await getLeftList();
  301. if (resp) {
  302. return resp.map((a: any) => ({ label: a.costTypeName, value: a.costTypeCode }))
  303. } else {
  304. return []
  305. }
  306. }}
  307. rules={[{ required: true, message: '人员类别不能为空!' }]}
  308. />
  309. )
  310. }
  311. {
  312. currentTabKey == 2 && (
  313. <ProFormSelect
  314. name="equipmentCode"
  315. label="设备名称:"
  316. placeholder="请选择"
  317. showSearch
  318. request={async ({ keyWords }) => {
  319. const resp = await getEquipTableData({ name: keyWords, pageSize: 500, current: 1 });
  320. if (resp) {
  321. return resp.list.map((a: any) => ({ label: a.name, value: a.code }))
  322. } else {
  323. return []
  324. }
  325. }}
  326. rules={[{ required: true, message: '设备名称不能为空!' }]}
  327. />
  328. )
  329. }
  330. {
  331. currentTabKey == 3 && (
  332. <>
  333. <ProFormText name='spaceCodePath' hidden />
  334. <ProFormText name='spaceCode' hidden />
  335. <ProFormCascader
  336. name="space"
  337. label="空间名称:"
  338. rules={[{ required: true, message: '空间名称不能为空!' }]}
  339. request={async () => {
  340. const resp = await getSpaceCostTableData();
  341. if (resp) {
  342. set_cascaderData(resp);
  343. return resp
  344. }
  345. }}
  346. fieldProps={{
  347. fieldNames: { label: 'name', value: 'code', children: 'childList' },
  348. onChange: async (value: any) => {
  349. // const a = findAllParents(cascaderData, value[value.length - 1]);
  350. // console.log({a});
  351. if (value.length > 0) {
  352. formRef.current?.setFieldsValue({
  353. spaceCodePath: value.join(','),
  354. spaceCode: value[value.length - 1]
  355. })
  356. }
  357. }
  358. }}
  359. />
  360. </>
  361. )
  362. }
  363. <ProFormDigit
  364. name="num"
  365. label="数量:"
  366. placeholder="请输入"
  367. rules={[{ required: true, message: '数量不能为空!' }]}
  368. />
  369. <ProFormDigit
  370. name="executeTime"
  371. label="执行时间(min):"
  372. placeholder="请输入"
  373. rules={[{ required: true, message: '执行时间不能为空!' }]}
  374. />
  375. </ModalForm>
  376. )
  377. }
  378. const tableSelecterCommit = async (keys: Key[], rows: any[]) => {
  379. // console.log({keys,rows});
  380. set_tableSelecterVisible(false);
  381. const result = {
  382. itemCode: record.code,
  383. items: rows
  384. }
  385. const resp = await addDrugTableData(result, Number(currentTabKey));
  386. if (resp) {
  387. getTableData(`${currentTabKey}`);
  388. }
  389. }
  390. const onSelectChange = (newSelectedRowKeys: React.Key[], selectedRows: any) => {
  391. setSelectedKeys([...newSelectedRowKeys]);
  392. set_selectedRows([...selectedRows]);
  393. };
  394. const batchDelTableData = async () => {
  395. const resp = await batchDelDrugTableData(selectedRows.map((a) => a.id), Number(currentTabKey));
  396. if (resp) {
  397. getTableData(`${currentTabKey}`);
  398. setSelectedKeys([]);
  399. set_selectedRows([]);
  400. }
  401. }
  402. useEffect(() => {
  403. getTableData(currentTabKey);
  404. set_currentEditRow(undefined);
  405. if (currentTabKey == '1') {
  406. set_columns([...empColumns, ...columnsData(Number(currentTabKey))])
  407. }
  408. if (currentTabKey == '2') {
  409. set_columns([...equipColumns, ...columnsData(Number(currentTabKey))])
  410. }
  411. if (currentTabKey == '3') {
  412. set_columns([...spaceColumns, ...columnsData(Number(currentTabKey))])
  413. }
  414. if (currentTabKey == '4') {
  415. set_columns([...valuationColumns, {
  416. title: '操作',
  417. key: 'option',
  418. width: 80,
  419. valueType: 'option',
  420. render: (_: any, record: any) => {
  421. return [
  422. <Popconfirm
  423. title="是否确认删除?"
  424. key="del"
  425. onConfirm={() => delTableData(record)}
  426. >
  427. <a>删除</a>
  428. </Popconfirm>,
  429. ]
  430. },
  431. },])
  432. }
  433. if (currentTabKey == '5') {
  434. set_columns([...valuationColumns, {
  435. title: '操作',
  436. key: 'option',
  437. width: 80,
  438. valueType: 'option',
  439. render: (_: any, record: any) => {
  440. return [
  441. <Popconfirm
  442. title="是否确认删除?"
  443. key="del"
  444. onConfirm={() => delTableData(record)}
  445. >
  446. <a>删除</a>
  447. </Popconfirm>,
  448. ]
  449. },
  450. }])
  451. }
  452. setSelectedKeys([]);
  453. set_selectedRows([]);
  454. }, [currentTabKey]);
  455. useEffect(()=>{
  456. if(currentTabKey == '4'||currentTabKey == '5')
  457. set_columns([...valuationColumns, {
  458. title: '操作',
  459. key: 'option',
  460. width: 80,
  461. valueType: 'option',
  462. render: (_: any, record: any) => {
  463. return [
  464. <Popconfirm
  465. title="是否确认删除?"
  466. key="del"
  467. onConfirm={() => delTableData(record)}
  468. >
  469. <a>删除</a>
  470. </Popconfirm>,
  471. ]
  472. },
  473. }])
  474. },[currentEditRow])
  475. return (
  476. <div className="settingDrawer">
  477. <TableSelecter
  478. onVisibleChange={(bool) => set_tableSelecterVisible(bool)}
  479. title='添加'
  480. rowKey={'code'}
  481. defaultSelectedKeys={dataSource.map((a: any) => a.code)}
  482. record={record}
  483. open={tableSelecterVisible}
  484. onFinish={(keys, rows) => tableSelecterCommit(keys, rows)}
  485. />
  486. <div className="header">
  487. <div className="title">{record?record.standItemName:'项目'}</div>
  488. <div className="btnGroup">
  489. <a className="back" onClick={() => onVisibleChange(false)}>返回</a>
  490. {(currentTabKey != '4' && currentTabKey != '5') && <UpDataActBtn key={'act'} record={record} type='ADD' currentTabKey={Number(currentTabKey)} />}
  491. {(currentTabKey == '4' || currentTabKey == '5') && <a className='add' onClick={() => set_tableSelecterVisible(true)}>添加</a>}
  492. </div>
  493. </div>
  494. <div style={{ padding: '0 16px' }}>
  495. <Tabs
  496. defaultActiveKey={`${currentTabKey}`}
  497. onChange={(key) => set_currentTabKey(key)}
  498. items={[
  499. {
  500. label: '参与人员',
  501. key: '1'
  502. },
  503. {
  504. label: '使用设备',
  505. key: '2'
  506. },
  507. {
  508. label: '使用空间',
  509. key: '3',
  510. },
  511. {
  512. label: '计价药材',
  513. key: '4',
  514. },
  515. {
  516. label: '不计价药材',
  517. key: '5',
  518. },
  519. ]}
  520. />
  521. <KCIMTable
  522. rowSelection={(currentTabKey == '4' || currentTabKey == '5') ? {
  523. alwaysShowAlert: false,
  524. selectedRowKeys: selectedKeys,
  525. onChange: onSelectChange,
  526. } : false}
  527. tableAlertRender={false}
  528. columns={[{
  529. title: '科室',
  530. width:120,
  531. dataIndex: 'departmentName',
  532. },...columns]}
  533. actionRef={tableRef} rowKey='id'
  534. dataSource={dataSource}
  535. />
  536. </div>
  537. {
  538. selectedKeys.length > 0 && (
  539. <div className='footer'>
  540. <div className='count'>{`已选择${selectedKeys.length}`}</div>
  541. <div className='btngroup'>
  542. <a className='cancel' onClick={() => { setSelectedKeys([]); set_selectedRows([]) }}>取消</a>
  543. <a className='confirm' onClick={() => batchDelTableData()}>批量删除</a>
  544. </div>
  545. </div>
  546. )
  547. }
  548. </div>
  549. )
  550. }