Blame view

src/pages/Client/FollowRecord/Components/CommunicationHistoryModal.tsx 10.5 KB
1
2
3
4
5
6
7
8
import ClientModal from '@/pages/Client/FollowRecord/Components/ClientModal';
import {
  postAdminClientQueryClientComunicationInfo,
  postAdminClientRemoveClientComunicationInfo,
} from '@/services/request';
import { ModalForm } from '@ant-design/pro-components';
import { Button, Descriptions, Space } from 'antd';
import { useEffect, useRef, useState } from 'react';
9
import '../index.less';
10
11
12
13
14
15
16
17

export default ({ data, reloadTable }) => {
  // const [isModalVisible, setIsModalVisible] = useState(false); // 控制 ClientModal 的显示
  const actionRef = useRef(); // 引用 actionRef,方便调用 reload 方法

  const [datetime, setDatetime] = useState(); // 跟进日期
  const [createByName, setCreateByName] = useState(''); // 跟进人员
  const [clientName, setClientName] = useState(''); // 客户名称
18
19
  const [way, setWay] = useState(); // 跟进方式
  const [tradeStatusText, setTradeStatusText] = useState(); // 状态
20
21
  const [content, setContent] = useState(''); // 跟进详情
  const [createTime, setCreateTime] = useState(null); // 创建时间
22
23
  const [attachments, setAttachments] = useState(); //附件
  const [attachmentsName, setAttachmentsName] = useState(''); // 附件名称
boyang authored
24
  const [comment, setComment] = useState(''); // 客户评价
25
26
27
28
29
30
31
  useEffect(() => {
    const request = async () => {
      const res = await postAdminClientQueryClientComunicationInfo({
        data: {
          id: data.id,
        },
      });
boyang authored
32
33
34
35
36
      // const resTicket = await getOrderErpTicketsGetTicketsByClientId({
      //   query: {
      //     id: data.id,
      //   },
      // });
37
38
39
40
41
      // data.type = resTicket.data.type;
      // data.detailText = resTicket.data.detailText;
      // data.annexUrl = resTicket.data.annexUrl;
      // data.assignPeople = resTicket.data.assignPeople;
      // console.log(resTicket, '5656resTicket');
42
      // const dataSearch = res.data.data[0];
43
44
      const dataSearch = res.data.data[0];
      if (dataSearch) {
boyang authored
45
46
47
48
        // data.type = resTicket.data.type;
        // data.detailText = resTicket.data.detailText;
        // data.annexUrl = resTicket.data.annexUrl;
        // data.assignPeople = resTicket.data.assignPeople;
49
50
51
52
53
54
55
56
57
58
59
60
        if (dataSearch.attachments) {
          const url = dataSearch.attachments;
          const match = url.match(/aliyuncs\.com\/(.*?)\?/);
          let decodedStr = '';

          if (match) {
            // 获取匹配的字符串并进行解码
            const encodedStr = match[1];
            decodedStr = decodeURIComponent(encodedStr);
            setAttachmentsName(decodedStr); // 设置跟进日期
          }
        }
61
62
63
64
65
66
67
68
69
70
71
72
        // if (dataSearch.ticketAttachments) {
        //   const url = dataSearch.attachments;
        //   const match = url.match(/aliyuncs\.com\/(.*?)\?/);
        //   let decodedStr = '';

        //   if (match) {
        //     // 获取匹配的字符串并进行解码
        //     const encodedStr = match[1];
        //     decodedStr = decodeURIComponent(encodedStr);
        //     setTicketsAttachmentName(decodedStr); // 设置跟进日期
        //   }
        // }
boyang authored
73
74
        setComment(dataSearch.comment);
        setComment(dataSearch.comment);
75
76
77
78
79
80
81
82
        setDatetime(dataSearch.datetime); // 设置跟进日期
        // setDateRange(data.dateRange || []); // 设置跟进时间范围
        setCreateByName(dataSearch.createByName); // 设置跟进人员
        setClientName(dataSearch.clientName); // 设置客户名称
        // setClientAddress(data.clientAddress || ''); // 设置客户地址
        // setClientNameLike(data.clientNameLike || ''); // 设置客户名称模糊查询
        // setClientAddressLike(data.clientAddressLike || ''); // 设置客户地址模糊查询
        // setTradeStatus(data.tradeStatus || ''); // 设置客户状态
83
        setTradeStatusText(data.tradeStatusLike || ''); // 设置客户状态模糊查询
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
        setContent(dataSearch.content); // 设置跟进详情
        setCreateTime(dataSearch.createTime); // 设置创建时间
        setWay(dataSearch.wayText);
        setAttachments(dataSearch.attachments);
      }
    };
    request();
  }, []);
  const items = [
    {
      key: '1',
      label: '跟进日期',
      children: datetime, // 跟进日期
    },
    {
      key: '2',
      label: '跟进人员',
      children: createByName, // 跟进人员
    },
    {
      key: '3',
      label: '客户名称',
      children: clientName, // 客户名称
    },
    {
      key: '4',
      label: '跟进详情',
      children: content, // 跟进详情
    },
    {
      key: '5',
      label: '创建时间',
      children: createTime, // 创建时间
    },
    {
      key: '6',
120
121
122
123
124
125
126
127
128
129
      label: '跟进方式',
      children: way, // 跟进方式
    },
    {
      key: '7',
      label: '跟进状态',
      children: tradeStatusText, // 跟进状态
    },
    {
      key: '8',
boyang authored
130
131
132
      label: '客户评价',
      children: comment, // 跟进状态
    },
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    // {
    //   key: '9',
    //   label: '工单类型',
    //   children: ticketsType, // 跟进状态
    // },
    // {
    //   key: '10',
    //   label: '工单详情',
    //   children: ticketsDetail, // 跟进状态
    // },
    // {
    //   key: '11',
    //   label: '指派人员',
    //   children: assignPeople, // 跟进状态
    // },
148
149
150
151
152
153
154
155
156
157
158
159
160
  ];
  const handleDelete = async () => {
    // 调用删除接口
    const success = await postAdminClientRemoveClientComunicationInfo({
      query: {
        id: data.id,
      },
    });
    // setIsModalVisible(false);
    if (success) {
      actionRef?.current?.reload(); // 重新加载表格数据
    }
  };
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
  const TicketDescriptions = ({ data }) => {
    return (
      <div>
        {data.ticketsList && data.ticketsList.length > 0 ? (
          data.ticketsList.map((ticket, index) => (
            <div key={index} style={{ marginBottom: '20px' }}>
              <Descriptions title={`工单 ${index + 1}`} column={1}>
                <Descriptions.Item label="工单类型">
                  {ticket.typeText}
                </Descriptions.Item>
                <Descriptions.Item label="工单详情">
                  {ticket.detailText}
                </Descriptions.Item>
                <Descriptions.Item label="指派人员">
                  {ticket.assignPeople}
                </Descriptions.Item>
              </Descriptions>
              {ticket.annexUrl && (
                <a
                  href={ticket.annexUrl}
                  target="_blank"
                  rel="noopener noreferrer"
                >
                  下载工单附件
                </a>
              )}
            </div>
          ))
        ) : (
          <p></p>
        )}
      </div>
    );
  };
195
196
197
  return (
    <Space>
      <ModalForm
198
        className="client-index"
199
        title="跟进记录"
200
        trigger={<Button type="primary">查看</Button>}
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
        submitter={{
          resetButtonProps: {
            style: {
              display: 'none',
            },
          },
          submitButtonProps: {
            style: {
              display: 'none',
            },
          },
          render: (props, defaultDoms) => {
            return [
              ...defaultDoms,
              <>
                <ClientModal
                  key={'modify'}
218
                  // data={data} // 将表单数据传递给 ClientModal
219
                  data={data} // 传递修改后的 data
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
                  reloadTable={() => {
                    actionRef?.current?.reload(); // 重新加载表格数据
                    props.submit();
                    reloadTable();
                  }}
                  type={'modify'}
                  onFinish={() => {
                    // setIsModalVisible(false);
                  }} // 关闭 Modal
                  style={{ marginRight: '10px' }}
                />
                <Button
                  key={'delete'}
                  onClick={() => {
                    handleDelete();
                    props.submit();
                    reloadTable();
                  }}
                  type="primary"
                  size="middle"
                  danger // 使用 danger 属性来将按钮颜色设置为红色
                  style={{ marginLeft: '10px' }}
                  onFinish={() => {
                    actionRef.current.reload();
                  }}
                >
                  删除
                </Button>
              </>,
            ];
          },
        }}
        onFinish={async () => {
          // 提交成功后,显示 ClientDrawer
          // setIsModalVisible(true);
          return true;
        }}
      >
        <Descriptions items={items} column={1} />
259
260
261
262
263
264
265
266
        {attachmentsName && (
          <div>
            {attachmentsName.endsWith('.png') ||
            attachmentsName.endsWith('.jpg') ? (
              <>
                <img
                  src={attachments}
                  alt={attachmentsName}
267
                  style={{ maxWidth: '300px', height: 'auto' }}
268
269
270
271
272
273
274
275
276
277
278
279
280
                />
                <div></div>
                <a href={attachments} download>
                  附件:{attachmentsName}
                </a>
              </>
            ) : (
              <a href={attachments} download>
                附件:{attachmentsName}
              </a>
            )}
          </div>
        )}
281
282
283
284
285
286
287
288
289
290
291
292
        <TicketDescriptions data={data} />
        {/* {attachmentsName && (
          <a href={attachments} download>
            附件:{attachmentsName}
          </a>
        )}
        <div></div>
        {ticketsAttachment && (
          <a href={ticketsAttachment} download>
            工单附件:{ticketsAttachment}
          </a>
        )} */}
293
294
295
296
297
298
299

        <div></div>
        {/* {ticketsAttachment && (
          <a href={ticketsAttachment} download>
            工单附件:{ticketsAttachment}
          </a>
        )} */}
boyang authored
300
        {/* {ticketsAttachment && (
301
302
          <div>
            {ticketsAttachment.includes('jpg') ||
boyang authored
303
              ticketsAttachment.includes('png') ? (
304
305
306
307
              <>
                <img
                  src={ticketsAttachment}
                  alt={ticketsAttachment}
308
                  style={{ maxWidth: '300px', height: 'auto' }}
309
310
311
312
313
314
315
316
317
318
319
320
                />
                <div></div>
                <a href={ticketsAttachment} download>
                  工单附件:{ticketsAttachment}
                </a>
              </>
            ) : (
              <a href={ticketsAttachment} download>
                工单附件:{ticketsAttachment}
              </a>
            )}
          </div>
boyang authored
321
        )} */}
322
323
324
325
      </ModalForm>
    </Space>
  );
};