forked from gzzfw/frontEnd/gzDyh

liuwh
2024-09-10 4e3b493f07b4bc7f325a4b8ebc91704ec8e902a9
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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-03-15 16:39:25
 * @LastEditTime: 2022-11-03 09:26:13
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: 姓名卡片
 */
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Popover, Space, Spin, Typography } from 'antd';
import { UserOutlined, ApartmentOutlined, HistoryOutlined } from '@ant-design/icons';
import * as $$ from '../../utils/utility';
import './index.less';
 
const { Text } = Typography;
 
// 获取数据
function getDataApi(submitData) {
    return $$.ax.request({ url: `ctUser/getByIdRole?id=${submitData}`, type: 'get', service: 'cust' });
}
 
const NameCard = ({ name, userId }) => {
    const [popoverVisible, setPopoverVisible] = useState(false);
 
    const [data, setData] = useState();
 
    const [spin, setSpin] = useState(false);
 
    useEffect(() => {
        // 获取数据
        async function getData() {
            if (!userId) return;
            setSpin(true);
            const res = await getDataApi(userId);
            setSpin(false);
            if (res.type) setData(res.data || {});
        }
        if (popoverVisible && !data) getData();
    }, [popoverVisible, data, userId]);
 
    const content = userId ? (
        <Spin spinning={spin}>
            <div className="nameCard-content">
                <Space direction="vertical">
                    <Space>
                        <UserOutlined />
                        <span>
                            <span>{data?.trueName || '-'}</span>
                            <span className="public-rightBorder">{data?.mobile || '-'}</span>
                        </span>
                    </Space>
                    <Space>
                        <ApartmentOutlined />
                        <span>
                            <span>
                                {data?.unitName || '-'} {data?.deptName || '-'}
                            </span>
                            <span className="public-rightBorder">{data?.userRoles || '-'}</span>
                        </span>
                    </Space>
                    <Space>
                        <HistoryOutlined />
                        <span>最近一次登录:{$$.dateFormat(data?.loginTime)}</span>
                    </Space>
                </Space>
            </div>
        </Spin>
    ) : (
        '无详情内容'
    );
 
    return !!userId ? (
        <Popover
            overlayClassName="nameCard"
            placement="right"
            visible={popoverVisible}
            title={null}
            content={content}
            trigger="click"
            onVisibleChange={(visible) => setPopoverVisible(visible)}
        >
            <span className={`${popoverVisible && 'nameCard-name-active'} nameCard-name`} onClick={() => setPopoverVisible(true)}>
                <span>{name}</span>
            </span>
        </Popover>
    ) : (
        <Text style={{ maxWidth: '200px' }} ellipsis={{ tooltip: name }}>
            {name}
        </Text>
    );
};
 
NameCard.propTypes = {
    name: PropTypes.any,
    userId: PropTypes.string,
};
 
export default NameCard;