EditGroup.jsx 1.83 KB
Newer Older
Maofei94's avatar
Maofei94 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import React, { useState, useEffect } from 'react';
import { notification, Form, Input } from 'antd';
import SiteModal from '@/components/Modal/SiteModa';
import { setRoleGroupName } from '@/services/userCenter/roleManage/api';
const { Item } = Form;
const EditGroup = props => {
  const { confirmModal, itemObj } = props;
  const [loading, setLoading] = useState(false);
  const [form] = Form.useForm();

  useEffect(() => {
    console.log(itemObj.groupflag, 'flag');
    form.setFieldsValue({
      newName: itemObj.groupflag,
    });
  }, [itemObj]);
  const onSubmit = props => {
    setLoading(true);
皮倩雯's avatar
皮倩雯 committed
19
    console.log(itemObj)
Maofei94's avatar
Maofei94 committed
20 21 22 23 24 25 26
    setRoleGroupName({
      subSystemValue: itemObj.visibleValue || itemObj.subSystemValue,
      oldName: itemObj.groupflag,
      newName: form.getFieldsValue().newName,
    })
      .then(res => {
        setLoading(false);
皮倩雯's avatar
皮倩雯 committed
27
        if (res.code===0) {
Maofei94's avatar
Maofei94 committed
28 29 30 31 32 33 34 35 36 37 38
          form.resetFields();
          notification.success({
            message: '提示',
            duration: 3,
            description: '修改成功',
          });
          confirmModal();
        } else {
          notification.error({
            message: '提示',
            duration: 15,
39
            description: res.msg,
Maofei94's avatar
Maofei94 committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
          });
        }
      })
      .catch(err => {
        setLoading(false);
      });
  };

  return (
    <SiteModal
      {...props}
      title="编辑分组名称"
      bodyStyle={{ width: '100%', minHeight: '50px' }}
      style={{ top: 200 }}
      width="600px"
      destroyOnClose
      cancelText="取消"
      okText="确认"
      onOk={() => onSubmit()}
      confirmLoading={loading}
    >
      <Form form={form} wrapperCol={{ span: 20 }}>
        <Item label="分组名称" name="newName">
          <Input placeholder="请输入分组名称" />
        </Item>
      </Form>
    </SiteModal>
  );
};

export default EditGroup;