index.jsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-09-28 10:11:43
  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 { PageContainer} from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import { ModalForm, ProFormText, ProFormSelect, ProFormDependency } from '@ant-design/pro-form';
  15. import UpdateForm from './updateForm';
  16. import { getDistrictList, editDistrictList, delDistrict, addDistrict,getMainDistrictList } from './service';
  17. const DistrictMana = () => {
  18. const columns = [
  19. {
  20. title: '医院/院区ID',
  21. dataIndex: 'id',
  22. key: 'id',
  23. ellipsis: true,
  24. hideInSearch: true,
  25. },
  26. {
  27. title: '医院名称',
  28. dataIndex: 'name',
  29. key: 'name',
  30. ellipsis: true,
  31. hideInSearch: false,
  32. },
  33. {
  34. title: '是否为主院',
  35. dataIndex: 'isHospital',
  36. key: 'isHospital',
  37. hideInSearch: true,
  38. ellipsis: true,
  39. render: (text) => <a>{text == 0 ? '是' : '否'}</a>,
  40. },
  41. {
  42. title: '医院标识',
  43. dataIndex: 'sign',
  44. key: 'sign',
  45. ellipsis: true,
  46. hideInSearch: true,
  47. },
  48. {
  49. title: '医院Id',
  50. dataIndex: 'parentId',
  51. key: 'parentId',
  52. ellipsis: true,
  53. hideInSearch: true,
  54. },
  55. {
  56. title: '主医院名',
  57. dataIndex: 'parentName',
  58. key: 'parentName',
  59. ellipsis: true,
  60. hideInSearch: true,
  61. },
  62. {
  63. title: '创建时间',
  64. dataIndex: 'createDateTime',
  65. key: 'createDateTime',
  66. ellipsis: true,
  67. hideInSearch: true,
  68. },
  69. {
  70. title:'操作',
  71. dataIndex: 'option',
  72. valueType: 'option',
  73. render: (_, record) => [
  74. <a
  75. key="config"
  76. onClick={() => {
  77. handleUpdateModalVisible(true);
  78. setCurrentRow(record);
  79. }}
  80. >
  81. 编辑
  82. </a>,
  83. <Popconfirm
  84. key="subscribeAlert"
  85. title="是否确定删除?"
  86. onConfirm={() => {
  87. setCurrentRow(record);
  88. delListHandler(record);
  89. }}
  90. >
  91. <a>删除</a>
  92. </Popconfirm>,
  93. ],
  94. },
  95. ];
  96. const [createModalVisible, handleModalVisible] = useState(false);
  97. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  98. const actionRef = useRef();
  99. const ref = useRef(); //新增表单
  100. const [currentRow, setCurrentRow] = useState({});
  101. /**
  102. *
  103. * @param {Boolean} bool 弹窗展示状态
  104. */
  105. const updateModalVisibleChange = (bool) => {
  106. handleUpdateModalVisible(bool);
  107. if (!bool) setCurrentRow(undefined);
  108. };
  109. //获取科室列表
  110. const getList = async (params = {}, sort, filter) => {
  111. const res = await getDistrictList(params);
  112. // console.log({res});
  113. return {
  114. data: res.data.list,
  115. total: res.data.totalCount,
  116. success: res.success,
  117. };
  118. };
  119. /**
  120. *
  121. * @param {Object} value 删除项数据
  122. */
  123. const delListHandler = async (value) => {
  124. const resp = await delDistrict(value);
  125. // console.log({ resp });
  126. if (resp) {
  127. if (actionRef.current) {
  128. actionRef.current.reload();
  129. }
  130. }
  131. };
  132. // useEffect(()=>{
  133. // CARequest('/api/costAccount/hosptail/list');
  134. // },[]);
  135. return (
  136. <PageContainer>
  137. <ProTable
  138. columns={columns}
  139. request={getList}
  140. actionRef={actionRef}
  141. rowKey="id"
  142. toolBarRender={() => [
  143. <Button
  144. key="button"
  145. icon={<PlusOutlined />}
  146. type="primary"
  147. onClick={() => {
  148. handleModalVisible(true);
  149. }}
  150. >
  151. 新增
  152. </Button>
  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. formRef={ref}
  168. visible={createModalVisible}
  169. onVisibleChange={(bool) => {
  170. if (ref.current) {
  171. ref.current.resetFields();
  172. }
  173. handleModalVisible(bool);
  174. }}
  175. onFinish={async (value) => {
  176. const {name,isHospital,id,sign} = value;
  177. const success = await addDistrict(isHospital==0?{
  178. name,isHospital,sign
  179. }:{
  180. name,isHospital,parentId:id
  181. });
  182. // console.log({ success });
  183. if (success) {
  184. handleModalVisible(false);
  185. if (actionRef.current) {
  186. actionRef.current.reload();
  187. }
  188. }
  189. }}
  190. >
  191. <ProFormText
  192. label="医院名"
  193. rules={[
  194. {
  195. required: true,
  196. message:'医院名是必填项',
  197. },
  198. ]}
  199. width="sm"
  200. name="name"
  201. />
  202. <ProFormSelect
  203. rules={[
  204. {
  205. required: true,
  206. message:'请选择是否为主院',
  207. },
  208. ]}
  209. options={[
  210. {
  211. value: 0,
  212. label: '是',
  213. },
  214. {
  215. value: 1,
  216. label: '否',
  217. },
  218. ]}
  219. width="xs"
  220. name="isHospital"
  221. label="是否为主院"
  222. />
  223. <ProFormDependency name={['isHospital']}>
  224. {({ isHospital }) => {
  225. return isHospital == 0 ? (
  226. <ProFormText
  227. label="医院标识"
  228. rules={[
  229. {
  230. required: true,
  231. message:'',
  232. },
  233. ]}
  234. width="sm"
  235. name="sign"
  236. />
  237. ) : <></>;
  238. }}
  239. </ProFormDependency>
  240. <ProFormDependency name={['isHospital']}>
  241. {({ isHospital }) => {
  242. return isHospital == 1 ? (
  243. <ProFormSelect
  244. name="id"
  245. label="选择主医院"
  246. request={async () =>{
  247. const resp = await getMainDistrictList();
  248. if(resp){
  249. return resp.map(item=>({
  250. label:item.name,
  251. value:item.id
  252. }))
  253. }
  254. }}
  255. placeholder=""
  256. width='sm'
  257. rules={[{ required: true, message: '请选择主医院ID' }]}
  258. />
  259. ) : <></>
  260. }}
  261. </ProFormDependency>
  262. </ModalForm>
  263. {/* 更新 */}
  264. <UpdateForm
  265. onSubmit={async (value) => {
  266. // console.log({ '编辑': value });
  267. const success = await editDistrictList(value);
  268. if (success) {
  269. handleUpdateModalVisible(false);
  270. setCurrentRow(undefined);
  271. if (actionRef.current) {
  272. actionRef.current.reload();
  273. }
  274. }
  275. }}
  276. onCancel={() => {
  277. handleUpdateModalVisible(false);
  278. setCurrentRow(undefined);
  279. }}
  280. updateModalVisible={updateModalVisible}
  281. updateModalVisibleChange={updateModalVisibleChange}
  282. values={currentRow || {}}
  283. />
  284. </PageContainer>
  285. );
  286. };
  287. export default DistrictMana;