index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-11-20 15:29:57
  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 } 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, 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, getCostshareparamConnectList, getResponsibilityCenterSelecterList, saveParamsList } from './service';
  20. import './style.less';
  21. import { getAccountingSubjectList } from '../../accountingAccountSet/accountingSubMana/service';
  22. import { getChilds } from '@/utils/tooljs';
  23. import EditTableModal from './editTableModal';
  24. import TableSelecter from './tableSelector';
  25. const IconFont = createFromIconfontCN({
  26. scriptUrl: '',
  27. });
  28. export default function AllocationParamsMap() {
  29. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>(undefined);
  30. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  31. const tableRef = useRef<ActionType>();
  32. const formRef = useRef<ProFormInstance>();
  33. const [currentRow, setCurrentRow] = useState<any | undefined>(undefined);
  34. const [selectableLevelList, setSelectableLevelList] = useState([]);//可选的分摊层级列表
  35. const [tabs, set_tabs] = useState<any[]>([]);
  36. const [accountType, set_accountType] = useState<Key>(1);
  37. const [selectedResponsibilityId, setSelectedResponsibilityId] = useState(null);
  38. const [selectedResponsibility, setSelectedResponsibility] = useState(null);
  39. const [editTableVisible, set_editTableVisible] = useState(false);
  40. const [tableSelecterVisible,set_tableSelecterVisible] = useState(false);
  41. const columns: ProColumns[] = [
  42. {
  43. title: '分摊级别',
  44. ellipsis:true,
  45. dataIndex: 'shareLevel',
  46. },
  47. {
  48. title: '责任中心编码',
  49. ellipsis:true,
  50. dataIndex: 'responsibilityCode',
  51. },
  52. {
  53. title: '责任中心名',
  54. ellipsis:true,
  55. dataIndex: 'responsibilityName',
  56. },
  57. {
  58. title: '会计科目名称',
  59. ellipsis:true,
  60. dataIndex: 'accountingNames',
  61. },
  62. {
  63. title: '会计科目编码',
  64. ellipsis:true,
  65. dataIndex: 'accountingCodes',
  66. },
  67. {
  68. title: '别名',
  69. ellipsis:true,
  70. dataIndex: 'alias',
  71. },
  72. {
  73. title: '备注',
  74. ellipsis:true,
  75. dataIndex: 'costNode',
  76. },
  77. {
  78. title: '操作',
  79. key: 'option',
  80. width:200,
  81. valueType: 'option',
  82. render: (_: any, record: any) => {
  83. return [
  84. <a key='copy' onClick={()=>{set_tableSelecterVisible(true);setCurrentRow(record);}}>复制</a>,
  85. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  86. <Popconfirm
  87. title="是否确认删除?"
  88. key="del"
  89. onConfirm={() => delTableData(record)}
  90. >
  91. <a>删除</a>
  92. </Popconfirm>,
  93. <a key='share' onClick={()=>{set_editTableVisible(true);setCurrentRow(record)}}>分摊参数</a>
  94. ]
  95. },
  96. },
  97. ]
  98. const getTableData = async (params: any) => {
  99. const resp = await getCostshareparamConnectList({ ...params });
  100. if (resp) {
  101. return {
  102. data: resp.list,
  103. success: true,
  104. total: resp.totalCount,
  105. pageSize: resp.pageSize,
  106. totalPage: resp.totalPage,
  107. }
  108. }
  109. return []
  110. }
  111. const tableDataSearchHandle = (paramName: string) => {
  112. set_tableDataFilterParams({
  113. ...tableDataFilterParams,
  114. [`${paramName}`]: tableDataSearchKeywords
  115. })
  116. }
  117. const delTableData = async (record: any) => {
  118. const resp = await delData(record.id);
  119. if (resp) {
  120. message.success('操作成功!');
  121. tableRef.current?.reload();
  122. // message.success('操作成功!');
  123. }
  124. }
  125. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  126. const result = {
  127. responsibilityId: formVal.responsibilityId,
  128. accountingIds: formVal.accountingIds.join(','),
  129. isShareCost: formVal.isShareCost,
  130. alias: formVal.alias,
  131. costNode: formVal.costNode,
  132. responsibilityName: formVal.responsibility.responsibilityName,
  133. shareLevel: formVal.responsibility.shareLevel,
  134. responsibilityCode: formVal.responsibility.responsibilityCode
  135. };
  136. if (type == 'ADD') {
  137. const resp = await addData(result);
  138. if (resp) {
  139. tableRef.current?.reload();
  140. message.success('操作成功!');
  141. }
  142. }
  143. if (type == 'EDIT') {
  144. try {
  145. const resp = await editData({ ...formVal, isBaseCost: formVal.isBaseCost, isIncomeGroutSetSelect: false, isShareParamSelect: false, accountType });
  146. if (resp) {
  147. tableRef.current?.reload();
  148. message.success('操作成功!');
  149. }
  150. } catch (error) {
  151. console.log({ error });
  152. }
  153. }
  154. return true;
  155. }
  156. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  157. const [ifDisable, setIfDisable] = useState(false);
  158. let needDisableIds: any[] = [];
  159. let accountingIds:Key[] = [];
  160. return (
  161. <ModalForm
  162. title={`${type == 'EDIT' ? '编辑' : '新增'}成本分摊参数对应`}
  163. width={350}
  164. formRef={formRef}
  165. initialValues={type == 'EDIT' ? {
  166. ...record,
  167. } : {}}
  168. trigger={
  169. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  170. }
  171. onFinish={(val) => {
  172. return updateTable(type == 'EDIT' ? { ...record, ...val,accountingIds } : { ...val,accountingIds }, type);
  173. }}
  174. modalProps={{ destroyOnClose: true }}
  175. colProps={{ span: 24 }}
  176. grid
  177. >
  178. <ProFormText name="responsibility" hidden />
  179. <ProFormSelect
  180. rules={[
  181. {
  182. required: true,
  183. message: '请选择责任中心',
  184. },
  185. ]}
  186. fieldProps={{
  187. onChange: async (val, option: any) => {
  188. const { } = option;
  189. const resp = await getResponsibilityCenterSelecterList();
  190. // const resp = [
  191. // {
  192. // calcType: 1,
  193. // id: 401,
  194. // responsibilityCode: "B0100",
  195. // responsibilityId: 401,
  196. // responsibilityName: "公共费用",
  197. // shareId: 59,
  198. // shareLevel: 1,
  199. // shareName: "公共费用",
  200. // }
  201. // ]
  202. if (resp) {
  203. const selected = resp.filter((item: any) => item.id == val);
  204. if (selected[0]) {
  205. formRef.current?.setFieldValue('responsibility', selected[0]);
  206. }
  207. }
  208. if (needDisableIds.includes(val)) {
  209. setIfDisable(false);
  210. } else {
  211. setIfDisable(true);
  212. }
  213. },
  214. }}
  215. request={async () => {
  216. const resp = await getResponsibilityCenterSelecterList();
  217. // const resp = [
  218. // {
  219. // calcType: 1,
  220. // id: 401,
  221. // responsibilityCode: "B0100",
  222. // responsibilityId: 401,
  223. // responsibilityName: "公共费用",
  224. // shareId: 59,
  225. // shareLevel: 1,
  226. // shareName: "公共费用",
  227. // }
  228. // ]
  229. if (resp) {
  230. return resp.map((item: any) => {
  231. if (item.calcType == 1) {
  232. needDisableIds.push(item.id);
  233. }
  234. return ({
  235. label: item.responsibilityName,
  236. value: item.id,
  237. })
  238. })
  239. }
  240. return []
  241. }}
  242. name="responsibilityId"
  243. label="请选择责任中心"
  244. />
  245. <ProFormTreeSelect
  246. disabled={ifDisable}
  247. allowClear
  248. rules={[
  249. {
  250. required: ifDisable ? false : true,
  251. message: '请选择会计科目',
  252. },
  253. ]}
  254. request={async () => {
  255. const resp = await getAccountingSubjectList({ accountType, pageSize: 500, current: 1 });
  256. // const resp = {
  257. // list: [
  258. // {
  259. // accountingCode: "C0160",
  260. // accountingName: "其他支出",
  261. // id: 259,
  262. // isBaseCost: 0,
  263. // isIncomeGroutSetSelect: false,
  264. // isShareParamSelect: false,
  265. // children: [
  266. // {
  267. // accountingCode: "C0164",
  268. // accountingName: "社会服务辅助",
  269. // id: 263,
  270. // isBaseCost: 0,
  271. // isIncomeGroutSetSelect: false,
  272. // isShareParamSelect: false,
  273. // }
  274. // ]
  275. // }
  276. // ]
  277. // };
  278. if (resp) {
  279. return resp.list
  280. }
  281. return []
  282. }}
  283. fieldProps={{
  284. showSearch: true,
  285. multiple: true,
  286. treeCheckable:true,
  287. treeNodeFilterProp: 'accountingName',
  288. showCheckedStrategy:'SHOW_CHILD',
  289. fieldNames: {
  290. label: 'accountingName',
  291. value: 'id'
  292. },
  293. onSelect: (value, opt) => {
  294. // console.log({ value, opt });
  295. // console.log(getChilds(opt,'children'));
  296. if(opt.children&&opt.children.length>0){
  297. const childs = getChilds(opt,'children');
  298. const ids = childs.map((a)=>a.id);
  299. accountingIds = accountingIds.concat(ids);
  300. }else{
  301. accountingIds.push(value);
  302. }
  303. }
  304. }}
  305. name="accountings"
  306. label="选择会计科目"
  307. />
  308. <ProFormSelect
  309. disabled={ifDisable}
  310. rules={[
  311. {
  312. required: ifDisable ? false : true,
  313. message: '请选择',
  314. },
  315. ]}
  316. request={async () => [
  317. { label: '不包含分摊成本', value: 0 },
  318. { label: '包含分摊成本', value: 1 }
  319. ]}
  320. name="isShareCost"
  321. label="是否包含分摊成本"
  322. />
  323. <ProFormText
  324. name="alias"
  325. label="别名"
  326. />
  327. <ProFormTextArea
  328. name="costNode"
  329. label="备注"
  330. placeholder="请输入备注"
  331. />
  332. </ModalForm>
  333. )
  334. }
  335. const shareParamsSetCommit = async (rows:any[])=>{
  336. const resp = await saveParamsList({id:currentRow.id,shareParamProportionVOList:rows});
  337. if(resp){
  338. set_editTableVisible(false);
  339. message.success('操作成功!');
  340. tableRef.current?.reload();
  341. }
  342. }
  343. const tableSelecterCommit = async (keys:Key[],rows:any) => {
  344. const { id } = currentRow;
  345. const resp = await copyParamsList({ id, responsibilityIds: keys });
  346. if(resp){
  347. set_tableSelecterVisible(false);
  348. message.success('操作成功!');
  349. tableRef.current?.reload();
  350. }
  351. }
  352. return (
  353. <KCIMPagecontainer className='AllocationParamsMap' title={false}>
  354. <EditTableModal
  355. onVisibleChange={(bool) => set_editTableVisible(bool)}
  356. title='分摊参数设置'
  357. rowKey={'id'}
  358. record={currentRow}
  359. open={editTableVisible}
  360. onFinish={(rows) => shareParamsSetCommit(rows)}
  361. />
  362. <TableSelecter
  363. onVisibleChange={(bool) => set_tableSelecterVisible(bool)}
  364. title='选择复制目标'
  365. rowKey={'id'}
  366. defaultSelectedKeys={[]}
  367. record={currentRow}
  368. open={tableSelecterVisible}
  369. onFinish={(keys, rows) => tableSelecterCommit(keys, rows)}
  370. />
  371. <div className='toolBar' >
  372. <div className='filter'>
  373. <div className='filterItem'>
  374. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  375. <Input placeholder={'责任中心名称'} allowClear
  376. suffix={
  377. <IconFont type="iconsousuo" style={{color:'#99A6BF'}} onClick={() => tableDataSearchHandle('name')} />
  378. }
  379. onChange={(e) => {
  380. set_tableDataSearchKeywords(e.target.value);
  381. if (e.target.value.length == 0) {
  382. set_tableDataFilterParams({
  383. ...tableDataFilterParams,
  384. name: ''
  385. });
  386. }
  387. }}
  388. onPressEnter={(e) => {
  389. set_tableDataFilterParams({
  390. ...tableDataFilterParams,
  391. name: (e.target as HTMLInputElement).value
  392. });
  393. }}
  394. />
  395. </div>
  396. </div>
  397. <div className='btnGroup'>
  398. <UpDataActBtn record type='ADD' />
  399. </div>
  400. </div>
  401. <div>
  402. <KCIMTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  403. </div>
  404. </KCIMPagecontainer>
  405. )
  406. }