Blame view

src/pages/Client/index.tsx 8.48 KB
1
import ClientDrawer from '@/pages/Client/Components/ClientDrawer';
2
import ClientImportModal from '@/pages/Client/Components/ClientImportModal';
3
import ClientStatistic from '@/pages/Client/Components/ClientStatistic';
4
5
6
import CommunicationHistoryModal from '@/pages/Client/Components/CommunicationHistoryModal';
import {
  postAdminClientQueryClientPage,
7
  postServiceConstClientGroupFilters,
8
9
10
11
12
  postServiceConstClientLevels,
  postServiceConstTradeStatus,
} from '@/services';
import { orderExport } from '@/services/order';
import { enumToSelect } from '@/utils';
13
14
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
15
16
import { Button, Radio, Space, message } from 'antd';
import { useEffect, useRef, useState } from 'react';
17
18
const columns = [
19
20
21
  {
    dataIndex: 'index',
    valueType: 'indexBorder',
22
    ellipsis: true,
23
24
25
    width: 48,
  },
  {
26
27
    title: '客户名称',
    dataIndex: 'name',
28
    width: 100,
29
    ellipsis: true,
30
    hideInSearch: true,
31
32
  },
  {
33
    title: '单位名称',
34
    width: 150,
35
    ellipsis: true,
36
    dataIndex: 'companyName',
37
    hideInSearch: true,
38
39
  },
  {
40
    title: '单位地址',
41
    width: 250,
42
    ellipsis: true,
43
    dataIndex: 'companyAddressText',
44
    hideInSearch: true,
45
46
  },
  {
47
    title: '联系电话',
48
    width: 150,
49
    ellipsis: true,
50
    dataIndex: 'phoneNumber',
51
    hideInSearch: true,
52
53
54
  },
  {
    title: '客户来源',
55
    width: 150,
56
    ellipsis: true,
57
58
    dataIndex: 'source',
    hideInSearch: true,
59
60
61
62
  },
  {
    title: '推荐人',
    dataIndex: 'referrers',
63
    width: 150,
64
    ellipsis: true,
65
    hideInSearch: true,
66
67
68
69
  },
  {
    title: '客户需求',
    dataIndex: 'requirements',
70
    width: 150,
71
    ellipsis: true,
72
    hideInSearch: true,
73
74
75
  },
  {
    title: '是否已报方案',
76
    width: 150,
77
    ellipsis: true,
78
    dataIndex: 'hasSchemeText',
79
    hideInSearch: true,
80
81
82
83
  },
  {
    title: '报价时间',
    key: 'since',
84
    width: 150,
85
    ellipsis: true,
86
87
    dataIndex: 'quoteDatetime',
    valueType: 'dateTime',
88
    hideInSearch: true,
89
90
91
  },
  {
    title: '跟进状态',
92
    width: 150,
93
    ellipsis: true,
94
    dataIndex: 'tradeStatusText',
95
    hideInSearch: true,
96
97
98
  },
  {
    title: '客户等级',
99
    width: 150,
100
    ellipsis: true,
101
    dataIndex: 'levelText',
102
    hideInSearch: true,
103
104
105
  },
  {
    title: '创建时间',
106
    key: 'since',
107
    width: 150,
108
    ellipsis: true,
109
110
    dataIndex: 'createTime',
    valueType: 'dateTime',
111
    hideInSearch: true,
112
113
114
115
  },
  {
    title: '最新跟进时间',
    key: 'since',
116
    width: 150,
117
    ellipsis: true,
118
119
    dataIndex: 'latestCommunicationTime',
    valueType: 'dateTime',
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
    hideInSearch: true,
  },
  {
    title: '客户名称',
    dataIndex: 'nameLike',
    valueType: 'Text',
    hideInTable: true,
  },
  {
    title: '单位名称',
    dataIndex: 'companyNameLike',
    valueType: 'Text',
    hideInTable: true,
  },
  {
    title: '联系电话',
    dataIndex: 'phoneNumberLike',
    valueType: 'Text',
    hideInTable: true,
  },
  {
    title: '是否已报方案',
    dataIndex: 'hasScheme',
    valueType: 'select',
    valueEnum: {
      true: {
        text: '是',
        value: true,
      },
      false: {
        text: '否',
        value: false,
      },
    },
    hideInTable: true,
  },
  {
    title: '客户等级',
    dataIndex: 'level',
    valueType: 'select',
    hideInTable: true,
    request: async () => {
      const res = await postServiceConstClientLevels();
      return enumToSelect(res.data);
    },
  },
  {
    title: '跟进状态',
    dataIndex: 'tradeStatus',
    valueType: 'select',
    hideInTable: true,
    request: async () => {
      const res = await postServiceConstTradeStatus();
      return enumToSelect(res.data);
    },
  },
  {
    title: '创建时间',
    valueType: 'dateRange',
    hideInTable: true,
    search: {
      transform: (value) => {
        if (value) {
          return {
            createTimeGe: value[0],
            createTimeLe: value[1],
          };
        }
      },
    },
190
191
192
193
194
  },
  {
    title: '操作',
    valueType: 'option',
    key: 'option',
195
    width: 150,
196
    render: (text, record, index, action) => {
197
198
199
200
201
202
      console.log(JSON.stringify(record));
      return [
        <CommunicationHistoryModal
          key={'communicationHistory'}
          clientId={record.id}
        />,
203
204
205
206
        <ClientDrawer
          key={'detail'}
          record={record}
          optType={'detail'}
207
208
209
          onFinish={() => {
            action.reload();
          }}
210
211
212
213
214
        ></ClientDrawer>,
        <ClientDrawer
          key={'edit'}
          record={record}
          optType={'edit'}
215
216
217
          onFinish={() => {
            action.reload();
          }}
218
        ></ClientDrawer>,
219
220
      ];
    },
221
222
223
224
  },
];

