123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import React, { useRef, useEffect, useState } from 'react';
- import { Button, Card, Form, Input, Select } from 'antd';
- import useBool from '@/utils/hooks/useBool';
- import { getSysPosition, postSysPosition, putSysPosition, getSysPositionById } from "@/service/sysposition";
- import { useSearchParams, useNavigate } from 'react-router-dom';
-
- const formItemLayout = {
- labelCol: {
- xs: { span: 24 },
- sm: { span: 8 },
- },
- wrapperCol: {
- xs: { span: 24 },
- sm: { span: 16 },
- },
- };
- const tailFormItemLayout = {
- wrapperCol: {
- xs: {
- span: 24,
- offset: 0,
- },
- sm: {
- span: 16,
- offset: 8,
- },
- },
- };
-
- const { Option } = Select;
- export default (props) => {
-
- const [loading, startLoading, cancelLoading] = useBool();
- const [submiting, startSubmit, cancelSubmit] = useBool();
- const [form] = Form.useForm();
- const navigate = useNavigate();
- const actionRef = useRef();
- const [searchParams, setSearchParams] = useSearchParams();
- const id = searchParams.get("id");
- const [sysPositionList, setSysPositionList] = useState([]);
-
- useEffect(() => {
- if (id) {
- getSysPositionById(id).then((res) => {
- form.setFieldsValue(res);
- });
- }
- }, [id]);
-
- useEffect(() => {
- getSysPosition({ pageSize: 999 }).then((res) => {
- console.log('res', res.records);
- setSysPositionList(res.records);
- })
- }, [])
-
- const onFinish = (values) => {
- startSubmit();
- console.log('fff', id);
- if (id) {
-
- // 修改
- putSysPosition(id, values).then((res) => {
- navigate(-1);
- }).catch(() => {
- cancelSubmit();
- });
- } else {
- // 新增
- postSysPosition(values).then((res) => {
- navigate(-1);
- }).catch(() => {
- cancelSubmit();
- });
- }
- }
-
-
- console.log('tiantian', sysPositionList);
-
-
- return (
- <Card loading={loading}>
- <Form onFinish={onFinish} form={form} {...formItemLayout} scrollToFirstError style={{ maxWidth: '1000px' }}>
- <Form.Item
- name="name"
- label="岗位名称"
- >
- <Input />
- </Form.Item>
- <Form.Item
- name="positionPId"
- label="上级岗位"
- >
- <Input />
- </Form.Item>
- <Form.Item
- name="orgId"
- label="所属单位"
- >
- <Select allowClear>
- {sysPositionList.map((item) => (
- <Option value={item.positionId} key={item.positionId}>
- {item.orgId}
- </Option>
- ))}
- </Select>
- </Form.Item>
- <Form.Item
- name="sortNum"
- label="排序"
- >
- <Input />
- </Form.Item>
- <Form.Item
- name="status"
- label="状态"
- >
- <Select
- style={{ width: '100%' }}
- placeholder="请选择状态"
- >
- <Option value={0}>不正常</Option>
- <Option value={1}>正常</Option>
- </Select>
- </Form.Item>
- <Form.Item {...tailFormItemLayout}>
- <Button loading={submiting} type="primary" htmlType="submit">
- 保存
- </Button>
- <Button style={{ marginLeft: '2em' }} onClick={() => navigate(-1)}>
- 返回
- </Button>
- </Form.Item>
- </Form>
- </Card>
- )
- }
-
-
|