Form.jsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React from "react";
  2. import { Button, Form, Input, Select } from "antd";
  3. import useBool from "@/utils/hooks/useBool";
  4. import { postTdLine, putTdLine } from "@/service/tdLine";
  5. import { formItemLayout, tailFormItemLayout } from "@/utils/form";
  6. export default (props) => {
  7. const { row, list, parentId, onChange } = props;
  8. const [submiting, startSubmit, cancelSubmit] = useBool();
  9. const [form] = Form.useForm();
  10. const onFinish = (values) => {
  11. startSubmit();
  12. if (row?.lineId) {
  13. // 修改
  14. putTdLine(row?.lineId, values)
  15. .then((res) => {
  16. cancelSubmit();
  17. onChange(res);
  18. })
  19. .catch(() => {
  20. cancelSubmit();
  21. });
  22. } else {
  23. // 新增
  24. postTdLine(values)
  25. .then((res) => {
  26. cancelSubmit();
  27. onChange(res);
  28. })
  29. .catch(() => {
  30. cancelSubmit();
  31. });
  32. }
  33. };
  34. React.useEffect(() => {
  35. form.resetFields();
  36. if (row) {
  37. form.setFieldsValue(row);
  38. }
  39. form.setFieldValue("parentId", parentId);
  40. }, [row, parentId]);
  41. return (
  42. <Form
  43. form={form}
  44. {...formItemLayout}
  45. style={{ maxWidth: "800px" }}
  46. onFinish={onFinish}
  47. >
  48. <Form.Item
  49. name="lineName"
  50. label="条线名称"
  51. rules={[{ required: true, message: "请填写条线名称" }]}
  52. getValueFromEvent={(e) => e.target.value.replace(/(^\s*)|(\s*$)/g, "")}
  53. >
  54. <Input />
  55. </Form.Item>
  56. {/* <Form.Item
  57. name="orgCode"
  58. label="机构号"
  59. rules={[{ required: true, message: "请填写机构号" }]}
  60. getValueFromEvent={(e) => e.target.value.replace(/(^\s*)|(\s*$)/g, "")}
  61. >
  62. <Input />
  63. </Form.Item> */}
  64. <Form.Item name="parentId" label="上级单位">
  65. <Select disabled={true}>
  66. {(list || []).map((x) => (
  67. <Select.Option key={x.lineId}>{x.lineName}</Select.Option>
  68. ))}
  69. </Select>
  70. </Form.Item>
  71. <Form.Item name="status" label="状态">
  72. <Select style={{ width: "100%" }} placeholder="请选择状态">
  73. <Select.Option value={0}>不正常</Select.Option>
  74. <Select.Option value={1}>正常</Select.Option>
  75. </Select>
  76. </Form.Item>
  77. {/* <Form.Item name="isSeven" label="7天全班">
  78. <Select style={{ width: "100%" }} placeholder="请选择">
  79. <Select.Option value={0}>否</Select.Option>
  80. <Select.Option value={1}>是</Select.Option>
  81. </Select>
  82. </Form.Item> */}
  83. <Form.Item {...tailFormItemLayout}>
  84. <Button loading={submiting} type="primary" htmlType="submit">
  85. 保存
  86. </Button>
  87. </Form.Item>
  88. </Form>
  89. );
  90. };