index.jsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-28 10:32:49
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. import { Space, Table, Tag } from 'antd';
  10. import React, { useState, useRef } from 'react';
  11. import { PageContainer } from '@ant-design/pro-layout';
  12. import ProTable from '@ant-design/pro-table';
  13. import { DrawerForm } from '@ant-design/pro-form';
  14. import { getAccountProductConnectList,getAccountProductConnectableList,saveAccountProductConnected } from './service';
  15. const ResponsibilityCenterConnect = () => {
  16. const columns = [
  17. {
  18. title: '会计科目名称',
  19. dataIndex: 'accountingName',
  20. key: 'accountingName',
  21. hideInSearch: false,
  22. width: '20%',
  23. },
  24. {
  25. title: '会计科目编号',
  26. dataIndex: 'accountingCode',
  27. key: 'accountingCode',
  28. hideInSearch: true,
  29. width: '20%'
  30. },
  31. {
  32. title: '成本列表',
  33. dataIndex: 'productVOs',
  34. key: 'productVOs',
  35. hideInSearch: false,
  36. render: (productVOs) => {
  37. if (Array.isArray(productVOs)) {
  38. return productVOs.map((item, index) => { return <Tag key={index}>{item.productName}</Tag> })
  39. } else {
  40. return <></>
  41. }
  42. }
  43. },
  44. {
  45. title:'操作',
  46. dataIndex: 'option',
  47. key: 'option',
  48. valueType: 'option',
  49. width: '15%',
  50. render: (_, record) => {
  51. const { isParent } = record;
  52. return !isParent ? [
  53. <a
  54. key="config"
  55. onClick={() => {
  56. setDrawerVisible(true);
  57. setCurrentRow(record);
  58. }}
  59. >
  60. 设置对应
  61. </a>,
  62. ] : []
  63. },
  64. }
  65. ];
  66. const drawerTableColumns = [
  67. {
  68. title: 'Id',
  69. dataIndex: 'id',
  70. key: 'id',
  71. hideInSearch: true,
  72. },
  73. {
  74. title: '成本中心名称',
  75. dataIndex: 'name',
  76. key: 'name',
  77. hideInSearch: false,
  78. }
  79. ];
  80. const actionRef = useRef(); //表格
  81. const drawerFormRef = useRef(); //DrawerForm
  82. const actionDrawertableRef = useRef(); //Drawertable
  83. const [currentRow, setCurrentRow] = useState({});
  84. const [drawerVisible, setDrawerVisible] = useState(false);
  85. const [selectedRowKeys,setSelectedRowKeys] = useState([]);
  86. const [defaultExpandedRowKeys,setDefaultExpandedRowKeys] = useState([]);
  87. const [accountType,setAccountType] = useState(1)
  88. /**
  89. *
  90. * @param {Boolean} bool
  91. */
  92. const drawerVisibleChange = (bool) => {
  93. // console.log({currentRow});
  94. const {productVOs} = currentRow;
  95. const selected = productVOs?productVOs.map(item=>item.id):[];
  96. if (bool)setSelectedRowKeys(selected==undefined?[]:selected);
  97. setDrawerVisible(bool);
  98. if (!bool) setCurrentRow(undefined);
  99. }
  100. //获取责任中心对应列表
  101. const getList = async (params = {}, sort, filter) => {
  102. const res = await getAccountProductConnectList({...params,accountType});
  103. const {data:{list=[],totalCount},success} = res;
  104. const defaultKeys = list&&list.map(item=>item.id);
  105. setDefaultExpandedRowKeys(defaultKeys);
  106. return {
  107. data: list,
  108. total:totalCount,
  109. success:success,
  110. };
  111. };
  112. //获取责任中心可绑定科室列表
  113. const getConnectableList = async (params = {}, sort, filter)=>{
  114. const {responsibilityId} = currentRow;
  115. const res = await getAccountProductConnectableList({...params,responsibilityId});
  116. const {data,status} = res;
  117. // console.log({res,data,status});
  118. if(status == 200){
  119. return {
  120. data:data,
  121. success:true,
  122. }
  123. }
  124. }
  125. const onExpandedRowsChange = (expandedRows)=>{
  126. setDefaultExpandedRowKeys([].concat(expandedRows))
  127. }
  128. return (
  129. <PageContainer
  130. tabList={[
  131. {
  132. tab: '收入',
  133. key: 1,
  134. },
  135. {
  136. tab: '支出',
  137. key: 2,
  138. },
  139. ]}
  140. onTabChange={(key)=>{
  141. setAccountType(key);
  142. if (actionRef.current) {
  143. actionRef.current.reload();
  144. }
  145. }}
  146. >
  147. <ProTable
  148. columns={columns}
  149. request={getList}
  150. actionRef={actionRef}
  151. rowKey="id"
  152. childrenColumnName="child"
  153. expandable={{ defaultExpandedRowKeys: [],expandedRowKeys:defaultExpandedRowKeys,onExpandedRowsChange:onExpandedRowsChange }}
  154. toolBarRender={() => []}
  155. pagination={{
  156. pageSize: 10,
  157. }}
  158. search={false}
  159. />
  160. <DrawerForm
  161. title="可绑定成本中心列表"
  162. formRef={drawerFormRef}
  163. visible={drawerVisible}
  164. onVisibleChange={(visible) => drawerVisibleChange(visible)}
  165. // onFinish={(value) => onSubmit({ ...values, ...value })}
  166. onFinish={async ()=>{
  167. // console.log({selectedRowKeys,currentRow});
  168. const {id} = currentRow;
  169. const resp = await saveAccountProductConnected({id,products:selectedRowKeys});
  170. const {status} = resp;
  171. if(status==200){
  172. setDrawerVisible(false);
  173. if (actionRef.current) {
  174. actionRef.current.reload();
  175. }
  176. }
  177. }}
  178. >
  179. <ProTable
  180. columns={drawerTableColumns}
  181. request={getConnectableList}
  182. rowKey="id"
  183. toolBarRender={() => []}
  184. actionRef={actionDrawertableRef}
  185. pagination={{
  186. pageSize: 10,
  187. }}
  188. rowSelection={{
  189. // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
  190. // 注释该行则默认不显示下拉选项
  191. selectedRowKeys,
  192. selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
  193. onChange:(selectedRowKeys)=>{
  194. setSelectedRowKeys([...selectedRowKeys]);
  195. }
  196. }}
  197. tableAlertRender={({ selectedRowKeys, selectedRows, onCleanSelected }) => {
  198. // console.log({selectedRowKeys});
  199. return (
  200. <Space size={24}>
  201. <span>
  202. 已选 {selectedRowKeys.length} 项
  203. <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
  204. 取消选择
  205. </a>
  206. </span>
  207. </Space>
  208. )
  209. }}
  210. tableAlertOptionRender={() => {
  211. return (
  212. <Space size={16}>
  213. {/* <a>批量绑定</a> */}
  214. </Space>
  215. );
  216. }}
  217. search={false}
  218. />
  219. </DrawerForm>
  220. </PageContainer>
  221. );
  222. };
  223. export default ResponsibilityCenterConnect;