Blame view

src/pages/Client/FollowRecord/Components/CommunicationHistoryModal.tsx 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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';

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(''); // 客户名称
  // const [clientAddress, setClientAddress] = useState(''); // 客户地址
18
19
  const [way, setWay] = useState(); // 跟进方式
  const [tradeStatusText, setTradeStatusText] = useState(); // 状态
20
21
22
23
24
25
  // const [clientNameLike, setClientNameLike] = useState(''); // 客户名称模糊查询
  // const [clientAddressLike, setClientAddressLike] = useState(''); // 客户地址模糊查询
  // const [tradeStatus, setTradeStatus] = useState(''); // 客户状态
  // const [tradeStatusLike, setTradeStatusLike] = useState(''); // 客户状态模糊查询
  const [content, setContent] = useState(''); // 跟进详情
  const [createTime, setCreateTime] = useState(null); // 创建时间
26
27
  const [attachments, setAttachments] = useState(); //附件
  const [attachmentsName, setAttachmentsName] = useState(''); // 附件名称
28
29
  const [ticketsType, setTicketsType] = useState(''); // 附件名称
  const [ticketsDetail, setTicketsDetail] = useState(''); // 附件名称
boyang authored
30
  const [ticketsAttachment, setTicketsAttachment] = useState(); // 附件名称
31
  // const [ticketsAttachmentName, setTicketsAttachmentName] = useState(''); // 附件名称
boyang authored
32
  const [comment, setComment] = useState(''); // 客户评价
33
  const [assignPeople, setAssignPeople] = useState(''); // 附件名称
34
35
  useEffect(() => {
    const request = async () => {
36
      console.log(data, '5656datatatatata');
37
38
39
40
41
      const res = await postAdminClientQueryClientComunicationInfo({
        data: {
          id: data.id,
        },
      });
boyang authored
42
43
44
45
46
      // const resTicket = await getOrderErpTicketsGetTicketsByClientId({
      //   query: {
      //     id: data.id,
      //   },
      // });
47
48
49
50
51
      // data.type = resTicket.data.type;
      // data.detailText = resTicket.data.detailText;
      // data.annexUrl = resTicket.data.annexUrl;
      // data.assignPeople = resTicket.data.assignPeople;
      // console.log(resTicket, '5656resTicket');
52
      // const dataSearch = res.data.data[0];
53
54
      const dataSearch = res.data.data[0];
      if (dataSearch) {
boyang authored
55
56
57
58
        // data.type = resTicket.data.type;
        // data.detailText = resTicket.data.detailText;
        // data.annexUrl = resTicket.data.annexUrl;
        // data.assignPeople = resTicket.data.assignPeople;
59
60
61
62
63
64
65
66
67
68
69
70
        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); // 设置跟进日期
          }
        }
71
72
73
74
75
76
77
78
79
80
81
82
        // 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
83
        setComment(dataSearch.comment);
boyang authored
84
        setTicketsType(dataSearch.ticketsTypeText);
boyang authored
85
86
87
88
        setTicketsDetail(dataSearch.ticketsDetail);
        setTicketsAttachment(dataSearch.ticketsAttachments);
        setAssignPeople(dataSearch.assignPeople);
        setComment(dataSearch.comment);
89
90
91
92
93
94
95
96
        setDatetime(dataSearch.datetime); // 设置跟进日期
        // setDateRange(data.dateRange || []); // 设置跟进时间范围
        setCreateByName(dataSearch.createByName); // 设置跟进人员
        setClientName(dataSearch.clientName); // 设置客户名称
        // setClientAddress(data.clientAddress || ''); // 设置客户地址
        // setClientNameLike(data.clientNameLike || ''); // 设置客户名称模糊查询
        // setClientAddressLike(data.clientAddressLike || ''); // 设置客户地址模糊查询
        // setTradeStatus(data.tradeStatus || ''); // 设置客户状态
97
        setTradeStatusText(data.tradeStatusLike || ''); // 设置客户状态模糊查询
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
        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',
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
      label: '跟进方式',
      children: way, // 跟进方式
    },
    {
      key: '7',
      label: '跟进状态',
      children: tradeStatusText, // 跟进状态
    },
    {
      key: '8',
      label: '工单类型',
      children: ticketsType, // 跟进状态
    },
    {
      key: '9',
      label: '工单详情',
      children: ticketsDetail, // 跟进状态
    },
    // {
