index.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-02 19:00:33
  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, Cascader } from 'antd';
  11. import React, { useState, useRef, useEffect } from 'react';
  12. import { useIntl, FormattedMessage,useModel } from 'umi';
  13. import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
  14. import ProTable from '@ant-design/pro-table';
  15. import ProForm, { ModalForm, ProFormText, ProFormSelect, ProFormTextArea } from '@ant-design/pro-form';
  16. import UpdateForm from './updateForm';
  17. import CAUpload from '@/components/CAUpload';
  18. import {
  19. getCostProjecttList, editCostProject, delCostProject,
  20. addCostProject,importExcel
  21. } from './service';
  22. const DepartmentMana = () => {
  23. const columns = [
  24. {
  25. title: 'Id',
  26. dataIndex: 'id',
  27. key: 'id',
  28. hideInSearch: true,
  29. },
  30. {
  31. title: '成本编号',
  32. dataIndex: 'productCode',
  33. key: 'productCode',
  34. hideInSearch: true,
  35. },
  36. {
  37. title: '成本项目名',
  38. dataIndex: 'productName',
  39. key: 'productName',
  40. hideInSearch: false,
  41. },
  42. {
  43. title: <FormattedMessage id="pages.searchTable.titleOption" defaultMessage="Operating" />,
  44. dataIndex: 'option',
  45. valueType: 'option',
  46. render: (_, record) => [
  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. },
  68. ];
  69. const [createModalVisible, handleModalVisible] = useState(false);
  70. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  71. const actionRef = useRef(); //表格
  72. const ref = useRef(); //新增表单
  73. const [currentRow, setCurrentRow] = useState({});
  74. const { initialState, setInitialState } = useModel('@@initialState');
  75. const {currentUser:{token}} = initialState;
  76. /**
  77. *
  78. * @param {Boolean} bool 弹窗展示状态
  79. */
  80. const updateModalVisibleChange = (bool) => {
  81. handleUpdateModalVisible(bool);
  82. if (!bool) setCurrentRow(undefined);
  83. };
  84. //获取科室列表
  85. const getList = async (params = {}, sort, filter) => {
  86. const res = await getCostProjecttList(params);
  87. return {
  88. data: res.data.list,
  89. total: res.data.totalCount,
  90. success: res.success,
  91. };
  92. };
  93. /**
  94. *
  95. * @param {Object} value 删除项数据
  96. */
  97. const delListHandler = async (value) => {
  98. const resp = await delCostProject(value);
  99. if (resp.status == 200) {
  100. if (actionRef.current) {
  101. actionRef.current.reload();
  102. }
  103. }
  104. };
  105. //自定义上传回调
  106. const customRequestCallback = async (formData)=>{
  107. const resp = await importExcel({formData},{
  108. // 'content-type': 'application/json'
  109. 'content-type':'multipart/form-data',
  110. })
  111. const {status} = resp;
  112. if(status==200){
  113. if (actionRef.current) {
  114. actionRef.current.reload();
  115. }
  116. }
  117. }
  118. return (
  119. <PageContainer>
  120. <ProTable
  121. columns={columns}
  122. request={getList}
  123. actionRef={actionRef}
  124. rowKey="id"
  125. toolBarRender={() => [
  126. <Button
  127. key="button"
  128. icon={<PlusOutlined />}
  129. type="primary"
  130. onClick={() => {
  131. handleModalVisible(true);
  132. }}
  133. >
  134. 新增
  135. </Button>,
  136. <CAUpload
  137. templateHref={'/costAccount/excel/getImportProductTemplate'}
  138. url='/costAccount/excel/importProduct'
  139. importSuccessCallback={() => { }}
  140. token={token}
  141. customRequestCallback={customRequestCallback}
  142. />
  143. ]}
  144. pagination={{
  145. pageSize: 10,
  146. }}
  147. search={{
  148. defaultCollapsed: false,
  149. labelWidth: 'auto',
  150. }}
  151. />
  152. <ModalForm
  153. title="新增成本项目"
  154. width="800px"
  155. labelCol={{ span: 5, offset: 3 }}
  156. layout={'horizontal'}
  157. visible={createModalVisible}
  158. formRef={ref}
  159. onVisibleChange={(bool) => {
  160. if (ref.current) {
  161. ref.current.resetFields();
  162. }
  163. handleModalVisible(bool);
  164. }}
  165. onFinish={async (value) => {
  166. const success = await addCostProject(value);
  167. // console.log({ success });
  168. if (success) {
  169. handleModalVisible(false);
  170. if (actionRef.current) {
  171. actionRef.current.reload();
  172. }
  173. }
  174. }}
  175. >
  176. <ProFormText
  177. label="成本项目编码"
  178. rules={[
  179. {
  180. required: true,
  181. message: (
  182. <FormattedMessage id="pages.searchTable.productCode" defaultMessage="成本项目编码是必填项" />
  183. ),
  184. },
  185. ]}
  186. width="sm"
  187. name="productCode"
  188. />
  189. <ProFormText
  190. label="成本项目名"
  191. rules={[
  192. {
  193. required: true,
  194. message: (
  195. <FormattedMessage id="pages.searchTable.productName" defaultMessage="成本项目名是必填项" />
  196. ),
  197. },
  198. ]}
  199. width="sm"
  200. name="productName"
  201. />
  202. </ModalForm>
  203. {/* 更新 */}
  204. <UpdateForm
  205. onSubmit={async (value) => {
  206. // console.log({ '编辑': value });
  207. const success = await editCostProject(value);
  208. if (success) {
  209. handleUpdateModalVisible(false);
  210. setCurrentRow(undefined);
  211. if (actionRef.current) {
  212. actionRef.current.reload();
  213. }
  214. }
  215. }}
  216. onCancel={() => {
  217. handleUpdateModalVisible(false);
  218. setCurrentRow(undefined);
  219. }}
  220. updateModalVisible={updateModalVisible}
  221. updateModalVisibleChange={updateModalVisibleChange}
  222. values={currentRow || {}}
  223. />
  224. </PageContainer>
  225. );
  226. };
  227. export default DepartmentMana;