index.jsx 13 KB

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