export default () => {
225
  const [messageApi, contextHolder] = message.useMessage();
226
227
  const [groupFilter, setGroupFilter] = useState('All');
  const [groupFilterOptions, setGroupFilterDataOptions] = useState([]);
228
  const actionRef = useRef<ActionType>();
229
230
231
232
233
234
235
236
237
238
239
  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]);
240
  return (
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
      <Space direction="vertical" size="middle" style={{ display: 'flex' }}>
        <ClientStatistic></ClientStatistic>
        <ProTable
          columns={columns}
          actionRef={actionRef}
          cardBordered
          request={async (params) => {
            const res = await postAdminClientQueryClientPage({
              data: {
                ...params,
                groupFilter: groupFilter,
              },
            });
            const data = res.data;
            return data;
          }}
          search={{
            optionRender: (searchConfig, formProps, dom) => [
              ...dom.reverse(),
              <Button
                key="out"
                onClick={() => {
                  const values = searchConfig?.form?.getFieldsValue();
                  messageApi.open({
                    type: 'loading',
                    content: '导出中...',
                    duration: 0,
                  });
                  orderExport(
                    '/api/admin/client/exportClients',
                    '客户信息.xlsx',
                    'POST',
                    values,
                    () => {
                      messageApi.destroy();
                    },
                  );
                }}
              >
                导出
              </Button>,
            ],
          }}
          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);
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
          }}
          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={() => [
            <div key={'groupFilter'}>
              <Radio.Group
                options={groupFilterOptions}
                onChange={(e) => {
                  setGroupFilter(e.target.value);
                }}
                value={groupFilter}
                optionType="button"
              />
            </div>,
            <ClientDrawer
              optType={'add'}
              key="button"
              onFinish={() => {
                actionRef.current.reload();
341
              }}
342
343
344
345
346
            ></ClientDrawer>,
            <ClientImportModal key="import" />,
          ]}
        />
      </Space>
347
348
      {contextHolder}
    </>
349
350
  );
};