addDiag.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, {
  2. useState, useEffect, useContext
  3. } from 'react';
  4. import { Form, Input, Select, Button, Switch, TreeSelect, message, Space } from 'antd';
  5. import apiObj from '@api/index';
  6. import { getCookie,setCookie } from '@utils/index';
  7. import DiagContext from './Diag-context';
  8. import { useSelector } from 'react-redux'
  9. import Item from 'antd/lib/list/Item';
  10. const { post, api } = apiObj;
  11. const { TextArea } = Input;
  12. function AddDiag(props) {
  13. const [form] = Form.useForm();
  14. const { type, formData} = useContext(DiagContext);
  15. const staticInfo = useSelector(state => {
  16. return state.staticInfo;
  17. });
  18. const initialValues = formData;
  19. const onFinish = values => {
  20. values.status ? values.status=1:values.status=0
  21. let params = values
  22. if (type == 3) {
  23. params.id=initialValues.id
  24. upDiseaseById(params)
  25. } else {
  26. addDisease(params)
  27. }
  28. };
  29. function addDisease(param) {
  30. const hisId = getCookie("hospitalId");
  31. const params ={
  32. hospitalId:hisId,
  33. ...param
  34. }
  35. post(api.addDisease, params).then((res) => {
  36. if (res.data.code === 200) {
  37. props.DiagChange()
  38. message.success(res.data.message);
  39. } else {
  40. message.error(res.data.message);
  41. }
  42. })
  43. }
  44. function upDiseaseById(param) {
  45. const hisId = getCookie("hospitalId");
  46. const params ={
  47. hospitalId:hisId,
  48. ...param
  49. }
  50. post(api.upDiseaseById, params).then((res) => {
  51. if (res.data.code === 200) {
  52. props.DiagChange()
  53. message.success(res.data.message);
  54. } else {
  55. message.error(res.data.message);
  56. }
  57. })
  58. }
  59. function cancel() {
  60. props.cancel()
  61. }
  62. function onValuesChange() {
  63. props.isChange(form.isFieldsTouched())
  64. }
  65. return (
  66. <>
  67. <Form
  68. labelCol={{ span: 6 }}
  69. wrapperCol={{ span: 16 }}
  70. form={form}
  71. name="register"
  72. onFinish={onFinish}
  73. initialValues={initialValues}
  74. onValuesChange={onValuesChange}
  75. >
  76. <Form.Item
  77. name="name"
  78. label="医院诊断名称"
  79. rules={[
  80. {
  81. required: true,
  82. message: '请输入医院诊断名称',
  83. },
  84. ]}
  85. >
  86. {type == 3 ?
  87. <Input autoComplete='off'/>
  88. :
  89. <Input placeholder="请输入医院诊断名称" autoComplete='off'/>
  90. }
  91. </Form.Item>
  92. <Form.Item
  93. name="code"
  94. label="code"
  95. rules={[
  96. {
  97. required: true,
  98. message: '请输入code',
  99. },
  100. ]}
  101. >
  102. {type == 3 ?
  103. <Input autoComplete='off'/>
  104. :
  105. <Input placeholder="请输入code" autoComplete='off'/>
  106. }
  107. </Form.Item>
  108. <Form.Item
  109. name="icd10"
  110. label="ICD-10编码:"
  111. >
  112. {type == 3 ?
  113. <Input autoComplete='off'/>
  114. :
  115. <Input placeholder="请输入ICD-10编码:" autoComplete='off'/>
  116. }
  117. </Form.Item>
  118. <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
  119. <Space size="middle">
  120. <Button htmlType="button" onClick={e => cancel()}>
  121. 取消
  122. </Button>
  123. <Button type="primary" htmlType="submit">
  124. 保存
  125. </Button>
  126. </Space>
  127. </Form.Item>
  128. </Form>
  129. </>
  130. );
  131. }
  132. export default AddDiag;