index.js 6.5 KB

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