index.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-06-12 17:45:12
  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 KCIMPagecontainer from '@/components/KCIMPageContainer';
  10. import { KCIMTable } from '@/components/KCIMTable';
  11. import { createFromIconfontCN } from '@ant-design/icons';
  12. import { ActionType, ProFormDependency, ProFormInstance, ProFormText, ProFormSelect, ProFormTextArea, ProFormTreeSelect } from '@ant-design/pro-components';
  13. import { ModalForm, ProFormCascader } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Input, message, Popconfirm, Tag, Tabs } from 'antd';
  16. import { Key, ReactNode, useEffect, useRef, useState } from 'react';
  17. import 'moment/locale/zh-cn';
  18. import locale from 'antd/es/date-picker/locale/zh_CN';
  19. import { addData, copyParamsList, delData, editData, getProfitReportType, getProjectCostShareTableData, getResponsibilityCenterSelecterList, saveParamsList } from './service';
  20. import './style.less';
  21. import { getChilds } from '@/utils/tooljs';
  22. import EditTableModal from './editTableModal';
  23. import TableSelecter from './tableSelector';
  24. import { getDicDataBySysId } from '@/services/getDic';
  25. import { getReportProjectSettingList } from '@/pages/baseSetting/otherItemSet/reportItemSet/service';
  26. import { KcimCenterSysId } from '@/constant';
  27. const IconFont = createFromIconfontCN({
  28. scriptUrl: '',
  29. });
  30. export default function AllocationParamsMap() {
  31. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>(undefined);
  32. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  33. const tableRef = useRef<ActionType>();
  34. const formRef = useRef<ProFormInstance>();
  35. const [currentRow, setCurrentRow] = useState<any | undefined>(undefined);
  36. const [editTableVisible, set_editTableVisible] = useState(false);
  37. const [tableSelecterVisible, set_tableSelecterVisible] = useState(false);
  38. const columns: ProColumns[] = [
  39. {
  40. title: '项目分类',
  41. ellipsis: true,
  42. width: 100,
  43. dataIndex: 'itemTypeName',
  44. },
  45. {
  46. title: '成本列代码',
  47. ellipsis: true,
  48. width: 100,
  49. dataIndex: 'columnCode',
  50. },
  51. {
  52. title: '成本列名称',
  53. ellipsis: true,
  54. width: 150,
  55. dataIndex: 'columnName',
  56. },
  57. {
  58. title: '成本列类型',
  59. ellipsis: true,
  60. width: 100,
  61. dataIndex: 'columnTypeName',
  62. },
  63. {
  64. title: '损益表类型',
  65. ellipsis: true,
  66. dataIndex: 'reportTypeName',
  67. },
  68. {
  69. title: '损益表项目',
  70. ellipsis: true,
  71. dataIndex: 'profitPathName',
  72. },
  73. {
  74. title: '分摊参数',
  75. ellipsis: true,
  76. width: 200,
  77. dataIndex: 'shareParamCostDetails',
  78. renderText(arr, record) {
  79. if (arr) {
  80. return arr.reduce((prev: string, cur: any) => `${prev.length > 0 ? prev + '|' : prev}${cur.shareParamName}`, '')
  81. }
  82. },
  83. },
  84. {
  85. title: '操作',
  86. key: 'option',
  87. width: 160,
  88. fixed: 'right',
  89. valueType: 'option',
  90. render: (_: any, record: any) => {
  91. return [
  92. <a key='share' onClick={() => { set_editTableVisible(true); setCurrentRow(record) }}>分摊参数</a>,
  93. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  94. <Popconfirm
  95. title="是否确认删除?"
  96. key="del"
  97. onConfirm={() => delTableData(record)}
  98. >
  99. <a>删除</a>
  100. </Popconfirm>,
  101. ]
  102. },
  103. },
  104. ]
  105. const getTableData = async (params: any) => {
  106. const resp = await getProjectCostShareTableData({ ...params });
  107. if (resp) {
  108. return {
  109. data: resp,
  110. success: true,
  111. }
  112. }
  113. return []
  114. }
  115. const tableDataSearchHandle = (paramName: string) => {
  116. set_tableDataFilterParams({
  117. ...tableDataFilterParams,
  118. [`${paramName}`]: tableDataSearchKeywords
  119. })
  120. }
  121. const delTableData = async (record: any) => {
  122. const resp = await delData(record.id);
  123. if (resp) {
  124. message.success('操作成功!');
  125. tableRef.current?.reload();
  126. // message.success('操作成功!');
  127. }
  128. }
  129. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  130. try {
  131. const result = {
  132. columnCode: formVal.columnCode,
  133. columnName: formVal.columnName,
  134. columnType: formVal.columnType,
  135. columnTypeName: formVal.columnTypeName,
  136. profitId: formVal.profitId[formVal.profitId.length - 1],
  137. profitNum: formVal.profitNum,
  138. profitName: formVal.profitName,
  139. profitPath: formVal.profitPath,
  140. profitPathName: formVal.profitPathName,
  141. itemType:formVal.itemType,
  142. reportType:formVal.reportType,
  143. };
  144. if (type == 'ADD') {
  145. const resp = await addData(result);
  146. if (resp) {
  147. tableRef.current?.reload();
  148. message.success('操作成功!');
  149. }
  150. }
  151. if (type == 'EDIT') {
  152. const resp = await editData({ ...result, id: formVal.id });
  153. if (resp) {
  154. tableRef.current?.reload();
  155. message.success('操作成功!');
  156. }
  157. }
  158. } catch (error) {
  159. console.log({ error });
  160. }
  161. return true;
  162. }
  163. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  164. return (
  165. <ModalForm
  166. title={`${type == 'EDIT' ? '编辑' : '新增'}项目分摊参数对应`}
  167. width={350}
  168. formRef={formRef}
  169. initialValues={type == 'EDIT' ? {
  170. ...record,
  171. profitId: (record.profitPath) ? ((record.profitPath).split(',')).map((a: string) => Number(a)) : []
  172. } : {}}
  173. trigger={
  174. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  175. }
  176. onFinish={(val) => {
  177. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type);
  178. }}
  179. modalProps={{ destroyOnClose: true }}
  180. colProps={{ span: 24 }}
  181. grid
  182. >
  183. <ProFormText name='columnTypeName' hidden />
  184. <ProFormText name='profitNum' hidden />
  185. <ProFormText name='profitName' hidden />
  186. <ProFormText name='profitPath' hidden />
  187. <ProFormText name='profitPathName' hidden />
  188. <ProFormSelect
  189. name="itemType"
  190. label="项目分类:"
  191. placeholder="请输入"
  192. request={async () => {
  193. const resp = await getDicDataBySysId(KcimCenterSysId, 'MED_SERVICE_ITEM_TYPE');
  194. if (resp) {
  195. const { dataVoList = [] } = resp;
  196. return dataVoList.map((a: any) => ({ label: a.name, value: a.code }))
  197. }
  198. return []
  199. }}
  200. rules={[{ required: true, message: '项目分类不能为空!' }]}
  201. />
  202. <ProFormText
  203. name="columnCode"
  204. label="成本列代码:"
  205. placeholder="请输入"
  206. rules={[{ required: true, message: '成本列代码不能为空!' }]}
  207. />
  208. <ProFormText
  209. name="columnName"
  210. label="成本列名称:"
  211. placeholder="请输入"
  212. rules={[{ required: true, message: '成本列名称不能为空!' }]}
  213. />
  214. <ProFormSelect
  215. rules={[
  216. {
  217. required: true,
  218. message: '请选择',
  219. },
  220. ]}
  221. request={async () => {
  222. const currentSys = localStorage.getItem('currentSelectedTab');
  223. const { systemId } = JSON.parse(currentSys as string);
  224. const resp = await getDicDataBySysId(systemId, 'ITEM_COST_COLUNM_TYPE');
  225. if (resp) {
  226. const { dataVoList = [] } = resp;
  227. return dataVoList.map((a: any) => ({ label: a.name, value: a.code }))
  228. }
  229. return []
  230. }}
  231. fieldProps={{
  232. onChange(value, option: any) {
  233. const { label = '' } = option;
  234. formRef.current?.setFieldValue('columnTypeName', label)
  235. },
  236. }}
  237. name="columnType"
  238. label="成本列类型:"
  239. />
  240. <ProFormSelect
  241. name="reportType"
  242. label="损益表类型:"
  243. placeholder="请输入"
  244. request={async () => {
  245. const { systemId } = JSON.parse((localStorage.getItem('currentSelectedTab')) as string)
  246. const resp = await getDicDataBySysId(systemId,'PROFIT_REPORT_TYPE');
  247. if (resp) {
  248. const { dataVoList = [] } = resp;
  249. return dataVoList.map((a: any) => ({ label: a.name, value: a.code }))
  250. }
  251. return []
  252. }}
  253. rules={[{ required: true, message: '损益表类型不能为空!' }]}
  254. />
  255. <ProFormDependency name={['reportType']}>
  256. {
  257. ({reportType}) => {
  258. return reportType? (
  259. <ProFormCascader
  260. rules={[
  261. {
  262. required: true,
  263. message: '请选择',
  264. },
  265. ]}
  266. params={{reportType}}
  267. request={async (params) => {
  268. console.log({params});
  269. const {reportType} = params;
  270. const resp = await getReportProjectSettingList({ reportType });
  271. if (resp) {
  272. return resp.list
  273. }
  274. return []
  275. }}
  276. fieldProps={{
  277. fieldNames: {
  278. label: 'reportName',
  279. value: 'id'
  280. },
  281. onChange: (value: any, selectedOptions: any) => {
  282. // console.log({value,selectedOptions});
  283. const { num = 0, reportName = '' } = selectedOptions[selectedOptions.length - 1]
  284. formRef.current?.setFieldValue('profitNum', num);
  285. formRef.current?.setFieldValue('profitName', reportName);
  286. formRef.current?.setFieldValue('profitPath', value.join(','));
  287. formRef.current?.setFieldValue('profitPathName', (selectedOptions.map((a: any) => a.reportName)).join('/'));
  288. }
  289. }}
  290. name="profitId"
  291. label="损益表项目:"
  292. />
  293. ):<></>
  294. }
  295. }
  296. </ProFormDependency>
  297. </ModalForm>
  298. )
  299. }
  300. const shareParamsSetCommit = async (rows: any[]) => {
  301. // console.log({currentRow,rows});
  302. const result = rows.map((a) => ({
  303. shareParamColumnCode: currentRow.columnCode,
  304. shareParamCode: a.shareParamCode,
  305. shareParamName: a.shareParamName,
  306. percent: a.percent
  307. }));
  308. const resp = await saveParamsList(result);
  309. if (resp) {
  310. set_editTableVisible(false);
  311. message.success('操作成功!');
  312. tableRef.current?.reload();
  313. }
  314. }
  315. const tableSelecterCommit = async (keys: Key[], rows: any) => {
  316. const { id } = currentRow;
  317. const resp = await copyParamsList({ id, responsibilityIds: keys });
  318. if (resp) {
  319. set_tableSelecterVisible(false);
  320. message.success('操作成功!');
  321. tableRef.current?.reload();
  322. }
  323. }
  324. return (
  325. <KCIMPagecontainer className='AllocationParamsMap' title={false}>
  326. <EditTableModal
  327. onVisibleChange={(bool) => { set_editTableVisible(bool); if (!bool) setCurrentRow(undefined) }}
  328. title='分摊参数设置'
  329. rowKey={'id'}
  330. record={currentRow}
  331. open={editTableVisible}
  332. onFinish={(rows) => shareParamsSetCommit(rows)}
  333. />
  334. <TableSelecter
  335. onVisibleChange={(bool) => set_tableSelecterVisible(bool)}
  336. title='选择复制目标'
  337. rowKey={'id'}
  338. defaultSelectedKeys={[]}
  339. record={currentRow}
  340. open={tableSelecterVisible}
  341. onFinish={(keys, rows) => tableSelecterCommit(keys, rows)}
  342. />
  343. <div className='toolBar' >
  344. <div className='filter'>
  345. <div className='filterItem'>
  346. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  347. <Input placeholder={'成本列代码/名称'} allowClear
  348. suffix={
  349. <IconFont type="iconsousuo" style={{ color: '#99A6BF' }} onClick={() => tableDataSearchHandle('filter')} />
  350. }
  351. onChange={(e) => {
  352. set_tableDataSearchKeywords(e.target.value);
  353. if (e.target.value.length == 0) {
  354. set_tableDataFilterParams({
  355. ...tableDataFilterParams,
  356. filter: ''
  357. });
  358. }
  359. }}
  360. onPressEnter={(e) => {
  361. set_tableDataFilterParams({
  362. ...tableDataFilterParams,
  363. filter: (e.target as HTMLInputElement).value
  364. });
  365. }}
  366. />
  367. </div>
  368. </div>
  369. <div className='btnGroup'>
  370. <UpDataActBtn record type='ADD' />
  371. </div>
  372. </div>
  373. <div>
  374. <KCIMTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  375. </div>
  376. </KCIMPagecontainer>
  377. )
  378. }