index.jsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-02 18:55:53
  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, message, Input, Drawer } 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 { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form';
  16. import UpdateForm from './updateForm';
  17. import CAUpload from '@/components/CAUpload';
  18. import { getDepartmentList ,editDepartmentList,delDepartment,addDepartment,importExcel} from './service';
  19. const DepartmentMana = () => {
  20. const columns = [
  21. {
  22. title: 'ID',
  23. dataIndex: 'id',
  24. key: 'name',
  25. hideInSearch: true,
  26. render: (text) => <a>{text}</a>,
  27. },
  28. {
  29. title: '科室名',
  30. dataIndex: 'departmentName',
  31. key: 'departmentName',
  32. hideInSearch: false,
  33. },
  34. {
  35. title: '科室编号',
  36. dataIndex: 'departmentCode',
  37. key: 'departmentCode',
  38. hideInSearch: false,
  39. },
  40. // {
  41. // title: '医院Id',
  42. // dataIndex: 'hospId',
  43. // key: 'hospId',
  44. // hideInSearch: true,
  45. // },
  46. {
  47. title: '创建时间',
  48. dataIndex: 'createDateTime',
  49. key: 'createTime',
  50. hideInSearch: true,
  51. },
  52. {
  53. title: <FormattedMessage id="pages.searchTable.titleOption" defaultMessage="Operating" />,
  54. dataIndex: 'option',
  55. valueType: 'option',
  56. render: (_, record) => [
  57. <a
  58. key="config"
  59. onClick={() => {
  60. handleUpdateModalVisible(true);
  61. console.log({ record });
  62. setCurrentRow(record);
  63. }}
  64. >
  65. 编辑
  66. </a>,
  67. <Popconfirm
  68. key="subscribeAlert"
  69. title="是否确定删除?"
  70. onConfirm={() => {
  71. setCurrentRow(record);
  72. delListHandler(record);
  73. }}
  74. >
  75. <a>删除</a>
  76. </Popconfirm>,
  77. ],
  78. },
  79. ];
  80. const [createModalVisible, handleModalVisible] = useState(false);
  81. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  82. const actionRef = useRef();
  83. const [currentRow, setCurrentRow] = useState({});
  84. const { initialState, setInitialState } = useModel('@@initialState');
  85. const {currentUser:{token}} = initialState;
  86. /**
  87. *
  88. * @param {Boolean} bool 弹窗展示状态
  89. */
  90. const updateModalVisibleChange = (bool) => {
  91. handleUpdateModalVisible(bool);
  92. if (!bool) setCurrentRow(undefined);
  93. };
  94. //获取科室列表
  95. const getList = async (params = {}, sort, filter) => {
  96. const res = await getDepartmentList(params);
  97. // console.log({res});
  98. return {
  99. data: res.data.list,
  100. total: res.data.totalCount,
  101. success: res.success,
  102. };
  103. };
  104. /**
  105. *
  106. * @param {Object} value 删除项数据
  107. */
  108. const delListHandler = async (value) => {
  109. const resp = await delDepartment(value);
  110. if(resp.status==200){
  111. if (actionRef.current) {
  112. actionRef.current.reload();
  113. }
  114. }
  115. };
  116. //自定义上传回调
  117. const customRequestCallback = async (formData)=>{
  118. const resp = await importExcel({formData},{
  119. // 'content-type': 'application/json'
  120. 'content-type':'multipart/form-data',
  121. })
  122. if(status==200){
  123. if (actionRef.current) {
  124. actionRef.current.reload();
  125. }
  126. }
  127. }
  128. return (
  129. <PageContainer>
  130. <ProTable
  131. columns={columns}
  132. request={getList}
  133. actionRef={actionRef}
  134. rowKey="id"
  135. toolBarRender={() => [
  136. <Button
  137. key="button"
  138. icon={<PlusOutlined />}
  139. type="primary"
  140. onClick={() => {
  141. handleModalVisible(true);
  142. }}
  143. >
  144. 新增
  145. </Button>,
  146. <CAUpload
  147. templateHref={'/costAccount/excel/getDepartmentTemplate'}
  148. url='/costAccount/excel/importDepartment'
  149. importSuccessCallback={() =>{}}
  150. token={token}
  151. customRequestCallback={customRequestCallback}
  152. />
  153. ]}
  154. pagination={{
  155. pageSize: 10,
  156. }}
  157. search={{
  158. defaultCollapsed: false,
  159. labelWidth: 'auto',
  160. }}
  161. />
  162. <ModalForm
  163. title="新增科室"
  164. width="800px"
  165. labelCol={{ span: 3, offset: 3 }}
  166. layout={'horizontal'}
  167. visible={createModalVisible}
  168. onVisibleChange={handleModalVisible}
  169. onFinish={async (value) => {
  170. const success = await addDepartment(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. <FormattedMessage id="pages.searchTable.departmentName" defaultMessage="科室名是必填项" />
  187. ),
  188. },
  189. ]}
  190. width="sm"
  191. name="departmentName"
  192. />
  193. <ProFormText
  194. label="科室编号"
  195. rules={[
  196. {
  197. required: true,
  198. message: (
  199. <FormattedMessage id="pages.searchTable.departmentCode" defaultMessage="科室编号是必填项" />
  200. ),
  201. },
  202. ]}
  203. width="sm"
  204. name="departmentCode"
  205. />
  206. </ModalForm>
  207. {/* 更新 */}
  208. <UpdateForm
  209. onSubmit={async (value) => {
  210. console.log({'编辑':value});
  211. const success = await editDepartmentList(value);
  212. if (success) {
  213. handleUpdateModalVisible(false);
  214. setCurrentRow(undefined);
  215. if (actionRef.current) {
  216. actionRef.current.reload();
  217. }
  218. }
  219. }}
  220. onCancel={() => {
  221. handleUpdateModalVisible(false);
  222. setCurrentRow(undefined);
  223. }}
  224. updateModalVisible={updateModalVisible}
  225. updateModalVisibleChange={updateModalVisibleChange}
  226. values={currentRow || {}}
  227. />
  228. </PageContainer>
  229. );
  230. };
  231. export default DepartmentMana;