index.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-30 15:57:46
  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} from 'react';
  12. import { useModel } from 'umi';
  13. import { PageContainer } from '@ant-design/pro-layout';
  14. import ProTable from '@ant-design/pro-table';
  15. import { ModalForm, ProFormText} 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 CostProjectMana = () => {
  23. const columns = [
  24. {
  25. title: 'Id',
  26. dataIndex: 'id',
  27. key: 'id',
  28. hideInTable: true,
  29. hideInSearch: true,
  30. },
  31. {
  32. title: '成本编号',
  33. dataIndex: 'productCode',
  34. key: 'productCode',
  35. hideInSearch: true,
  36. },
  37. {
  38. title: '成本项目名',
  39. dataIndex: 'productName',
  40. key: 'productName',
  41. hideInSearch: false,
  42. },
  43. {
  44. title:'操作',
  45. dataIndex: 'option',
  46. valueType: 'option',
  47. render: (_, record) => [
  48. <a
  49. key="config"
  50. onClick={() => {
  51. handleUpdateModalVisible(true);
  52. setCurrentRow(record);
  53. }}
  54. >
  55. 编辑
  56. </a>,
  57. <Popconfirm
  58. key="subscribeAlert"
  59. title="是否确定删除?"
  60. onConfirm={() => {
  61. setCurrentRow(record);
  62. delListHandler(record);
  63. }}
  64. >
  65. <a>删除</a>
  66. </Popconfirm>,
  67. ],
  68. },
  69. ];
  70. const [createModalVisible, handleModalVisible] = useState(false);
  71. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  72. const actionRef = useRef(); //表格
  73. const ref = useRef(); //新增表单
  74. const [currentRow, setCurrentRow] = useState({});
  75. const { initialState, setInitialState } = useModel('@@initialState');
  76. const {currentUser:{token}} = initialState;
  77. /**
  78. *
  79. * @param {Boolean} bool 弹窗展示状态
  80. */
  81. const updateModalVisibleChange = (bool) => {
  82. handleUpdateModalVisible(bool);
  83. if (!bool) setCurrentRow(undefined);
  84. };
  85. //获取科室列表
  86. const getList = async (params = {}, sort, filter) => {
  87. const res = await getCostProjecttList(params);
  88. return {
  89. data: res.data.list,
  90. total: res.data.totalCount,
  91. success: res.success,
  92. };
  93. };
  94. /**
  95. *
  96. * @param {Object} value 删除项数据
  97. */
  98. const delListHandler = async (value) => {
  99. const resp = await delCostProject(value);
  100. if (resp.status == 200) {
  101. if (actionRef.current) {
  102. actionRef.current.reload();
  103. }
  104. }
  105. };
  106. //自定义上传回调
  107. /**
  108. *
  109. * @param {FormData} formData
  110. */
  111. const customRequestCallback = async (formData)=>{
  112. const resp = await importExcel({formData},{
  113. 'content-type':'multipart/form-data',
  114. })
  115. const {status} = resp;
  116. if(status==200){
  117. if (actionRef.current) {
  118. actionRef.current.reload();
  119. }
  120. }
  121. }
  122. return (
  123. <PageContainer>
  124. <ProTable
  125. columns={columns}
  126. request={getList}
  127. actionRef={actionRef}
  128. rowKey="id"
  129. toolBarRender={() => [
  130. <Button
  131. key="button"
  132. icon={<PlusOutlined />}
  133. type="primary"
  134. onClick={() => {
  135. handleModalVisible(true);
  136. }}
  137. >
  138. 新增
  139. </Button>,
  140. <CAUpload
  141. templateHref={'/costAccount/excel/getImportProductTemplate'}
  142. url='/costAccount/excel/importProduct'
  143. importSuccessCallback={() => { }}
  144. token={token}
  145. customRequestCallback={customRequestCallback}
  146. />
  147. ]}
  148. pagination={{
  149. pageSize: 10,
  150. }}
  151. search={{
  152. defaultCollapsed: false,
  153. labelWidth: 'auto',
  154. }}
  155. />
  156. <ModalForm
  157. title="新增成本项目"
  158. width="800px"
  159. labelCol={{ span: 5, offset: 3 }}
  160. layout={'horizontal'}
  161. visible={createModalVisible}
  162. formRef={ref}
  163. onVisibleChange={(bool) => {
  164. if (ref.current) {
  165. ref.current.resetFields();
  166. }
  167. handleModalVisible(bool);
  168. }}
  169. onFinish={async (value) => {
  170. const success = await addCostProject(value);
  171. // console.log({ success });
  172. if (success) {
  173. handleModalVisible(false);
  174. if (actionRef.current) {
  175. actionRef.current.reload();
  176. }
  177. }
  178. }}
  179. >
  180. <ProFormText
  181. label="成本项目编码"
  182. rules={[
  183. {
  184. required: true,
  185. message:'成本项目编码是必填项',
  186. },
  187. ]}
  188. width="sm"
  189. name="productCode"
  190. />
  191. <ProFormText
  192. label="成本项目名"
  193. rules={[
  194. {
  195. required: true,
  196. message:'成本项目名是必填项',
  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 CostProjectMana;