CommunicationHistoryModal.tsx
10.7 KB
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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import { RESPONSE_CODE } from '@/constants/enum';
import {
postAdminClientAddOrModifyClientComunicationInfo,
postAdminClientQueryClientComunicationInfo,
postAdminClientRemoveClientComunicationInfo,
postServiceConstClientWay,
postServiceConstTradeStatus,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
ActionType,
EditableProTable,
ModalForm,
ProFormInstance,
} from '@ant-design/pro-components';
import { Descriptions, Popconfirm, message } from 'antd';
import { useEffect, useRef, useState } from 'react';
import ClientModal from './ClientModal';
import InformationHistoryModal from './InformationHistoryModal';
export default ({ record }) => {
const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
const [dataSource, setDataSource] = useState();
const ref = useRef<ProFormInstance>();
const actionRef = useRef<ActionType>();
const [refreshKey, setRefreshKey] = useState(0); // 用于强制刷新的键
const reloadInformationHistoryModal = () => {
actionRef.current.reload(); // 重新加载数据
// 更新 refreshKey,强制刷新 CommunicationHistoryModal
setRefreshKey((prevKey) => prevKey + 1);
};
const columns = [
{
title: '跟进时间',
dataIndex: 'datetime',
width: 50,
valueType: 'dateTime',
rules: [{ required: true, message: '请选择时间' }],
},
{
title: '跟进人',
width: 50,
rules: [{ required: true, message: '请输入跟进人' }],
dataIndex: 'updateByName',
},
{
title: '跟进方式',
width: 50,
dataIndex: 'way',
rules: [{ required: true, message: '请选择方式' }],
render: (text, record) => record.wayText, // 显示 wayText
request: async () => {
const res = await postServiceConstClientWay();
return enumToSelect(res.data);
},
},
{
title: '跟进状态',
width: 50,
dataIndex: 'tradeStatus',
rules: [{ required: true, message: '请选择方式' }],
render: (text, record) => record.tradeStatusLike, // 显示 wayText
request: async () => {
const res = await postServiceConstTradeStatus();
return enumToSelect(res.data);
},
},
{
title: '跟进详情',
width: 80,
valueType: 'textarea',
rules: [{ required: true, message: '请输入内容' }],
dataIndex: 'content',
},
{
title: '操作',
valueType: 'option',
width: 60,
render: (text, record, _, action) => [
// <a
// key="editable"
// onClick={() => {
// action?.startEditable?.(record.tid);
// }}
// >
// 编辑
// </a>,
<InformationHistoryModal
// key={'communicationHistory'}
key={`communicationHistory-${refreshKey}`} // 使用 refreshKey 来强制更新组件
data={record}
// reloadTable={() => {
// actionRef.current.reload();
// console.log('5656flush');
// }}
reloadTable={reloadInformationHistoryModal}
/>,
<Popconfirm
key={'delete'}
title="删除记录"
description="确认删除记录?"
onConfirm={async () => {
setDataSource(dataSource.filter((item) => item.tid !== record.tid));
const res = await postAdminClientRemoveClientComunicationInfo({
query: {
id: record.id,
},
});
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
action?.reload();
} else {
message.error('删除失败');
}
}}
okText="是"
cancelText="否"
>
<a type={'danger'}>删除</a>
</Popconfirm>,
],
},
];
const [name, setName] = useState(''); // 客户名称
const [leaderName, setLeaderName] = useState(''); // 负责人
const [sourceText, setSourceText] = useState(''); // 来源文本
const [phoneNumber, setPhoneNumber] = useState(''); // 联系电话
const [institutionContactName, setInstitutionContactName] = useState(''); // 联系电话
const [department, setDepartment] = useState(''); // 联系电话
const [gradePosition, setGradePosition] = useState(''); // 联系电话
const [referrers, setReferrers] = useState(''); // 推荐人
const [levelText, setLevelText] = useState(''); // 客户等级文本
const [createTime, setCreateTime] = useState(null); // 最新沟通时间
const [address, setAddress] = useState(''); // 客户地址
const [notes, setNotes] = useState(''); // 备注信息
const [createByName, setCreateByName] = useState(''); // 创建人
const [latestObject, setLatestObject] = useState(); // 最新跟进时间
const [recordSave, setRecordSave] = useState(); //新增跟进
useEffect(() => {
const request = async () => {
const resShow = await postAdminClientQueryClientComunicationInfo({
data: {
clientId: record.id,
},
});
if (resShow?.data?.data !== null) {
const data = resShow?.data?.data;
// const latest = data.reduce((latest: any, current: any) => {
// return new Date(current.updateTime) > new Date(latest.updateTime) ? current : latest;
// });
// const data = [];
const latestObject2 =
data?.length > 0
? data.reduce((latest, current) =>
new Date(current.datetime) > new Date(latest.datetime)
? current
: latest,
)
: null; // 或返回其他默认值
setLatestObject(latestObject2?.datetime);
}
setRecordSave(record);
setName(record.name);
setLeaderName(record.leaderName);
setSourceText(record.sourceText);
setPhoneNumber(record.phoneNumber);
setInstitutionContactName(record.institutionContactName);
setDepartment(record.department);
setGradePosition(record.gradePosition);
setReferrers(record.referrers);
setLevelText(record.levelText);
setCreateTime(record.createTime);
setAddress(record.address);
setNotes(record.notes);
setCreateByName(record.createByName);
};
request();
}, []);
const items = [
{
key: '1',
label: '客户名称',
children: name, // 客户名称
},
{
key: '2',
label: '负责人',
children: leaderName, // 负责人
},
{
key: '3',
label: '来源',
children: sourceText, // 来源文本
},
{
key: '4',
label: '联系电话',
children: phoneNumber, // 联系电话
},
{
key: '5',
label: '课题组',
children: institutionContactName, // 推荐人
},
{
key: '6',
label: '部门',
children: department, // 推荐人
},
{
key: '7',
label: '年级/职位',
children: gradePosition, // 推荐人
},
{
key: '8',
label: '推荐人',
children: referrers, // 推荐人
},
{
key: '10',
label: '客户等级',
children: levelText, // 客户等级文本
},
{
key: '11',
label: '创建时间',
children: createTime, // 最新沟通时间
},
{
key: '12',
label: '客户地址',
children: address, // 客户地址
},
{
key: '13',
label: '备注',
children: notes, // 备注信息
},
{
key: '14',
label: '创建人',
children: createByName, // 创建人
},
{
key: '15',
label: '最新跟进时间',
children: latestObject, // 最新跟进时间
},
];
return (
<ModalForm
title="客户详情"
trigger={<a type="primary">查看</a>}
modalProps={{
destroyOnClose: true,
}}
onFinish={async () => {
return true;
}}
>
<Descriptions items={items} column={2} />
<ClientModal
key={'add'}
data={recordSave}
reloadTable={() => {
actionRef.current?.reload();
}}
type={'add2'}
/>
<EditableProTable
rowKey="tid"
formRef={ref}
actionRef={actionRef}
recordCreatorProps={false}
// recordCreatorProps={{
// record: () => ({ tid: (Math.random() * 1000000).toFixed(0) }),
// }}
loading={false}
columns={columns}
request={async () => {
const res = await postAdminClientQueryClientComunicationInfo({
data: {
clientId: record.id,
},
});
if (res.result === RESPONSE_CODE.SUCCESS) {
console.log(JSON.stringify(res.data));
return {
...res.data,
data: res.data.data.map((item) => {
return {
...item,
tid: (Math.random() * 1000000).toFixed(0),
};
}),
};
} else {
message.error('获取失败');
}
}}
value={dataSource}
onChange={setDataSource}
editable={{
type: 'multiple',
editableKeys,
onSave: async (rowKey, data, row) => {
console.log(rowKey, data, row);
if (data?.way === '拜访') {
data.way = 'VISIT';
} else if (data?.way === '电话') {
data.way = 'PHONE';
} else if (data?.way === '微信') {
data.way = 'WECHAT';
} else if (data?.way === '邮件') {
data.way = 'EMAIL';
} else if (data?.way === '其他') {
data.way = 'OTHER';
}
const res = await postAdminClientAddOrModifyClientComunicationInfo({
data: {
...data,
clientId: record.id,
},
});
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
} else {
message.error('修改失败');
}
actionRef.current?.reload();
},
onChange: setEditableRowKeys,
}}
/>
{/* <Descriptions title="User Info" items={items} column={2} /> */}
{/*<ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
<ProFormField
ignoreFormItem
fieldProps={{
style: {
width: '100%',
},
}}
mode="read"
valueType="jsonCode"
text={JSON.stringify(dataSource)}
/>
</ProCard>*/}
</ModalForm>
);
};