123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- import React, { useState, useMemo, useRef } from 'react';
- import { Avatar, Button, message } from 'antd';
- import router from 'umi/router';
- import QueryTable from '@/components/QueryTable';
- import apis from '@/services/apis';
- import request from '@/utils/request';
- import withActions from '@/components/ActionList';
- import AuthButton from '@/components/AuthButton';
- import Styles from '../style.less';
- import ChangeStatus from './components/ChangeStatus';
- import Attribution from './components/Attribution';
- import IntegralRecord from './components/IntegralRecord';
- import Recommend from './components/Recommend';
- import getSearchFields from './searchFields';
-
- const actionList = {
- changeStatus: 'changeStatus', // 变更状态
- attribution: 'attribution', //调整归属
- integralRecord: 'integralRecord', //积分记录
- recommend: 'recommend', //推荐客户
- };
-
- const PrivateCustomer = () => {
- const ref = useRef();
-
- const [showModel, SetShowModel] = useState({});
- const [exportLoding, setExportLoding] = useState(false);
-
- const handShowModel = (record, actionType) => {
- SetShowModel({
- [actionList[actionType]]: {
- visible: true,
- data: record,
- },
- });
- };
-
- function toCustomerDateil(record) {
- router.push({
- pathname: '/customer/customerlist/privateCustomerDetail',
- query: {
- id: record.customerId,
- },
- });
- }
-
- const columns = useMemo(() => {
- return [
- {
- title: '头像',
- dataIndex: 'picture',
- key: 'picture',
- align: 'center',
- width: '10%',
- render: (_, record) => (
- <Avatar
- shape="square"
- style={{ color: 'blue' }}
- src={record.picture}
- size={64}
- icon="user"
- />
- ),
- },
- {
- title: '姓名',
- dataIndex: 'name',
- key: 'name',
- align: 'center',
- width: '10%',
- // eslint-disable-next-line no-nested-ternary
- // render: (_, record) => (
- // <>
- // <Navigate onClick={() => toCustomerDateil(record)}>{record.name}</Navigate>
- // </>
- // ),
- },
- {
- title: '电话',
- dataIndex: 'phone',
- key: 'phone',
- align: 'center',
- width: '10%',
- },
- {
- title: '性别',
- dataIndex: 'sex',
- key: 'sex',
- align: 'center',
- width: '10%',
- // eslint-disable-next-line no-nested-ternary
- render: (_, record) => (
- <>
- <span>{record.sex === 1 ? '男' : record.sex === 2 ? '女' : '未知'}</span>
- </>
- ),
- },
- {
- title: '置业顾问',
- dataIndex: 'consultantName',
- key: 'consultantName',
- align: 'center',
- width: '10%',
- // eslint-disable-next-line no-nested-ternary
- render: (_, record) => (
- <>
- <span>{record.consultantName}</span>
- <br />
- <span>{record.consultTel}</span>
- </>
- ),
- },
- {
- title: '归属项目',
- dataIndex: 'buildingName',
- key: 'buildingName',
- align: 'center',
- width: '10%',
- },
- {
- title: '推广人员',
- dataIndex: 'sharePersonName',
- key: 'sharePersonName',
- align: 'center',
- width: '10%',
- },
- {
- title: '客户状态',
- dataIndex: 'reportRecommendStatus',
- key: 'reportRecommendStatus',
- align: 'center',
- width: '10%',
- // eslint-disable-next-line no-nested-ternary
- render: (_, records) => {
- if (records.status === 1) {
- return '报备';
- }
- if (records.status === 2) {
- return '到访';
- }
- if (records.status === 3) {
- return '认购';
- }
- if (records.status === 4) {
- return '签约';
- }
- },
- },
- {
- title: '操作',
- dataIndex: 'customerId',
- key: 'customerId',
- align: 'center',
- width: '20%',
- render: withActions((_, record) => [
- <Button type="link" onClick={() => toCustomerDateil(record)}>
- 查看详情
- </Button>,
- // <EditIcon color="#FF4A4A" text="查看详情" onClick={() => toCustomerDateil(record)} />,
- <AuthButton name="admin.customer.recommend.edit.id.put" noRight={null}>
- <Button
-
- type="link"
- onClick={() => handShowModel(record, actionList.changeStatus)}
- >
- 变更状态
- </Button>
- </AuthButton>,
-
- <AuthButton name="admin.customer.recommend.belong" noRight={null}>
- <Button
-
- type="link"
- onClick={() => handShowModel(record, actionList.attribution)}
- >
- 调整归属
- </Button>
- </AuthButton>,
-
- ]),
- },
- ];
- }, []);
-
- //导出
- function exportCustomer() {
- console.log(ref.current, 'ref');
- setExportLoding(true);
-
- request({
- ...apis.customer.customerRecommendExport,
- responseType: 'blob',
- params: ref.current.getSearchData,
- })
- .then(response => {
- download(response);
- setExportLoding(false);
- })
- .catch(() => {
- message.err('连接超时');
- setExportLoding(false);
- });
- }
-
- function download(data) {
- if (!data) {
- return;
- }
- const url = window.URL.createObjectURL(new Blob([data]));
- const link = document.createElement('a');
- link.style.display = 'none';
- link.href = url;
- link.setAttribute('download', '客户列表.xlsx');
- document.body.append(link);
- link.click();
- }
-
- const searchFields = useMemo(getSearchFields, []);
-
- //操作成功请求数据
- const handleCancel = () => {
- SetShowModel({});
- ref.current.reload();
- };
-
- const actionRender = () => {
-
- return (
- <Button type="danger" loading={exportLoding} onClick={() => exportCustomer()}>
- 导出
- </Button>
- );
- };
- return (
- <>
- <QueryTable
- ref={ref}
- rowKey="customerId"
- api={apis.customer.customerRecommend}
- searchFields={searchFields}
- params={{
- customerType: 'private',
- }}
- columns={columns}
- actionRender={actionRender}
- // onPageChange={(pg) => setPage(pg)}
- />
-
- <ChangeStatus
- modelProps={showModel[actionList.changeStatus]}
- handleCancel={handleCancel}
- onCancel={() => SetShowModel({})}
- ></ChangeStatus>
-
- <Attribution
- modelProps={showModel[actionList.attribution]}
- handleCancel={handleCancel}
- onCancel={() => SetShowModel({})}
- />
-
- <IntegralRecord
- modelProps={showModel[actionList.integralRecord]}
- handleCancel={handleCancel}
- onCancel={() => SetShowModel({})}
- />
-
- <Recommend
- modelProps={showModel[actionList.recommend]}
- handleCancel={handleCancel}
- onCancel={() => SetShowModel({})}
- />
- </>
- );
- };
-
- export default PrivateCustomer;
|