index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-30 15:57:21
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. import { PlusOutlined } from '@ant-design/icons';
  10. import { Button, Popconfirm, Space,Table } from 'antd';
  11. import React, { useState, useRef } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import { ModalForm, ProFormText, ProFormSelect} from '@ant-design/pro-form';
  15. import UpdateForm from './updateForm';
  16. import DrawerContent from './selectCopyDrawer';
  17. import {deepGetAllParents} from '@/utils';
  18. import { getCostshareparamList, editCostshareparamList, delCostshareparam, addCostshareparam,updateCostShareParamByAccountId } from './service';
  19. import { getAccountingSubjectList} from '../accountingSubject/service';
  20. const CostAllocationParamsSetting = () => {
  21. const columns = [
  22. {
  23. title: '成本分摊参数名',
  24. dataIndex: 'shareParamName',
  25. key: 'shareParamName',
  26. hideInSearch: false,
  27. },
  28. {
  29. title: '成本分摊参数编号',
  30. dataIndex: 'shareParamCode',
  31. key: 'shareParamCode',
  32. hideInSearch: true,
  33. },
  34. {
  35. title: '计算方式',
  36. dataIndex: 'calcType',
  37. key: 'calcType',
  38. hideInSearch: true,
  39. render: (text) => <>{text == 1 ? '手动填写' : '按对应会计科目计算'}</>,
  40. },
  41. {
  42. title:'操作',
  43. dataIndex: 'option',
  44. valueType: 'option',
  45. render: (_, record) =>{
  46. const {calcType} = record;
  47. const groups = [
  48. <a
  49. key="config"
  50. onClick={() => {
  51. handleUpdateModalVisible(true);
  52. setCurrentRow(record);
  53. }}
  54. >
  55. 编辑
  56. </a>,
  57. <Popconfirm
  58. key="subscribeAlert"
  59. title="是否确定删除?"
  60. onConfirm={() => {
  61. setCurrentRow(record);
  62. delListHandler(record);
  63. }}
  64. >
  65. <a>删除</a>
  66. </Popconfirm>,
  67. ]
  68. return calcType==1?groups:[...groups,<a
  69. key="config"
  70. onClick={() => {
  71. setDrawerVisible(true);
  72. setCurrentRow(record);
  73. setCurrentResponsibilityRow(record);
  74. }}
  75. >
  76. 设置对应会计科目
  77. </a>,]
  78. }
  79. },
  80. ];
  81. const drawerTableColumns = [
  82. {
  83. title: '会计科目编码',
  84. dataIndex: 'accountingCode',
  85. key: 'accountingCode',
  86. hideInSearch: true,
  87. },
  88. {
  89. title: '会计科目名称',
  90. dataIndex: 'accountingName',
  91. key: 'accountingName',
  92. hideInSearch: false,
  93. }
  94. ];
  95. const [createModalVisible, handleModalVisible] = useState(false);
  96. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  97. const actionRef = useRef(); //表格
  98. const ref = useRef(); //新增表单
  99. const [currentRow, setCurrentRow] = useState({});
  100. const [currentResponsibilityRow, setCurrentResponsibilityRow] = useState({});
  101. const [expandedRowKeys,setExpandedRowKeys] = useState([]);
  102. const actionDrawertableRef = useRef(); //Drawertable
  103. const [drawerVisible, setDrawerVisible] = useState(false);
  104. const [accountType, setAccountType] = useState(1);
  105. const [selectedRowKeys,setSelectedRowKeys] = useState([]);
  106. /**
  107. *
  108. * @param {Boolean} bool 弹窗展示状态
  109. */
  110. const updateModalVisibleChange = (bool) => {
  111. handleUpdateModalVisible(bool);
  112. if (!bool) setCurrentRow(undefined);
  113. };
  114. //获取科室列表
  115. const getList = async (params = {}, sort, filter) => {
  116. const res = await getCostshareparamList(params);
  117. return {
  118. data: res.data.list,
  119. total: res.data.totalCount,
  120. success: res.success,
  121. };
  122. };
  123. /**
  124. *
  125. * @param {Object} value 删除项数据
  126. */
  127. const delListHandler = async (value) => {
  128. const resp = await delCostshareparam(value);
  129. if (resp.status == 200) {
  130. if (actionRef.current) {
  131. actionRef.current.reload();
  132. }
  133. }
  134. };
  135. //分摊参数回调
  136. const drawerVisibleChange = async (bool) => {
  137. // console.log({currentRow});
  138. if (bool) {
  139. if(actionDrawertableRef.current){
  140. actionDrawertableRef.current.reload();
  141. }
  142. }
  143. setDrawerVisible(bool);
  144. }
  145. const getAccountingSubjects = async (params = {}, sort, filter)=>{
  146. const {id} = currentResponsibilityRow;
  147. const {accountingIds=[]} = currentRow;
  148. const result = await getAccountingSubjectList({accountType,shareParamId:id});
  149. const {status,data:{list}} = result;
  150. if(status==200){
  151. const allparents= deepGetAllParents(list,'children');
  152. const allparentsIds = allparents?allparents.map(item=>item.id):[];
  153. setExpandedRowKeys(allparentsIds);
  154. const temp = accountingIds&&accountingIds.length>0?accountingIds.map(item=>Number(item)):[];
  155. setSelectedRowKeys(temp);
  156. return {
  157. data: list,
  158. success: true
  159. };
  160. }
  161. }
  162. /**
  163. *
  164. * @param {*} key tab key
  165. * @param {*} tableRef dtawer table instance
  166. */
  167. const onTabChange = (key,tableRef)=>{
  168. setAccountType(Number(key));
  169. if (tableRef.current) {
  170. tableRef.current.reload();
  171. }
  172. }
  173. return (
  174. <PageContainer>
  175. <ProTable
  176. columns={columns}
  177. request={getList}
  178. actionRef={actionRef}
  179. rowKey="id"
  180. toolBarRender={() => [
  181. <Button
  182. key="button"
  183. icon={<PlusOutlined />}
  184. type="primary"
  185. onClick={() => {
  186. handleModalVisible(true);
  187. }}
  188. >
  189. 新增
  190. </Button>
  191. ]}
  192. pagination={{
  193. pageSize: 10,
  194. }}
  195. search={{
  196. defaultCollapsed: false,
  197. labelWidth: 'auto',
  198. }}
  199. />
  200. <ModalForm
  201. title="新增成本分摊参数"
  202. width="800px"
  203. labelCol={{ span: 5, offset: 3 }}
  204. layout={'horizontal'}
  205. visible={createModalVisible}
  206. formRef={ref}
  207. onVisibleChange={(bool)=>{
  208. if (ref.current) {
  209. ref.current.resetFields();
  210. }
  211. handleModalVisible(bool);
  212. }}
  213. onFinish={async (value) => {
  214. const success = await addCostshareparam(value);
  215. // console.log({ success });
  216. if (success) {
  217. handleModalVisible(false);
  218. if (actionRef.current) {
  219. actionRef.current.reload();
  220. }
  221. }
  222. }}
  223. >
  224. <ProFormText
  225. label="成本分摊参数名"
  226. rules={[
  227. {
  228. required: true,
  229. message:'成本分摊参数名是必填项',
  230. },
  231. ]}
  232. width="sm"
  233. name="shareParamName"
  234. />
  235. <ProFormText
  236. label="成本分摊参数编号"
  237. rules={[
  238. {
  239. required: true,
  240. message:'成本分摊参数编号是必填项',
  241. },
  242. ]}
  243. width="sm"
  244. name="shareParamCode"
  245. />
  246. <ProFormSelect
  247. rules={[
  248. {
  249. required: true,
  250. message:'请选择计算方式',
  251. },
  252. ]}
  253. options={[
  254. {
  255. value: 1,
  256. label: '手动填写',
  257. },
  258. {
  259. value: 2,
  260. label: '按对应会计科目计算',
  261. },
  262. ]}
  263. width="sm"
  264. name="calcType"
  265. label="计算方式"
  266. />
  267. </ModalForm>
  268. {/* 设置对应会计科目 */}
  269. <DrawerContent
  270. columns={drawerTableColumns}
  271. visible={drawerVisible}
  272. currentRow={currentRow}
  273. title={'选择会计科目'}
  274. defaultSelected={selectedRowKeys}
  275. pageContainerConfig={(tableRef) => {
  276. return {
  277. header: {
  278. title: ''
  279. },
  280. tabList:[
  281. {
  282. tab: '收益',
  283. key: 1,
  284. },
  285. {
  286. tab: '支出',
  287. key: 2,
  288. },
  289. ],
  290. onTabChange:(key)=>onTabChange(key,tableRef)
  291. }
  292. }}
  293. onVisibleChange={(bool) => drawerVisibleChange(bool)}
  294. renderListFunc={getAccountingSubjects}
  295. config={{ rowKeys: 'id', tableSearch: false }}
  296. tableSearch={false}
  297. expandable={{
  298. expandedRowKeys:expandedRowKeys
  299. }}
  300. onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
  301. const {id} = currentResponsibilityRow;
  302. const resp = await updateCostShareParamByAccountId({costShareParamId:id,accountIds:selectedRowKeys});
  303. const {status} = resp;
  304. setDrawerVisible(false);
  305. if(status==200){
  306. if (actionRef.current) {
  307. actionRef.current.reload();
  308. }
  309. }
  310. }}
  311. />
  312. {/* <DrawerForm
  313. title="设置对应会计科目"
  314. formRef={drawerFormRef}
  315. visible={drawerVisible}
  316. onVisibleChange={(visible) => drawerVisibleChange(visible)}
  317. // onFinish={(value) => onSubmit({ ...values, ...value })}
  318. onFinish={async () => {
  319. const {id} = currentResponsibilityRow;
  320. const resp = await updateCostShareParamByAccountId({costShareParamId:id,accountIds:selectedRowKeys});
  321. const {status} = resp;
  322. setDrawerVisible(false);
  323. if(status==200){
  324. if (actionRef.current) {
  325. actionRef.current.reload();
  326. }
  327. }
  328. }}
  329. >
  330. <PageContainer
  331. header={{
  332. title:''
  333. }}
  334. tabList={[
  335. {
  336. tab: '收益',
  337. key: 1,
  338. },
  339. {
  340. tab: '支出',
  341. key: 2,
  342. },
  343. ]}
  344. onTabChange={onTabChange}
  345. >
  346. <ProTable
  347. columns={drawerTableColumns}
  348. rowKey="id"
  349. actionRef={actionDrawertableRef}
  350. rowSelection={{
  351. // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
  352. // 注释该行则默认不显示下拉选项
  353. checkStrictly:false,
  354. selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
  355. selectedRowKeys:selectedRowKeys,
  356. onChange:(selectedRowKeys, selectedRows)=>{
  357. setSelectedRowKeys(selectedRowKeys);
  358. }
  359. }}
  360. tableAlertRender={({ selectedRowKeys, selectedRows, onCleanSelected }) =>{
  361. setSelectedRowKeys(selectedRowKeys);
  362. return (
  363. <Space size={24}>
  364. <span>
  365. 已选 {selectedRowKeys.length} 项
  366. <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
  367. 取消选择
  368. </a>
  369. </span>
  370. </Space>
  371. )
  372. }}
  373. request={async (params = {}, sort, filter) => {
  374. const {id} = currentResponsibilityRow;
  375. const result = await getAccountingSubjectList({accountType,shareParamId:id});
  376. const {status,data} = result;
  377. if(status==200){
  378. const selectedList = data.list.filter(item=>item.isSelect);
  379. const temp = selectedList.map(item=>item.id);
  380. setSelectedRowKeys(temp);
  381. return {
  382. data: data.list,
  383. success: true
  384. };
  385. }
  386. }}
  387. pagination={{
  388. pageSize: 10,
  389. }}
  390. search={false}
  391. />
  392. </PageContainer>
  393. </DrawerForm> */}
  394. {/* 更新 */}
  395. <UpdateForm
  396. onSubmit={async (value) => {
  397. console.log({ '编辑': value });
  398. const success = await editCostshareparamList(value);
  399. if (success) {
  400. handleUpdateModalVisible(false);
  401. setCurrentRow(undefined);
  402. if (actionRef.current) {
  403. actionRef.current.reload();
  404. }
  405. }
  406. }}
  407. onCancel={() => {
  408. handleUpdateModalVisible(false);
  409. setCurrentRow(undefined);
  410. }}
  411. updateModalVisible={updateModalVisible}
  412. updateModalVisibleChange={updateModalVisibleChange}
  413. values={currentRow || {}}
  414. />
  415. </PageContainer>
  416. );
  417. };
  418. export default CostAllocationParamsSetting;