index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-12 19:19:17
  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, ProFormSelect } from '@ant-design/pro-form';
  16. import UpdateForm from './updateForm';
  17. import CAUpload from '@/components/CAUpload';
  18. import { getUserList, addUser, editUser, delUser,importExcel } from './service';
  19. const UserMana = () => {
  20. const columns = [
  21. {
  22. title: 'Id',
  23. dataIndex: 'id',
  24. key: 'id',
  25. hideInSearch: true,
  26. },
  27. {
  28. title: '姓名',
  29. dataIndex: 'name',
  30. key: 'name',
  31. },
  32. {
  33. title: '用户名',
  34. dataIndex: 'account',
  35. key: 'account',
  36. hideInSearch: true,
  37. },
  38. {
  39. title: '在职状态',
  40. dataIndex: 'hospitalStatus',
  41. key: 'hospitalStatus',
  42. hideInSearch: true,
  43. render: (text) => <>{text == 1 ? '在职' : '离职'}</>,
  44. },
  45. {
  46. title:'操作',
  47. dataIndex: 'option',
  48. valueType: 'option',
  49. render: (_, record) => [
  50. <a
  51. key="config"
  52. onClick={() => {
  53. handleUpdateModalVisible(true);
  54. setCurrentRow(record);
  55. }}
  56. >
  57. 编辑
  58. </a>,
  59. <Popconfirm
  60. key="subscribeAlert"
  61. title="是否确定删除?"
  62. onConfirm={() => {
  63. setCurrentRow(record);
  64. delUserHandler(record);
  65. }}
  66. >
  67. <a>删除</a>
  68. </Popconfirm>,
  69. ],
  70. },
  71. ];
  72. const [createModalVisible, handleModalVisible] = useState(false);
  73. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  74. const actionRef = useRef();
  75. const [currentRow, setCurrentRow] = useState({});
  76. const { initialState, setInitialState } = useModel('@@initialState');
  77. const {currentUser:{token}} = initialState;
  78. // const [shareParamsSetting,setShareParamsSetting] = useState(false); //是否分摊参数设置
  79. /**
  80. *
  81. * @param {Boolean} bool 弹窗展示状态
  82. */
  83. const updateModalVisibleChange = (bool) => {
  84. handleUpdateModalVisible(bool);
  85. if (!bool) setCurrentRow(undefined);
  86. };
  87. //获取用户列表
  88. const getUserlist = async (params = {}, sort, filter) => {
  89. const res = await getUserList(params);
  90. return {
  91. data: res.data.list,
  92. total: res.data.totalCount,
  93. success: res.success,
  94. };
  95. };
  96. /**
  97. *
  98. * @param {Object} value 删除项数据
  99. */
  100. const delUserHandler = async (value) => {
  101. const resp = await delUser(value);
  102. if(resp.msg){
  103. if (actionRef.current) {
  104. actionRef.current.reload();
  105. }
  106. }
  107. };
  108. //自定义上传回调
  109. const customRequestCallback = async (formData)=>{
  110. const resp = await importExcel({formData},{
  111. 'content-type':'multipart/form-data',
  112. })
  113. const {status} = resp;
  114. if(status==200){
  115. if (actionRef.current) {
  116. actionRef.current.reload();
  117. }
  118. }
  119. }
  120. return (
  121. <PageContainer>
  122. <ProTable
  123. columns={columns}
  124. request={getUserlist}
  125. actionRef={actionRef}
  126. rowKey="id"
  127. toolBarRender={() => [
  128. <Button
  129. key="button"
  130. icon={<PlusOutlined />}
  131. type="primary"
  132. onClick={() => {
  133. handleModalVisible(true);
  134. }}
  135. >
  136. 新增
  137. </Button>,
  138. <CAUpload
  139. templateHrefs={'/costAccount/excel/getImportUserTemplate'}
  140. url='/costAccount/excel/importUser'
  141. importSuccessCallback={() =>{}}
  142. token={token}
  143. type='normal'
  144. customRequestCallback={customRequestCallback}
  145. />
  146. ]}
  147. pagination={{
  148. pageSize: 10,
  149. }}
  150. search={{
  151. defaultCollapsed: false,
  152. labelWidth: 'auto',
  153. }}
  154. />
  155. <ModalForm
  156. title="新增人员"
  157. width="800px"
  158. labelCol={{ span: 3, offset: 3 }}
  159. layout={'horizontal'}
  160. visible={createModalVisible}
  161. onVisibleChange={handleModalVisible}
  162. onFinish={async (value) => {
  163. const success = await addUser(value);
  164. // console.log({ success });
  165. if (success) {
  166. handleModalVisible(false);
  167. if (actionRef.current) {
  168. actionRef.current.reload();
  169. }
  170. }
  171. }}
  172. >
  173. <ProFormText
  174. label="姓名"
  175. rules={[
  176. {
  177. required: true,
  178. message:'人员名是必填项',
  179. },
  180. ]}
  181. width="sm"
  182. name="name"
  183. />
  184. <ProFormText
  185. label="账户"
  186. rules={[
  187. {
  188. required: true,
  189. message:'账户名是必填项',
  190. },
  191. ]}
  192. width="sm"
  193. name="account"
  194. />
  195. <ProFormText
  196. label="密码不修改留空"
  197. rules={[
  198. {
  199. required: false,
  200. message:'',
  201. },
  202. ]}
  203. width="sm"
  204. name="password"
  205. />
  206. <ProFormSelect
  207. options={[
  208. {
  209. value: 0,
  210. label: '离职',
  211. },
  212. {
  213. value: 1,
  214. label: '在职',
  215. },
  216. ]}
  217. width="sm"
  218. name="hospitalStatus"
  219. label="在职状态"
  220. />
  221. </ModalForm>
  222. {/* 更新 */}
  223. <UpdateForm
  224. onSubmit={async (value) => {
  225. // console.log({value});
  226. const success = await editUser(value);
  227. if (success) {
  228. handleUpdateModalVisible(false);
  229. setCurrentRow(undefined);
  230. if (actionRef.current) {
  231. actionRef.current.reload();
  232. }
  233. }
  234. }}
  235. onCancel={() => {
  236. handleUpdateModalVisible(false);
  237. setCurrentRow(undefined);
  238. }}
  239. updateModalVisible={updateModalVisible}
  240. updateModalVisibleChange={updateModalVisibleChange}
  241. values={currentRow || {}}
  242. />
  243. </PageContainer>
  244. );
  245. };
  246. export default UserMana;