广州矛调粤政易端
xusd
7 days ago d27794814b69d18aeb8ee96a46cae91d5613570c
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-08-10 18:33:51
 * @LastEditTime: 2023-08-03 14:38:45
 * @LastEditors: dminyi 1301963064@qq.com
 * @Version: 1.0.0
 * @Description: 描述列表
 */
import React, { useState } from 'react';
import { RightArrow2Outlined } from 'dd-icons';
import { Space } from 'dingtalk-design-mobile';
import { idcard, address, person1, person2 } from '../../assets/img';
import ImgShow from '../../components/ImgShow';
import { ellipsis, showToast } from '../../utils/utility';
 
/**
 * data: array, [{label:"",value:""}], // 数据
 * columns: number, // 展示的列数
 * title: string, // 标题
 * extra: ReactNode, // 标题右侧的操作区自定义
 * topRightActionVisible: bool, // 是否展示标题右侧区域
 * onTopRightAction: func, // 点击标题右侧区域方法回调
 * layout: string, // horizontal , vertical
 * colon: bool, // 是否有冒号
 * textGap: number, // 文字的间距
 * itemGap: number, // col之间的间距
 */
const Descriptions = ({
  data = [],
  otherData = [],
  columns = 2,
  title,
  extra,
  topRightActionVisible = false,
  onTopRightAction = null,
  layout = 'horizontal',
  colon = true,
  textGap = 6,
  itemGap = 4,
}) => {
  const width = 100 / columns;
  const [visibles, setVisibles] = useState([]); //显示隐藏引导气泡
 
  // 显隐
  function handleVisible(index, visible) {
    setVisibles(() => {
      const tmp = new Array(data.length || []).fill(false);
      if (!visible) {
        return tmp;
      } else {
        tmp.splice(index, 1, visible);
        return tmp;
      }
    })
  }
 
  function typeChange(x) {
    switch (x.type) {
      case 'idcard':
        return (
          <div className="descriptions-card  descriptions-card-blue">
            <div className="descriptions-card-avatar descriptions-card-avatar-blue">
              <img className="descriptions-card-img" src={idcard} alt="" />
            </div>
            <div className="roomDetail-msgCard-content">
              <Space align="center">
                <span>{x.title}</span>
              </Space>
              <div className="roomDetail-msgCard-content-desc">
                <span>{x.cardType}</span>
                <span className="public-rightBorder">{x.contents}</span>
              </div>
            </div>
          </div>
        );
      case 'address':
        return (
          <div className="descriptions-card  descriptions-card-orange">
            <div className="descriptions-card-avatar descriptions-card-avatar-orange">
              <img className="descriptions-card-img" src={address} alt="" />
            </div>
            <div className="roomDetail-msgCard-content">
              <Space align="center">
                <span>{x.title}</span>
              </Space>
              <div className="roomDetail-msgCard-content-desc">
                <span>户籍详址:{x.contents}</span>
              </div>
            </div>
          </div>
        );
      case 'abroad':
        return (
          <div className="descriptions-card  descriptions-card-orange">
            <div className="descriptions-card-avatar descriptions-card-avatar-orange">
              <img className="descriptions-card-img" src={address} alt="" />
            </div>
            <div className="roomDetail-msgCard-content">
              <Space align="center">
                <span>{x.title}</span>
              </Space>
              <div className="roomDetail-msgCard-content-desc">
                <span>来华目的:{x.contents}</span>
              </div>
            </div>
          </div>
        );
      case 'files':
        return (
          <div className="descriptions-card-files">
            {x.files?.map((x, t) => (
              <div className="descriptions-card-files-item" key={t}>
                <ImgShow fileType={x.type || '22_00017-3'} img={x.showUrl} allImg={x.files} title={x.name} />
              </div>
            ))}
            {(x.files || []).length === 0 && (
              <div className="descriptions-card-files-item">
                <ImgShow />
              </div>
            )}
          </div>
        );
      // 综治相关信息
      case 'children':
        return (
          <div className="descriptions-card-ssim  descriptions-card-red">
            <div className="descriptions-card-ssim-title">综治9+X</div>
            <div className="roomDetail-msgCard-content" style={{ marginTop: '20px' }}>
              <Space align="center">
                <span>{x.title}</span>
              </Space>
              <div className="roomDetail-msgCard-content-desc">
                <span>留守类型:{x.contents}</span>
              </div>
            </div>
            <div className="descriptions-card-ssim-avatar descriptions-card-ssim-avatar-red">
              <img className="descriptions-card-ssim-img" src={person1} alt="" />
            </div>
          </div>
        );
      // 综治相关信息
      case 'teenager':
        return (
          <div className="descriptions-card-ssim  descriptions-card-red">
            <div className="descriptions-card-ssim-title">综治9+X</div>
            <div className="roomDetail-msgCard-content" style={{ marginTop: '20px' }}>
              <Space align="center">
                <span>{x.title}</span>
              </Space>
              <div className="roomDetail-msgCard-content-desc">
                <span>{x.teenagerTypeDesc ? (x.teenagerTypeDesc.substring(0, 5) + (x.teenagerTypeDesc.length > 5 ? '...' : '')) : ''}</span>
                <span className="public-rightBorder">{x.teenagerFamilyDesc ? (x.teenagerFamilyDesc.substring(0, 5) + (x.teenagerFamilyDesc.length > 5 ? '...' : '')) : ''}</span>
                <span className="public-rightBorder">{x.teenagerHelpDesc ? (x.teenagerHelpDesc.substring(0, 5) + (x.teenagerHelpDesc.length > 5 ? '...' : '')) : ''}</span>
              </div>
            </div>
            <div className="descriptions-card-ssim-avatar descriptions-card-ssim-avatar-red">
              <img className="descriptions-card-ssim-img" src={person2} alt="" />
            </div>
          </div>
        );
      case 'build':
        return;
      default:
        return;
    }
  }
 
  return (
    <>
      {title && (
        <div className="descriptions-title">
          <div className="descriptions-title-left">{title || '标题'}</div>
          {!!extra
            ? extra
            : topRightActionVisible && (
              <div className="descriptions-title-right" onClick={onTopRightAction}>
                <span>修改信息</span>
                <RightArrow2Outlined />
              </div>
            )}
        </div>
      )}
      {otherData.map((x, t) => {
        return <React.Fragment key={t}>{typeChange(x)}</React.Fragment>;
      })}
      {data?.length > 0 && (
        <div className="descriptions-grid" style={{ marginTop: `-${itemGap}px` }}>
          {data.map((x, t) => {
            return (
              <div style={{ maxWidth: `${x.width || width}%`, flex: `0 0 ${x.width || width}%`, marginTop: itemGap + 'px' }} key={t}>
                <div className="descriptions-grid-col" style={{ flexDirection: layout === 'horizontal' ? 'row' : 'column' }}>
                  <div className="descriptions-grid-col-left" style={{ margin: layout === 'horizontal' ? `0 ${textGap}px 0 0` : `0 0 ${textGap}px` }}>
                    {x.label}
                    {colon && ':'}
                  </div>
                  {
                    x.value && x.value.length < 32 ?
                      <pre className="descriptions-grid-col-right">{x.value ? ellipsis(x.value, 32) : '-'}</pre> :
                      <pre onClick={() => showToast.msg({ content: x.value, showType: 'line' })} className="descriptions-grid-col-right">{x.value ? ellipsis(x.value, 32) : '-'}</pre>
                  }
                </div>
              </div>
            );
          })}
        </div>
      )}
    </>
  );
};
 
export default Descriptions;