addSurg.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { useContext} from 'react';
  2. import { Form, Input, Button, message, Space } from 'antd';
  3. import apiObj from '@api/index';
  4. import { getCookie,setCookie } from '@utils/index';
  5. import SurgContext from './surg-context';
  6. const { post, api } = apiObj;
  7. function AddSurg(props) {
  8. const [form] = Form.useForm();
  9. const { type, formData} = useContext(SurgContext);
  10. const initialValues = formData;
  11. const onFinish = values => {
  12. values.status ? values.status=1:values.status=0
  13. let params = values
  14. if (type == 3) {
  15. params.id=initialValues.id
  16. upSurgById(params)
  17. } else {
  18. addSurg(params)
  19. }
  20. };
  21. function addSurg(param) {
  22. const hisId = getCookie("hospitalId");
  23. const params ={
  24. hospitalId:hisId,
  25. ...param
  26. }
  27. post(api.addOperation, params).then((res) => {
  28. if (res.data.code === 200) {
  29. props.SurgChange()
  30. message.success(res.data.message);
  31. } else {
  32. message.error(res.data.message);
  33. }
  34. })
  35. }
  36. function upSurgById(param) {
  37. const hisId = getCookie("hospitalId");
  38. const params ={
  39. hospitalId:hisId,
  40. ...param
  41. }
  42. post(api.upOperationById, params).then((res) => {
  43. if (res.data.code === 200) {
  44. props.SurgChange()
  45. message.success(res.data.message);
  46. } else {
  47. message.error(res.data.message);
  48. }
  49. })
  50. }
  51. function cancel() {
  52. props.cancel()
  53. }
  54. function onValuesChange() {
  55. props.isChange(form.isFieldsTouched())
  56. }
  57. return (
  58. <>
  59. <Form
  60. labelCol={{ span: 7 }}
  61. wrapperCol={{ span: 16 }}
  62. form={form}
  63. name="register"
  64. onFinish={onFinish}
  65. initialValues={initialValues}
  66. onValuesChange={onValuesChange}
  67. >
  68. <Form.Item
  69. name="name"
  70. label="医院手术/操作名称"
  71. rules={[
  72. {
  73. required: true,
  74. message: '请输入医院手术/操作名称',
  75. },
  76. ]}
  77. >
  78. {type == 3 ?
  79. <Input autoComplete='off'/>
  80. :
  81. <Input placeholder="请输入" autoComplete='off'/>
  82. }
  83. </Form.Item>
  84. <Form.Item
  85. name="code"
  86. label="手术和操作代码"
  87. rules={[
  88. {
  89. required: true,
  90. message: '请输入手术和操作代码',
  91. },
  92. ]}
  93. >
  94. {type == 3 ?
  95. <Input autoComplete='off'/>
  96. :
  97. <Input placeholder="请输入" autoComplete='off'/>
  98. }
  99. </Form.Item>
  100. <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
  101. <Space size="middle">
  102. <Button htmlType="button" onClick={e => cancel()}>
  103. 取消
  104. </Button>
  105. <Button type="primary" htmlType="submit">
  106. 保存
  107. </Button>
  108. </Space>
  109. </Form.Item>
  110. </Form>
  111. </>
  112. );
  113. }
  114. export default AddSurg;