index.jsx 14 KB

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