Blame view

src/pages/Client/FollowRecord/index.tsx 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
import { RESPONSE_CODE } from '@/constants/enum';
import ClientModal from '@/pages/Client/FollowRecord/Components/ClientModal';
import CommunicationHistoryModal from '@/pages/Client/FollowRecord/Components/CommunicationHistoryModal';
import {
  postAdminClientQueryClientComunicationInfo,
  postAdminClientRemoveClientComunicationInfo,
  postServiceConstClientWay,
  postServiceConstTradeStatus,
} from '@/services';
import { enumToSelect } from '@/utils';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
boyang authored
13
import { Button, Popconfirm, Space, message } from 'antd';
14
import { useRef, useState } from 'react';
15
import './index.less';
16
17
18
19
20
21
22
23
24
25

export default () => {
  const actionRef = useRef<ActionType>();
  const [refreshKey, setRefreshKey] = useState(0); // 用于强制刷新的键

  const reload = () => {
    actionRef.current.reload(); // 重新加载数据

    // 更新 refreshKey,强制刷新 CommunicationHistoryModal
    setRefreshKey((prevKey) => prevKey + 1);
26
    console.log('5656refresh');
27
28
29
30
31
32
33
34
35
36
37
  };
  //biaoji
  const columns = [
    {
      title: '跟进日期',
      key: 'datetime',
      width: 150,
      ellipsis: true,
      dataIndex: 'datetime',
      valueType: 'dateTime',
      hideInSearch: true,
boyang authored
38
39
40
41
42
43
44
45
46
47
      // search: {
      //   transform: (value) => {
      //     if (value) {
      //       return {
      //         createTimeGe: value[0],
      //         createTimeLe: value[1],
      //       };
      //     }
      //   },
      // },
48
49
    },
    {
50
      title: '跟进日期',
51
52
53
54
55
56
57
      dataIndex: 'dateRange',
      valueType: 'dateRange',
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
boyang authored
58
59
              dateTimeGe: value[0],
              dateTimeLe: value[1],
60
61
62
63
64
65
66
            };
          }
        },
      },
    },
    {
      title: '跟进人员',
boyang authored
67
      dataIndex: 'updateByName',
68
69
70
71
      width: 100,
      ellipsis: true,
      hideInSearch: false,
    },
72
73
74
75
76
77
78
    // {
    //   title: '跟进状态',
    //   width: 150,
    //   ellipsis: true,
    //   dataIndex: 'tradeStatusText',
    //   hideInSearch: true,
    // },
79
80
81
82
83
84
85
    {
      title: '客户名称',
      dataIndex: 'clientName',
      width: 150,
      ellipsis: true,
      hideInSearch: true,
    },
86
87
88
89
90
91
92
    // {
    //   title: '客户地址',
    //   dataIndex: 'clientAddress',
    //   width: 250,
    //   ellipsis: true,
    //   hideInSearch: true,
    // },
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
      title: '联系人',
      dataIndex: 'contact',
      width: 150,
      ellipsis: true,
      hideInSearch: false,
    },
    // {
    //   title: '联系人',
    //   dataIndex: 'contactLike',
    //   width: 150,
    //   ellipsis: true,
    //   hideInSearch: false,
    //   hideInTable: true,
    // },
    {
      title: '联系电话',
      dataIndex: 'contactPhone',
      width: 150,
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '跟进状态',
      dataIndex: 'tradeStatusLike',
      width: 100,
119
120
121
122
      ellipsis: true,
      hideInSearch: true,
    },
    {
123
      title: '跟进方式',
124
125
126
127
128
129
      dataIndex: 'wayText',
      width: 100,
      ellipsis: true,
      hideInSearch: true,
    },
    {
130
      title: '跟进方式',
131
132
133
134
135
136
137
138
139
140
      dataIndex: 'way',
      width: 100,
      ellipsis: true,
      hideInSearch: false,
      hideInTable: true,
      request: async () => {
        const res = await postServiceConstClientWay();
        return enumToSelect(res.data);
      },
    },
141
142
143
144
145
146
147
148
149
150
    // {
    //   title: '跟进状态',
    //   dataIndex: 'tradeStatus',
    //   valueType: 'select',
    //   hideInTable: true,
    //   request: async () => {
    //     const res = await postServiceConstTradeStatus();
    //     return enumToSelect(res.data);
    //   },
    // },
151
152
153
154
155
156
157
158
    {
      title: '客户名称',
      dataIndex: 'clientNameLike',
      width: 150,
      ellipsis: true,
      hideInSearch: false,
      hideInTable: true,
    },
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    // {
    //   title: '客户地址',
    //   dataIndex: 'clientAddressLike',
    //   width: 250,
    //   ellipsis: true,
    //   hideInSearch: false,
    //   hideInTable: true,
    // },
    // {
    //   title: '跟进状态',
    //   dataIndex: 'tradeStatus',
    //   width: 100,
    //   ellipsis: true,
    //   hideInSearch: true,
    // },
