123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React, { useRef, useEffect, useState } from 'react';
  2. import { Button, Card, Form, Input, Select } from 'antd';
  3. import useBool from '@/utils/hooks/useBool';
  4. import { getSysPosition, postSysPosition, putSysPosition, getSysPositionById } from "@/service/sysposition";
  5. import { useSearchParams, useNavigate } from 'react-router-dom';
  6. const formItemLayout = {
  7. labelCol: {
  8. xs: { span: 24 },
  9. sm: { span: 8 },
  10. },
  11. wrapperCol: {
  12. xs: { span: 24 },
  13. sm: { span: 16 },
  14. },
  15. };
  16. const tailFormItemLayout = {
  17. wrapperCol: {
  18. xs: {
  19. span: 24,
  20. offset: 0,
  21. },
  22. sm: {
  23. span: 16,
  24. offset: 8,
  25. },
  26. },
  27. };
  28. const { Option } = Select;
  29. export default (props) => {
  30. const [loading, startLoading, cancelLoading] = useBool();
  31. const [submiting, startSubmit, cancelSubmit] = useBool();
  32. const [form] = Form.useForm();
  33. const navigate = useNavigate();
  34. const actionRef = useRef();
  35. const [searchParams, setSearchParams] = useSearchParams();
  36. const id = searchParams.get("id");
  37. const [sysPositionList, setSysPositionList] = useState([]);
  38. useEffect(() => {
  39. if (id) {
  40. getSysPositionById(id).then((res) => {
  41. form.setFieldsValue(res);
  42. });
  43. }
  44. }, [id]);
  45. useEffect(() => {
  46. getSysPosition({ pageSize: 999 }).then((res) => {
  47. console.log('res', res.records);
  48. setSysPositionList(res.records);
  49. })
  50. }, [])
  51. const onFinish = (values) => {
  52. startSubmit();
  53. console.log('fff', id);
  54. if (id) {
  55. // 修改
  56. putSysPosition(id, values).then((res) => {
  57. navigate(-1);
  58. }).catch(() => {
  59. cancelSubmit();
  60. });
  61. } else {
  62. // 新增
  63. postSysPosition(values).then((res) => {
  64. navigate(-1);
  65. }).catch(() => {
  66. cancelSubmit();
  67. });
  68. }
  69. }
  70. console.log('tiantian', sysPositionList);
  71. return (
  72. <Card loading={loading}>
  73. <Form onFinish={onFinish} form={form} {...formItemLayout} scrollToFirstError style={{ maxWidth: '1000px' }}>
  74. <Form.Item
  75. name="name"
  76. label="岗位名称"
  77. >
  78. <Input />
  79. </Form.Item>
  80. <Form.Item
  81. name="positionPId"
  82. label="上级岗位"
  83. >
  84. <Input />
  85. </Form.Item>
  86. <Form.Item
  87. name="orgId"
  88. label="所属单位"
  89. >
  90. <Select allowClear>
  91. {sysPositionList.map((item) => (
  92. <Option value={item.positionId} key={item.positionId}>
  93. {item.orgId}
  94. </Option>
  95. ))}
  96. </Select>
  97. </Form.Item>
  98. <Form.Item
  99. name="sortNum"
  100. label="排序"
  101. >
  102. <Input />
  103. </Form.Item>
  104. <Form.Item
  105. name="status"
  106. label="状态"
  107. >
  108. <Select
  109. style={{ width: '100%' }}
  110. placeholder="请选择状态"
  111. >
  112. <Option value={0}>不正常</Option>
  113. <Option value={1}>正常</Option>
  114. </Select>
  115. </Form.Item>
  116. <Form.Item {...tailFormItemLayout}>
  117. <Button loading={submiting} type="primary" htmlType="submit">
  118. 保存
  119. </Button>
  120. <Button style={{ marginLeft: '2em' }} onClick={() => navigate(-1)}>
  121. 返回
  122. </Button>
  123. </Form.Item>
  124. </Form>
  125. </Card>
  126. )
  127. }