boyang authored
153
    //   key: '12',
154
155
156
157
158
159
160
    //   label: '工单附件',
    //   children: ticketsAttachment, // 跟进状态
    // },
    {
      key: '10',
      label: '指派人员',
      children: assignPeople, // 跟进状态
161
    },
boyang authored
162
163
164
165
166
    {
      key: '11',
      label: '客户评价',
      children: comment, // 跟进状态
    },
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  ];
  const handleDelete = async () => {
    // 调用删除接口
    const success = await postAdminClientRemoveClientComunicationInfo({
      query: {
        id: data.id,
      },
    });
    // setIsModalVisible(false);
    if (success) {
      actionRef?.current?.reload(); // 重新加载表格数据
    }
  };
  return (
    <Space>
      <ModalForm
        title="跟进记录"
184
        trigger={<Button type="primary">查看</Button>}
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
        submitter={{
          resetButtonProps: {
            style: {
              display: 'none',
            },
          },
          submitButtonProps: {
            style: {
              display: 'none',
            },
          },
          render: (props, defaultDoms) => {
            return [
              ...defaultDoms,
              <>
                <ClientModal
                  key={'modify'}
202
                  // data={data} // 将表单数据传递给 ClientModal
203
                  data={data} // 传递修改后的 data
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
                  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} />
243
        {/* {attachmentsName && (
244
245
246
247
          <a href={attachments} download>
            附件:{attachmentsName}
          </a>
        )}
248
249
250
251
252
        <div></div>
        {ticketsAttachment && (
          <a href={ticketsAttachment} download>
            工单附件:{ticketsAttachment}
          </a>
253
254
255
256
257
258
259
260
261
        )} */}
        {attachmentsName && (
          <div>
            {attachmentsName.endsWith('.png') ||
            attachmentsName.endsWith('.jpg') ? (
              <>
                <img
                  src={attachments}
                  alt={attachmentsName}
262
                  style={{ maxWidth: '300px', height: 'auto' }}
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
                />
                <div></div>
                <a href={attachments} download>
                  附件:{attachmentsName}
                </a>
              </>
            ) : (
              <a href={attachments} download>
                附件:{attachmentsName}
              </a>
            )}
          </div>
        )}

        <div></div>
        {/* {ticketsAttachment && (
          <a href={ticketsAttachment} download>
            工单附件:{ticketsAttachment}
          </a>
        )} */}
boyang authored
283
        {/* {ticketsAttachment && (
284
285
          <div>
            {ticketsAttachment.includes('jpg') ||
boyang authored
286
              ticketsAttachment.includes('png') ? (
287
288
289
290
              <>
                <img
                  src={ticketsAttachment}
                  alt={ticketsAttachment}
291
                  style={{ maxWidth: '300px', height: 'auto' }}
292
293
294
295
296
297
298
299
300
301
302
303
                />
                <div></div>
                <a href={ticketsAttachment} download>
                  工单附件:{ticketsAttachment}
                </a>
              </>
            ) : (
              <a href={ticketsAttachment} download>
                工单附件:{ticketsAttachment}
              </a>
            )}
          </div>
boyang authored
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
        )} */}
        {ticketsAttachment && (
          <div>
            {ticketsAttachment.split(',').map((ticketsAttachment, index) => (
              <div key={index}>
                {ticketsAttachment.includes('jpg') ||
                ticketsAttachment.includes('png') ? (
                  <>
                    <img
                      src={ticketsAttachment}
                      alt={`附件 ${index + 1}`}
                      style={{ maxWidth: '300px', height: 'auto' }}
                    />
                    <div></div>
                  </>
                ) : null}
                <a href={ticketsAttachment} download>
                  工单附件:{ticketsAttachment}
                </a>
              </div>
            ))}
          </div>
326
        )}
327
328
329
330
      </ModalForm>
    </Space>
  );
};