BasicForm.jsx 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, { useState, useEffect } from 'react';
  2. import { Link, useNavigate } from 'react-router-dom';
  3. import { Button, Row, Col, Form, Input, InputNumber, DatePicker, notification } from 'antd';
  4. import { addGuaranteeTask, updateGuaranteeTask } from '@/services/guaranteeTask';
  5. import moment from 'moment';
  6. const { TextArea } = Input;
  7. const { RangePicker } = DatePicker;
  8. export default (props) => {
  9. const { dataSource, setDataSource } = props;
  10. const id = dataSource ? dataSource.id : undefined;
  11. const navigate = useNavigate();
  12. const [form] = Form.useForm();
  13. const [rangeDate, setRangeDate] = useState([]);
  14. const [loading, setLoading] = useState(false);
  15. const onChange = (dts) => {
  16. const [start, end] = dts;
  17. setRangeDate(dts);
  18. form.setFieldValue('startDate', start ? start.format('YYYY-MM-DD') : undefined);
  19. form.setFieldValue('endDate', end ? end.format('YYYY-MM-DD') : undefined);
  20. }
  21. const onFinish = values => {
  22. const notNull = Object.keys(values).map(k => values[k]).filter(Boolean);
  23. if (!notNull || notNull.length < 1) {
  24. notification.warn({ message: '未检索到填写内容' });
  25. return ;
  26. }
  27. const [start, end] = rangeDate;
  28. const startDate = start ? start.format('YYYY-MM-DD') : undefined;
  29. const endDate = end ? end.format('YYYY-MM-DD') : undefined;
  30. const func = id ? updateGuaranteeTask : addGuaranteeTask;
  31. setLoading(true);
  32. func({ ...values, startDate, endDate }, id).then(res => {
  33. setLoading(false);
  34. setDataSource(res);
  35. // notification.success({ message: '操作成功' })
  36. }).catch(() => {
  37. setLoading(false);
  38. });
  39. }
  40. useEffect(() => {
  41. if (dataSource) {
  42. form.setFieldsValue(dataSource);
  43. let rangeDt = [];
  44. if (dataSource.startDate) {
  45. rangeDt[0] = moment(dataSource.startDate);
  46. }
  47. if (dataSource.endDate) {
  48. rangeDt[1] = moment(dataSource.endDate);
  49. }
  50. setRangeDate(rangeDt);
  51. }
  52. }, [dataSource, form]);
  53. return (
  54. <Form layout="vertical" form={form} onFinish={onFinish}>
  55. <h3 style={{ marginBottom: '1.5em', fontWeight: 700 }}>人员安排</h3>
  56. <Row gutter={48}>
  57. <Col span={6}>
  58. <Form.Item label="受领人" name="receiver">
  59. <Input allowClear />
  60. </Form.Item>
  61. </Col>
  62. <Col span={6}>
  63. <Form.Item label="受领人电话" name="receiverPhone">
  64. <Input allowClear />
  65. </Form.Item>
  66. </Col>
  67. <Col span={6}>
  68. <Form.Item label="部队联系人" name="concatPerson">
  69. <Input allowClear />
  70. </Form.Item>
  71. </Col>
  72. <Col span={6}>
  73. <Form.Item label="部队联系人电话" name="concatPhone">
  74. <Input allowClear />
  75. </Form.Item>
  76. </Col>
  77. </Row>
  78. <Row gutter={48}>
  79. <Col span={6}>
  80. <Form.Item label="制餐人" name="chef">
  81. <Input allowClear />
  82. </Form.Item>
  83. </Col>
  84. <Col span={6}>
  85. <Form.Item label="制餐人电话" name="chefPhone">
  86. <Input allowClear />
  87. </Form.Item>
  88. </Col>
  89. <Col span={6}>
  90. <Form.Item label="送餐人" name="deliveryMan">
  91. <Input allowClear />
  92. </Form.Item>
  93. </Col>
  94. <Col span={6}>
  95. <Form.Item label="送餐人电话" name="deliveryPhone">
  96. <Input allowClear />
  97. </Form.Item>
  98. </Col>
  99. </Row>
  100. <h3 style={{ margin: '1.5em 0', fontWeight: 700 }}>基本情况</h3>
  101. <Row gutter={48}>
  102. <Col span={6}>
  103. <Form.Item label="军代表" name="deputyMan">
  104. <Input allowClear />
  105. </Form.Item>
  106. </Col>
  107. <Col span={6}>
  108. <Form.Item label="电话" name="deputyPhone">
  109. <Input allowClear />
  110. </Form.Item>
  111. </Col>
  112. <Col span={6}>
  113. <Form.Item label="通报时间" name="gotDate">
  114. <Input allowClear />
  115. </Form.Item>
  116. </Col>
  117. </Row>
  118. <Row gutter={48}>
  119. <Col span={6}>
  120. <Form.Item label="保障序号" name="guaranteeNo">
  121. <Input allowClear />
  122. </Form.Item>
  123. </Col>
  124. <Col span={6}>
  125. <Form.Item label="军运号" name="transportNo">
  126. <Input allowClear />
  127. </Form.Item>
  128. </Col>
  129. <Col span={6}>
  130. <Form.Item label="车次" name="tripsNo">
  131. <Input allowClear />
  132. </Form.Item>
  133. </Col>
  134. </Row>
  135. <Row gutter={48}>
  136. <Col span={12}>
  137. <Form.Item label="保障日期">
  138. <RangePicker
  139. style={{ width: '100%' }}
  140. allowClear
  141. value={rangeDate}
  142. onChange={onChange}
  143. />
  144. </Form.Item>
  145. </Col>
  146. <Col span={6}>
  147. <Form.Item label="保障时间" name="timeRange">
  148. <Input allowClear />
  149. </Form.Item>
  150. </Col>
  151. </Row>
  152. <Row gutter={48}>
  153. <Col span={6}>
  154. <Form.Item label="保障人数" name="totalPersonNum">
  155. <InputNumber min={1} style={{ width: '100%' }}/>
  156. </Form.Item>
  157. </Col>
  158. <Col span={6}>
  159. <Form.Item label="其中回民" name="huiPersonNum">
  160. <InputNumber min={0} style={{ width: '100%' }}/>
  161. </Form.Item>
  162. </Col>
  163. <Col span={6}>
  164. <Form.Item label="其中病号" name="patientNum">
  165. <InputNumber min={0} style={{ width: '100%' }}/>
  166. </Form.Item>
  167. </Col>
  168. </Row>
  169. <Row gutter={48}>
  170. <Col span={12}>
  171. <Form.Item label="保障地点" name="address">
  172. <Input allowClear />
  173. </Form.Item>
  174. </Col>
  175. <Col span={6}>
  176. <Form.Item label="伙食标准" name="standard">
  177. <Input allowClear />
  178. </Form.Item>
  179. </Col>
  180. </Row>
  181. <Row gutter={48}>
  182. <Col span={12}>
  183. <Form.Item label="备注" name="remark">
  184. <TextArea rows={4} />
  185. </Form.Item>
  186. </Col>
  187. </Row>
  188. <Row gutter={48}>
  189. <Col offset={6} span={12}>
  190. <Button type="primary" htmlType="submit" loading={loading}>提交</Button>
  191. <Button style={{ marginLeft: '48px' }} onClick={() => navigate(-1)}>返回</Button>
  192. <Button style={{ marginLeft: '48px' }} disabled={!id}>
  193. <a target="_blank" href={`${window.location.pathname}#/task/guaranteeTask/print?id=${id}`}>打印预览</a>
  194. </Button>
  195. </Col>
  196. </Row>
  197. </Form>
  198. )
  199. }