广州市综治平台前端
xusd
8 days ago 544148eddae96db824423cd059ebecb9d13c392e
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
/*
 * @Company: hugeInfo
 * @Author: lwh
 * @Date: 2024-12-11 15:26:38
 * @LastEditTime: 2024-12-12 15:04:58
 * @LastEditors: lwh
 * @Version: 1.0.0
 * @Description: 
 */
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Spin, Typography } from 'antd';
import { Modal } from '@arco-design/web-react';
import { register } from '@/assets/images';
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 [personData, setPersonData] = useState();
 
  const [visible, setVisible] = useState(false);
 
  const [spin, setSpin] = useState(false);
 
 
  useEffect(() => {
    // 获取数据
    async function getData() {
      if (!userId) return;
      setSpin(true);
      const res = await getDataApi(userId);
      setSpin(false);
      if (res.type) setPersonData(res.data || {});
    }
    if (visible && !personData) getData();
  }, [visible, personData, userId]);
 
 
  return !!userId ? (
    <>
      <Text verticalAlign='middle' onClick={() => setVisible(true)} style={{ cursor: 'pointer', display: 'flex', alignItems: 'center' }}><span>{name || '-'}</span><img src={register} alt='' style={{ width: '14px', height: '14px', marginLeft: '8px' }} /></Text>
      <Modal visible={visible} onCancel={() => { setVisible(false) }} title='工作人员信息' centered footer={null}>
        <>
          {userId ? (
            <Spin spinning={spin}>
              <table border="1" align="center" cellpadding="5" className="table">
                <tr>
                  <th bgcolor="#F7F8FA" className="table-title" width="120">姓名</th>
                  <td width='380'><div style={{ display: 'flex' }}><div>{personData?.trueName}</div></div></td>
                  <th bgcolor="#F7F8FA" className="table-title" width="120">登录账号</th>
                  <td width='380'>{personData?.acc}</td>
                </tr>
                <tr>
                  <th bgcolor="#F7F8FA" className="table-title">手机号码</th>
                  <td>{personData?.mobile}</td>
                  <th bgcolor="#F7F8FA" className="table-title">工作电话</th>
                  <td>-</td>
                </tr>
                <tr>
                  <th bgcolor="#F7F8FA" className="table-title">所属部门</th>
                  <td>{personData?.unitName}</td>
                  <th bgcolor="#F7F8FA" className="table-title">职务</th>
                  <td>{personData?.userRoles}</td>
                </tr>
              </table>
            </Spin>
          ) : (
            '无详情内容'
          )}
        </>
 
      </Modal>
    </>
    // <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;