Blame view

src/pages/Client/FollowRecord/index.tsx 10.9 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
26
27
28
29
30
31
32
33
34
35
36

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

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

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

  // 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 (
330
    <div className="client-index">
331
332
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
      <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} */}
412
    </div>
413
414
  );
};