index.jsx 12 KB

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