广州市综治平台前端
xusd
2025-06-07 ee685c9f350ec9241107d4e8a05799768a0bce9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-03-02 16:05:31
 * @LastEditTime: 2022-10-31 12:02:37
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 岗位列表modal
 */
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Modal, Button, Input, Popconfirm, Typography } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import TableView from '../../TableView';
import * as $$ from '../../../utils/utility';
 
const PostModal = ({ data, visible, handleDel, handleAdd, handleCancel }) => {
    // 岗位名称
    const [postName, setPostName] = useState('');
 
    // addType
    const [addType, setAddType] = useState('1');
 
    // 是否新增岗位
    const [isAdd, setIsAdd] = useState(false);
 
    function handleAddPost(type) {
        if (!postName || postName.length > 32) {
            $$.info({ type: 'error', content: '岗位数据无效,请重新输入' });
            return false;
        }
        setAddType(type);
        handleAdd(postName);
    }
 
    useEffect(() => {
        if (addType === '1') {
            setIsAdd(false);
        } else {
            setPostName('');
        }
    }, [data.length]);
 
    return (
        <Modal width={600} visible={visible} title="岗位列表" onCancel={handleCancel} footer={false}>
            {isAdd ? (
                <div>
                    <Input
                        placeholder="请输入岗位名称"
                        value={postName}
                        style={{ width: '200px', marginRight: '8px' }}
                        onChange={(e) => setPostName(e.target.value)}
                    />
                    <Button className="public-buttonMargin" onClick={() => setIsAdd(false)}>
                        取消
                    </Button>
                    <Button className="public-buttonMargin" onClick={() => handleAddPost('2')}>
                        新增并继续
                    </Button>
                    <Button type="primary" onClick={() => handleAddPost('1')}>
                        新增
                    </Button>
                </div>
            ) : (
                <Button
                    icon={<PlusOutlined />}
                    type="primary"
                    onClick={() => {
                        setPostName('');
                        setIsAdd(true);
                    }}
                >
                    新增
                </Button>
            )}
            <TableView
                style={{ marginTop: '16px' }}
                columns={[
                    { title: '岗位', dataIndex: 'name' },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        render: (_, record) => {
                            return (
                                <Popconfirm title="是否确认删除该岗位?" onConfirm={() => handleDel(record.id)}>
                                    <Typography.Link>删除</Typography.Link>
                                </Popconfirm>
                            );
                        },
                    },
                ]}
                dataSource={data}
                bordered
                pagination={false}
                scroll={{ y: 500 }}
            />
        </Modal>
    );
};
 
PostModal.propTypes = {
    data: PropTypes.array,
    visible: PropTypes.bool,
    handleDel: PropTypes.func,
    handleAdd: PropTypes.func,
    handleCancel: PropTypes.func,
};
 
export default PostModal;