index.jsx 15 KB

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