CommunicationHistoryModal.tsx
4.49 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
import { RESPONSE_CODE } from '@/constants/enum';
import {
postAdminClientAddOrModifyClientComunicationInfo,
postAdminClientQueryClientComunicationInfo,
postAdminClientRemoveClientComunicationInfo,
} from '@/services';
import {
ActionType,
EditableProTable,
ModalForm,
ProFormInstance,
} from '@ant-design/pro-components';
import { Popconfirm, message } from 'antd';
import { useEffect, useRef, useState } from 'react';
export default ({ clientId }) => {
const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
const [dataSource, setDataSource] = useState();
const ref = useRef<ProFormInstance>();
const actionRef = useRef<ActionType>();
const columns = [
{
title: '跟进时间',
dataIndex: 'datetime',
width: 50,
valueType: 'dateTime',
rules: [{ required: true, message: '请选择时间' }],
},
{
title: '方式',
width: 50,
dataIndex: 'way',
rules: [{ required: true, message: '请选择方式' }],
},
{
title: '内容',
width: 100,
valueType: 'textarea',
rules: [{ required: true, message: '请输入内容' }],
dataIndex: 'content',
},
{
title: '操作',
valueType: 'option',
width: 50,
render: (text, record, _, action) => [
<a
key="editable"
onClick={() => {
action?.startEditable?.(record.tid);
}}
>
编辑
</a>,
<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>,
],
},
];
useEffect(() => {
console.log('clientId', clientId);
}, []);
return (
<ModalForm
title="跟进记录"
trigger={<a type="primary">跟进记录</a>}
modalProps={{
destroyOnClose: true,
}}
>
<EditableProTable
rowKey="tid"
formRef={ref}
actionRef={actionRef}
recordCreatorProps={{
record: () => ({ tid: (Math.random() * 1000000).toFixed(0) }),
}}
loading={false}
columns={columns}
request={async () => {
const res = await postAdminClientQueryClientComunicationInfo({
data: {
clientId: clientId,
},
});
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);
const res = await postAdminClientAddOrModifyClientComunicationInfo({
data: {
...data,
clientId: clientId,
},
});
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
} else {
message.error('修改失败');
}
actionRef.current?.reload();
},
onChange: setEditableRowKeys,
}}
/>
{/*<ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
<ProFormField
ignoreFormItem
fieldProps={{
style: {
width: '100%',
},
}}
mode="read"
valueType="jsonCode"
text={JSON.stringify(dataSource)}
/>
</ProCard>*/}
</ModalForm>
);
};