index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-06 18:28:12
  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} from 'antd';
  11. import React, { useState, useRef, useEffect } 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 { getAccountingSubjectList, editAccountingSubjectList, delAccountingSubject, addAccountingSubject, getAccountingSubjectForSelecter } from './service';
  17. const AccountingSubject = () => {
  18. const columns = [
  19. {
  20. title: '会计科目名称',
  21. dataIndex: 'accountingName',
  22. key: 'accountingName',
  23. hideInSearch: false,
  24. width: '30%'
  25. },
  26. {
  27. title: '会计科目编码',
  28. dataIndex: 'accountingCode',
  29. key: 'accountingCode',
  30. hideInSearch: true,
  31. width: '30%'
  32. },
  33. {
  34. title: '是否固定成本',
  35. dataIndex: 'isBaseCost',
  36. key: 'isBaseCost',
  37. hideInSearch: true,
  38. render: (text) => <>{text == 1 ? '是' : '否'}</>,
  39. width: '20%'
  40. },
  41. {
  42. title:'操作',
  43. dataIndex: 'option',
  44. valueType: 'option',
  45. key: 'option',
  46. width: '15%',
  47. render: (_, record) => [
  48. <a
  49. key="config"
  50. onClick={() => {
  51. setCurrentRow(record);
  52. handleModalVisible(true)
  53. }}
  54. >
  55. 添加
  56. </a>,
  57. <a
  58. key="config"
  59. onClick={() => {
  60. handleUpdateModalVisible(true);
  61. setCurrentRow(record);
  62. }}
  63. >
  64. 编辑
  65. </a>,
  66. <Popconfirm
  67. key="subscribeAlert"
  68. title="是否确定删除?"
  69. onConfirm={() => {
  70. setCurrentRow(record);
  71. delListHandler(record);
  72. }}
  73. >
  74. <a>删除</a>
  75. </Popconfirm>,
  76. ],
  77. },
  78. ];
  79. const [createModalVisible, handleModalVisible] = useState(false);
  80. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  81. const actionRef = useRef(); //表格
  82. const ref = useRef(); //新增表单
  83. const [currentRow, setCurrentRow] = useState(undefined);
  84. const [accountType, setAccountType] = useState(1);
  85. const [options, setOptions] = useState([]);
  86. const [ifChild, setIfChild] = useState(false);
  87. const [expanedRowIds,setExpanedRowIds] = useState([]);
  88. /**
  89. *
  90. * @param {Boolean} bool 弹窗展示状态
  91. */
  92. const updateModalVisibleChange = (bool) => {
  93. handleUpdateModalVisible(bool);
  94. setIfChild(false);
  95. if (!bool) setCurrentRow(undefined);
  96. };
  97. //获取科室列表
  98. const getList = async (params = {}, sort, filter) => {
  99. const res = await getAccountingSubjectList({ ...params, accountType: accountType });
  100. // console.log({res});
  101. return {
  102. data: res.data.list,
  103. total: res.data.totalCount,
  104. success: res.success,
  105. };
  106. };
  107. /**
  108. *
  109. * @param {Object} value 删除项数据
  110. */
  111. const delListHandler = async (value) => {
  112. const resp = await delAccountingSubject(value);
  113. if (resp.status == 200) {
  114. if (actionRef.current) {
  115. actionRef.current.reload();
  116. }
  117. }
  118. };
  119. const expandHandle = id=>{
  120. if(expanedRowIds.includes(id)){
  121. const temp = expanedRowIds;
  122. temp.splice(temp.findIndex(item => item == id), 1);
  123. setExpanedRowIds([...temp])
  124. }else{
  125. setExpanedRowIds([...expanedRowIds,id])
  126. }
  127. }
  128. /**
  129. *
  130. * @param {Object} record record对象
  131. * @param {String} type 可选值[del,edit,‘add’]
  132. */
  133. const customRowUpdata = (record,type)=>{
  134. // console.log({record});
  135. const {accountingCode,accountingName,id} = record;
  136. const needRowData = {accountingCode,accountingName,id};
  137. setIfChild(true);
  138. setCurrentRow(needRowData);
  139. if(type == 'add')handleModalVisible(true);
  140. if(type == 'edit')handleUpdateModalVisible(true);
  141. if(type == 'del')delListHandler(needRowData);
  142. }
  143. //展开table
  144. const expandedRowRender = (record, index, indent, expanded) => {
  145. // console.log({ record, index, indent, expanded });
  146. const { child } = record;
  147. const _columns = columns.filter(item => !(['id', 'option'].includes(item.key)));
  148. return (<table>
  149. <tbody>
  150. {
  151. child&&child.map((item, index) => {
  152. const { accountingCode, accountingName, id, child } = item;
  153. console.log({ accountingCode, accountingName, id, child });
  154. return (
  155. <React.Fragment key={index}>
  156. <tr key={id} style={{ position: 'relative' }}>
  157. <td>
  158. <table>
  159. <tbody>
  160. <tr>
  161. <td style={{ position: 'absolute', width: 0 }}>
  162. {
  163. child&&child.length > 0 &&(
  164. <button onClick={()=>expandHandle(id)} style={{top:12}} className={
  165. expanedRowIds.includes(id)?'ant-table-row-expand-icon ant-table-row-expand-icon-expanded':'ant-table-row-expand-icon ant-table-row-expand-icon-collapsed'
  166. }></button>
  167. )
  168. }
  169. {/* <button className="ant-table-row-expand-icon ant-table-row-expand-icon-expanded customExpandIcon"></button> */}
  170. </td>
  171. <td width="30%" style={{ paddingLeft: '0.8%',paddingTop:10,paddingBottom:10 }}><span style={{transform:'rotateY(180deg)'}}>↵</span>会计科目名称:{accountingName}</td>
  172. <td width="30%" style={{ paddingLeft: '0.3%' }}>会计科目编码:{accountingCode}</td>
  173. <td width="20%" style={{ paddingLeft: '0.7%' }}>否</td>
  174. <td width="15%" style={{ paddingLeft: '0.9%' }}>
  175. <a onClick={()=>customRowUpdata(item,'add')}>添加</a>
  176. <a onClick={()=>customRowUpdata(item,'edit')}>编辑</a>
  177. <a onClick={()=>customRowUpdata(item,'del')}>删除</a>
  178. </td>
  179. </tr>
  180. </tbody>
  181. </table>
  182. </td>
  183. </tr>
  184. {
  185. expanedRowIds.includes(id)&&<tr key={`expand${id}`}>
  186. <td width="100%">
  187. <table>
  188. <tbody>
  189. {
  190. child.map((data, index) => {
  191. const { accountingCode, accountingName, id, child } = data;
  192. return (
  193. <tr key={id} style={{ position: 'relative' }}>
  194. <td style={{ position: 'absolute', width: 0 }}>
  195. {
  196. child&&child.length > 0 && <button class="ant-table-row-expand-icon ant-table-row-expand-icon-collapsed"></button>
  197. }
  198. </td>
  199. <td width="30%" style={{ paddingLeft: '2.5%',paddingTop:10,paddingBottom:10 }}>↵会计科目名称:{accountingName}</td>
  200. <td width="30%" style={{ paddingLeft: '0.3%' }}>会计科目编码:{accountingCode}</td>
  201. <td width="20%" style={{ paddingLeft: '0.7%' }}>否</td>
  202. <td width="15%" style={{ paddingLeft: '0.9%' }}><a >编辑</a></td>
  203. </tr>
  204. )
  205. })
  206. }
  207. </tbody>
  208. </table>
  209. </td>
  210. </tr>
  211. }
  212. </React.Fragment>
  213. )
  214. })
  215. }
  216. </tbody>
  217. </table>
  218. )
  219. };
  220. const onTabChange = (key)=>{
  221. setAccountType(Number(key));
  222. if (actionRef.current) {
  223. actionRef.current.reload();
  224. }
  225. }
  226. useEffect(async () => {
  227. const respForSelecter = await getAccountingSubjectForSelecter();
  228. if (respForSelecter.status == 200) {
  229. setOptions(respForSelecter.data);
  230. }
  231. }, [])
  232. return (
  233. <PageContainer
  234. tabList={[
  235. {
  236. tab: '收益',
  237. key: 1,
  238. },
  239. {
  240. tab: '支出',
  241. key: 2,
  242. },
  243. ]}
  244. onTabChange={onTabChange}
  245. >
  246. <ProTable
  247. columns={columns}
  248. request={getList}
  249. actionRef={actionRef}
  250. rowKey="id"
  251. expandable={{defaultExpandedRowKeys:[]}}
  252. // expandable={{ expandedRowRender }}
  253. toolbar={{
  254. actions: [
  255. <Button
  256. key="button"
  257. icon={<PlusOutlined />}
  258. type="primary"
  259. onClick={() => {
  260. handleModalVisible(true);
  261. }}
  262. >
  263. 新增
  264. </Button>
  265. ],
  266. }}
  267. search={false}
  268. pagination={{
  269. pageSize: 10,
  270. }}
  271. />
  272. <ModalForm
  273. title="新增会计科目"
  274. width="800px"
  275. labelCol={{ span: 5, offset: 3 }}
  276. layout={'horizontal'}
  277. visible={createModalVisible}
  278. onVisibleChange={(bool) => {
  279. if (ref.current) {
  280. ref.current.resetFields();
  281. }
  282. setIfChild(false);
  283. handleModalVisible(bool);
  284. }}
  285. formRef={ref}
  286. onFinish={async (value) => {
  287. let id=0;
  288. currentRow&&(id=currentRow.id)
  289. const success = await addAccountingSubject({ ...value, id:id,accountingType:accountType });
  290. // console.log({ success });
  291. if (success) {
  292. handleModalVisible(false);
  293. if (actionRef.current) {
  294. actionRef.current.reload();
  295. }
  296. }
  297. setCurrentRow(undefined);
  298. }}
  299. >
  300. <ProFormText
  301. label="会计科目编码"
  302. rules={[
  303. {
  304. required: true,
  305. message:'会计科目编码是必填项',
  306. },
  307. ]}
  308. width="sm"
  309. name="accountingCode"
  310. />
  311. <ProFormText
  312. label="会计科目名"
  313. rules={[
  314. {
  315. required: true,
  316. message:'会计科目名是必填项',
  317. },
  318. ]}
  319. width="sm"
  320. name="accountingName"
  321. />
  322. <ProFormSelect
  323. rules={[
  324. {
  325. required: false,
  326. message:'',
  327. },
  328. ]}
  329. options={[
  330. {
  331. value: 0,
  332. label: '不是',
  333. },
  334. {
  335. value: 1,
  336. label: '是',
  337. },
  338. ]}
  339. width="sm"
  340. name="isBaseCode"
  341. label="是否固定成本"
  342. />
  343. </ModalForm>
  344. {/* 更新 */}
  345. <UpdateForm
  346. onSubmit={async (value) => {
  347. // console.log({ '编辑': value });
  348. console.log({currentRow});
  349. const success = await editAccountingSubjectList({...value,accountType});
  350. if (success) {
  351. handleUpdateModalVisible(false);
  352. setCurrentRow(undefined);
  353. if (actionRef.current) {
  354. actionRef.current.reload();
  355. }
  356. }
  357. }}
  358. onCancel={() => {
  359. handleUpdateModalVisible(false);
  360. setCurrentRow(undefined);
  361. }}
  362. updateModalVisible={updateModalVisible}
  363. updateModalVisibleChange={updateModalVisibleChange}
  364. values={currentRow || {}}
  365. />
  366. </PageContainer>
  367. );
  368. };
  369. export default AccountingSubject;