174
    {
175
      title: '跟进状态',
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
      dataIndex: 'tradeStatus',
      width: 100,
      ellipsis: true,
      hideInSearch: false,
      hideInTable: true,
      request: async () => {
        const res = await postServiceConstTradeStatus();
        return enumToSelect(res.data);
      },
    },
    {
      title: '跟进详情',
      dataIndex: 'content',
      width: 250,
      ellipsis: true,
191
      hideInSearch: true,
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      width: 150,
      ellipsis: true,
      hideInSearch: true,
    },
    {
      title: '附件',
      dataIndex: 'attachments',
      width: 150,
      ellipsis: true,
      hideInSearch: true,
      hideInTable: true,
    },
    {
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
      title: '创建日期',
      dataIndex: 'createTime',
      valueType: 'dateRange',
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
              createTimeGe: value[0],
              createTimeLe: value[1],
            };
          }
        },
      },
    },
    {
225
226
227
      title: '操作',
      valueType: 'option',
      key: 'option',
228
      width: 220,
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
      render: (text, record, index, action) => {
        const handleDelete = async () => {
          // console.log(JSON.stringify(record), '5656record');
          // 调用删除接口
          const success = await postAdminClientRemoveClientComunicationInfo({
            query: {
              id: record.id,
            },
          });
          if (success) {
            action.reload(); // 刷新表格
          }
        };
        return [
          <CommunicationHistoryModal
            // key={'communicationHistory'}
245
246
            // key={'communicationHistory'}
            key={`${refreshKey}`} // 使用 refreshKey 来强制更新组件
247
248
249
250
251
252
253
            data={record}
            // reloadTable={() => {
            //   actionRef.current.reload();
            //   console.log('5656flush');
            // }}
            reloadTable={reload}
          />,
254
          <ClientModal
255
256
257
258
259
260
261
262
263
264
265
266
267
            key={'modify'}
            // data={data} // 将表单数据传递给 ClientModal
            data={record} // 传递修改后的 data
            reloadTable={() => {
              actionRef?.current?.reload(); // 重新加载表格数据
              // props.submit();
            }}
            type={'modify'}
            onFinish={() => {
              // setIsModalVisible(false);
            }} // 关闭 Modal
            style={{ marginRight: '10px' }}
          />,
268
          <>
boyang authored
269
            {/* <Button
270
271
272
273
274
275
276
277
              key={'delete'}
              onClick={() => {
                handleDelete();
                actionRef.current.reload();
              }}
              // reloadTable={() => {
              //   actionRef.current.reload();
              // }}
278
              type="primary"
279
              size="middle"
280
              danger
boyang authored
281
282
283
284
            // 使用 danger 属性来将按钮颜色设置为红色
            // onFinish={() => {
            //   actionRef.current.reload();
            // }}
285
286
287
            >
              删除
            </Button>
boyang authored
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
            <ButtonConfirm
              key={'delete'}
              className="p-0"
              title={'是否确认删除'}
              text="删除"
              type="primary"
              size="middle"
              danger
              onConfirm={async () => {
                handleDelete();
                actionRef.current.reload();
              }}
            /> */}
            <Popconfirm
              title={'是否确认删除'}
              onConfirm={async () => {
                handleDelete();
                actionRef.current.reload();
              }}
              okText="确认"
              cancelText="取消"
            >
              <Button key={'delete'} type="primary" size="middle" danger>
                删除
              </Button>
            </Popconfirm>
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
          </>,
        ];
      },
    },
  ];

  // useEffect(() => {
  //   const pullGroupFilterDataOptions = async () => {
  //     const res = await postServiceConstClientGroupFilters();
  //     console.log('setGroupFilterDataOptions' + JSON.stringify(res.data));
  //     setGroupFilterDataOptions(enumToSelect(res.data));
  //   };
  //   pullGroupFilterDataOptions();
  // }, []);
  // useEffect(() => {
  //   actionRef.current?.reload();
  // }, [groupFilter]);
  return (
332
    <div className="client-index">
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
      <Space direction="vertical" size="middle" style={{ display: 'flex' }}>
        <ProTable
          columns={columns}
          actionRef={actionRef}
          cardBordered
          request={async (params) => {
            const res = await postAdminClientQueryClientComunicationInfo({
              data: {
                ...params,
              },
            });
            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('获取失败');
            }
          }}
          search={{
            optionRender: (searchConfig, formProps, dom) => [...dom.reverse()],
          }}
          scroll={{
            x: 1400,
          }}
          editable={{
            type: 'multiple',
          }}
          columnsState={{
            persistenceKey: 'pro-table-singe-demos',
            persistenceType: 'localStorage',
            defaultValue: {
              option: { fixed: 'right', disable: true },
            },
            onChange(value) {
              console.log('value: ', value);
            },
          }}
          rowKey="id"
          options={{
            setting: {
              listsHeight: 400,
            },
          }}
          form={{
            // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
            syncToUrl: (values, type) => {
              if (type === 'get') {
                return {
                  ...values,
                  created_at: [values.startTime, values.endTime],
                };
              }
              return values;
            },
          }}
          pagination={{
            pageSize: 5,
            onChange: (page) => console.log(page),
          }}
          dateFormatter="string"
          headerTitle="高级表格"
          toolBarRender={() => [
            <ClientModal
              key={'add'}
              reloadTable={() => {
                actionRef.current.reload();
              }}
              type={'add'}
            />,
          ]}
        />
      </Space>
      {/* {contextHolder} */}
414
    </div>
415
416
  );
};