index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-05-18 17:56:28
  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 { getPubDicData } from '@/services/getDic';
  12. import { createFromIconfontCN } from '@ant-design/icons';
  13. import { ActionType, ProFormRadio } from '@ant-design/pro-components';
  14. import { ModalForm, ProFormCheckbox, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  15. import { ProColumns } from '@ant-design/pro-table';
  16. import { Input, message, Popconfirm, Tabs } from 'antd';
  17. import { useEffect, useRef, useState } from 'react'
  18. import { addCostData, addIncomeData, delData, editCostData, editIncomeData, getCostIncomeProjectTable, getCostProjectTable } from './service';
  19. import './style.less';
  20. const IconFont = createFromIconfontCN({
  21. scriptUrl: '//at.alicdn.com/t/c/font_1927152_4nm5kxbv4m3.js',
  22. });
  23. export default function CostIncomeProjectSet() {
  24. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  25. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  26. const tableRef = useRef<ActionType>();
  27. const [columns, set_columns] = useState<ProColumns[]>([]);
  28. const [currentSelectedTabKey, set_currentSelectedTabKey] = useState<string>('1');
  29. const incomeColumns: ProColumns[] = [
  30. {
  31. title: '项目代码',
  32. dataIndex: 'code',
  33. },
  34. {
  35. title: '项目名称',
  36. dataIndex: 'name',
  37. },
  38. {
  39. title: '适应范围',
  40. dataIndex: 'scope',
  41. renderText(num, record, index, action) {
  42. return `${record.opdFlag == 1 ? record.opdFlagName : ''}${(record.opdFlag ==1&&record.inpFlag==1)?' | ':''}${record.inpFlag == 1?record.inpFlagName : ''}`
  43. },
  44. },
  45. {
  46. title: '统计',
  47. dataIndex: 'statFlag',
  48. renderText(num, record, index, action) {
  49. return record.statFlag ? '是' : '否'
  50. },
  51. },
  52. {
  53. title: '序号',
  54. dataIndex: 'seqNo',
  55. },
  56. {
  57. title: '操作',
  58. key: 'option',
  59. width: 120,
  60. valueType: 'option',
  61. render: (_: any, record: any) => {
  62. return [
  63. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  64. <Popconfirm
  65. title="是否确认删除?"
  66. key="del"
  67. onConfirm={() => delTableData(record)}
  68. >
  69. <a>删除</a>
  70. </Popconfirm>
  71. ]
  72. },
  73. },
  74. ]
  75. const costCloumns: ProColumns[] = [
  76. {
  77. title: '项目名称',
  78. dataIndex: 'name',
  79. },
  80. {
  81. title: '类型',
  82. dataIndex: 'itemTypeName',
  83. },
  84. {
  85. title: '汇总',
  86. dataIndex: 'summaryFlag',
  87. renderText(num, record, index, action) {
  88. return record.summaryFlag ? '是' : '否'
  89. },
  90. },
  91. {
  92. title: '可控',
  93. dataIndex: 'ctrlFlag',
  94. renderText(num, record, index, action) {
  95. return record.ctrlFlag ? '是' : '否'
  96. },
  97. },
  98. {
  99. title: '统计',
  100. dataIndex: 'statFlag',
  101. renderText(num, record, index, action) {
  102. return record.statFlag ? '是' : '否'
  103. },
  104. },
  105. {
  106. title: '序号',
  107. dataIndex: 'seqNo',
  108. },
  109. {
  110. title: '操作',
  111. key: 'option',
  112. width: 160,
  113. valueType: 'option',
  114. render: (_: any, record: any) => {
  115. return record.summaryFlag ? [
  116. <UpDataActBtn key={'add'} type='ADD' text='添加' record={record} />,
  117. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  118. <Popconfirm
  119. title="是否确认删除?"
  120. key="del"
  121. onConfirm={() => delTableData(record)}
  122. >
  123. <a>删除</a>
  124. </Popconfirm>
  125. ] : [
  126. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  127. <Popconfirm
  128. title="是否确认删除?"
  129. key="del"
  130. onConfirm={() => delTableData(record)}
  131. >
  132. <a>删除</a>
  133. </Popconfirm>
  134. ]
  135. },
  136. },
  137. ]
  138. const getTableData = async (params: any) => {
  139. if (currentSelectedTabKey == '1') {
  140. const resp = await getCostIncomeProjectTable(params);
  141. if (resp) {
  142. return {
  143. data: resp.list,
  144. success: true,
  145. total: resp.totalCount,
  146. pageSize: resp.pageSize,
  147. totalPage: resp.totalPage,
  148. }
  149. }
  150. }
  151. if (currentSelectedTabKey == '2') {
  152. const resp = await getCostProjectTable(params);
  153. if (resp) {
  154. return {
  155. data: resp,
  156. success: true,
  157. }
  158. }
  159. }
  160. return []
  161. }
  162. const delTableData = async (record: any) => {
  163. const resp = await delData(record.id,currentSelectedTabKey);
  164. if (resp) {
  165. message.success('操作成功!');
  166. tableRef.current?.reload();
  167. // message.success('操作成功!');
  168. }
  169. }
  170. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  171. console.log({ formVal });
  172. if(currentSelectedTabKey == '1'){
  173. const result = {
  174. name: formVal.name,
  175. opdFlag: formVal.scope.includes('门诊') ? 1 : 0,
  176. inpFlag: formVal.scope.includes('住院') ? 1 : 0,
  177. statFlag: formVal.statFlag,
  178. seqNo: formVal.seqNo
  179. }
  180. if (type == 'ADD') {
  181. const resp = await addIncomeData({ ...result });
  182. if (resp) {
  183. tableRef.current?.reload();
  184. message.success('操作成功!');
  185. }
  186. }
  187. if (type == 'EDIT') {
  188. const resp = await editIncomeData({ id: formVal.id, ...result });
  189. if (resp) {
  190. tableRef.current?.reload();
  191. message.success('操作成功!');
  192. }
  193. }
  194. }
  195. if(currentSelectedTabKey == '2'){
  196. const result = {
  197. name: formVal.name,
  198. parentCode: formVal.parentCode,
  199. itemType: formVal.itemType,
  200. summaryFlag: formVal.summaryFlag,
  201. ctrlFlag: formVal.ctrlFlag,
  202. statFlag: formVal.statFlag,
  203. seqNo: formVal.seqNo
  204. }
  205. if (type == 'ADD') {
  206. const resp = await addCostData({ ...result });
  207. if (resp) {
  208. tableRef.current?.reload();
  209. message.success('操作成功!');
  210. }
  211. }
  212. if (type == 'EDIT') {
  213. const resp = await editCostData({ id: formVal.id, ...result });
  214. if (resp) {
  215. tableRef.current?.reload();
  216. message.success('操作成功!');
  217. }
  218. }
  219. }
  220. return true;
  221. }
  222. const [dicData, set_dicData] = useState<any[]>([]);
  223. const getDirecData = async (key?: string) => {
  224. const data = await getPubDicData();
  225. if (data) {
  226. set_dicData(data);
  227. }
  228. }
  229. const UpDataActBtn = ({ record, type, text }: { record: any, type: 'EDIT' | 'ADD', text?: string }) => {
  230. let scope = [];
  231. if (record.opdFlag) { scope.push('门诊') }
  232. if (record.inpFlag) { scope.push('住院') }
  233. return (
  234. <ModalForm
  235. title={`${type == 'EDIT' ? '编辑' : '新增'}${currentSelectedTabKey == '1' ? '收入项目' : '成本项目'}`}
  236. width={352}
  237. initialValues={type == 'EDIT' ? { ...record, scope: scope } : {}}
  238. trigger={
  239. type == 'EDIT' ? <a key="edit" >编辑</a> : <a className='add'>{text ? text : '新增'}</a>
  240. }
  241. onFinish={(val) => {
  242. return updateTable(type == 'EDIT' ? { ...record, ...val,parentCode:record.parentCode} : { ...val,parentCode:record.code?record.code:0 }, type);
  243. }}
  244. modalProps={{ destroyOnClose: true }}
  245. colProps={{ span: 24 }}
  246. grid
  247. >
  248. {
  249. currentSelectedTabKey == '1' && (
  250. <>
  251. <ProFormText
  252. name="name"
  253. label="项目名称:"
  254. placeholder="请输入"
  255. rules={[{ required: true, message: '名称不能为空!' }]}
  256. />
  257. <ProFormCheckbox.Group
  258. name="scope"
  259. label="适应范围:"
  260. options={['门诊', '住院']}
  261. rules={[{ required: true, message: '适应范围不能为空!' }]}
  262. />
  263. <ProFormRadio.Group
  264. name="statFlag"
  265. label="统计:"
  266. options={[
  267. {
  268. label: '是',
  269. value: 1,
  270. },
  271. {
  272. label: '否',
  273. value: 0,
  274. }
  275. ]}
  276. placeholder="请选择"
  277. />
  278. <ProFormDigit
  279. name="seqNo"
  280. label="序号:"
  281. rules={[{ required: true, message: '序号不能为空!' }]}
  282. />
  283. </>
  284. )
  285. }
  286. {
  287. currentSelectedTabKey == '2'&&(
  288. <>
  289. <ProFormText
  290. name="name"
  291. label="项目名称:"
  292. placeholder="请输入"
  293. rules={[{ required: true, message: '名称不能为空!' }]}
  294. />
  295. <ProFormSelect
  296. name="itemType"
  297. label="类型:"
  298. placeholder="请选择"
  299. options={[
  300. {
  301. label:'人事成本',value:1
  302. },
  303. {
  304. label:'变动成本',value:2
  305. },
  306. {
  307. label:'固定成本',value:3
  308. }
  309. ]}
  310. rules={[{ required: true, message: '类型不能为空!' }]}
  311. />
  312. <ProFormRadio.Group
  313. name="summaryFlag"
  314. label="汇总:"
  315. options={[
  316. {
  317. label: '是',
  318. value: 1,
  319. },
  320. {
  321. label: '否',
  322. value: 0,
  323. }
  324. ]}
  325. placeholder="请选择"
  326. />
  327. <ProFormRadio.Group
  328. name="ctrlFlag"
  329. label="可控:"
  330. options={[
  331. {
  332. label: '是',
  333. value: 1,
  334. },
  335. {
  336. label: '否',
  337. value: 0,
  338. }
  339. ]}
  340. placeholder="请选择"
  341. />
  342. <ProFormRadio.Group
  343. name="statFlag"
  344. label="统计:"
  345. options={[
  346. {
  347. label: '是',
  348. value: 1,
  349. },
  350. {
  351. label: '否',
  352. value: 0,
  353. }
  354. ]}
  355. placeholder="请选择"
  356. />
  357. <ProFormDigit
  358. name="seqNo"
  359. label="序号:"
  360. rules={[{ required: true, message: '序号不能为空!' }]}
  361. />
  362. </>
  363. )
  364. }
  365. </ModalForm>
  366. )
  367. }
  368. const tableDataSearchHandle = (paramName: string) => {
  369. set_tableDataFilterParams({
  370. ...tableDataFilterParams,
  371. [`${paramName}`]: tableDataSearchKeywords
  372. })
  373. }
  374. const onTabChange = (activeKey: string) => {
  375. set_currentSelectedTabKey(activeKey);
  376. }
  377. useEffect(() => {
  378. tableRef.current?.reload();
  379. if (currentSelectedTabKey == '1') {
  380. set_columns(incomeColumns)
  381. }
  382. if (currentSelectedTabKey == '2') {
  383. set_columns(costCloumns)
  384. }
  385. }, [currentSelectedTabKey])
  386. useEffect(() => {
  387. getDirecData();
  388. }, [])
  389. return (
  390. <BMSPagecontainer className='CostIncomeProjectSet' title={false}>
  391. <Tabs
  392. defaultActiveKey="1"
  393. onChange={onTabChange}
  394. items={[
  395. {
  396. label: `收入项目`,
  397. key: '1',
  398. },
  399. {
  400. label: `成本项目`,
  401. key: '2',
  402. },
  403. ]}
  404. />
  405. <div className='toolBar'>
  406. <div className='filter'>
  407. <div className='filterItem'>
  408. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  409. <Input placeholder={'请输入项目名称'} allowClear
  410. suffix={
  411. <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('name')} />
  412. }
  413. onChange={(e) => {
  414. set_tableDataSearchKeywords(e.target.value);
  415. if (e.target.value.length == 0) {
  416. set_tableDataFilterParams({
  417. ...tableDataFilterParams,
  418. name: ''
  419. });
  420. }
  421. }}
  422. onPressEnter={(e) => {
  423. set_tableDataFilterParams({
  424. ...tableDataFilterParams,
  425. name: (e.target as HTMLInputElement).value
  426. });
  427. }}
  428. />
  429. </div>
  430. </div>
  431. <div className='btnGroup'>
  432. {/* <span className='getDataBtn' onClick={() => getDataBySQL()}>获取</span> */}
  433. <UpDataActBtn record type='ADD' />
  434. </div>
  435. </div>
  436. <div style={{ marginTop: 16 }}>
  437. <BMSTable columns={columns as ProColumns[]} pagination={currentSelectedTabKey == '2'&&false} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  438. </div>
  439. </BMSPagecontainer>
  440. )
  441. }