import React, { useState, useEffect, useRef } from 'react' import ProTable from '@ant-design/pro-table' import { Row, Col, Select, Card, Skeleton } from 'antd' import { AddressBook, City, Finance, Comment } from '@icon-park/react' import consts from '@/consts' import { useModal } from '@/components/Modal' import { queryDashboard } from '@/services/dashboard' import ReminderList from './components/ReminderList' import LeaderBoard from './components/LeaderBoard' import SoftLeaderboard from './components/SoftLeaderboard' import { cardTypeMap, cyclicalOp } from './consts' import BusinessChar from './components/BusinessChar' import RatioPanels from './components/RatioPanels' import PermSelect from '@/pages/Customer/Company/components/PermSelect' const Dashboard = () => { const timer = useRef(null) const [state, setState] = useState({ loading: true, staffIds: null, immediate: false, visible: false, reminderData: [], leaderboard: [], productLeaderBoard: [], clientChainRatio: {}, customerChainRatio: {}, businessChainRatio: {}, serviceLogChainRatio: {}, aggregation: {}, businessChar: {}, params: { businessGroupId: '', dataPermission: 'oneself', cyclical: 'week' } }) const { toggleModal, setModalProps } = useModal() // 展示服务弹窗详情 const handleReminderList = (dataType, reminderCyclical) => { setModalProps({ width: '90vw', modalRender: () => , onCancel: () => toggleModal() }) toggleModal() } // 展示卡片详情 const handleRatioCard = dataType => { setModalProps({ width: '90vw', modalRender: () => ( ), onCancel: () => toggleModal() }) toggleModal() } const initData = async payload => { if (timer.current) clearTimeout(timer.current) const { code = -1, data: { reminderData = [], leaderboard = [], productLeaderBoard = {}, clientChainRatio = [], customerChainRatio = {}, businessChainRatio = {}, serviceLogChainRatio = {}, aggregation = {}, businessChar = {} } } = await queryDashboard(payload) if (code === consts.RET_CODE.SUCCESS) { if (state.immediate) { setState({ ...state, loading: false, immediate: false, reminderData, leaderboard, productLeaderBoard, clientChainRatio, customerChainRatio, businessChainRatio, serviceLogChainRatio, aggregation, businessChar }) return } timer.current = setTimeout(() => { setState({ ...state, loading: false, reminderData, leaderboard, productLeaderBoard, clientChainRatio, customerChainRatio, businessChainRatio, serviceLogChainRatio, aggregation, businessChar }) }, 1000) } } useEffect(() => { initData(state.params) }, [state.params.businessGroupId, state.params.dataPermission, state.params.cyclical]) const columns = [ { title: '超过周期未服务提醒', dataIndex: 'name' }, { title: '7天', dataIndex: 'day7', render: (name, record) => ( handleReminderList(record.type, '7day')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) }, { title: '15天', dataIndex: 'day15', render: (name, record) => ( handleReminderList(record.type, '15day')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) }, { title: '30天', dataIndex: 'day30', render: (name, record) => ( handleReminderList(record.type, '30day')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) }, { title: '3个月', dataIndex: 'month3', render: (name, record) => ( handleReminderList(record.type, '3month')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) }, { title: '6个月', dataIndex: 'month6', render: (name, record) => ( handleReminderList(record.type, '6month')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) }, { title: '备忘', dataIndex: 'remind', render: (name, record) => ( handleReminderList(record.type, 'reminder')} className="text-primary cursor-pointer hover:text-[#967bbd]"> {name} ) } ] const handleChangeGroupId = e => setState({ ...state, immediate: true, params: { ...state.params, businessGroupId: e } }) // 处理权限Select下拉组件OnChange事件 const handlePermChange = ({ staffIds = [], dataPermission }) => { if (staffIds?.length) { setState({ ...state, immediate: true, params: { ...state.params, staffIds, dataPermission: null } }) return } setState({ ...state, immediate: true, params: { ...state.params, staffIds: null, dataPermission } }) } return (
record.type + Date.now()} columns={columns} dataSource={state.reminderData} search={false} toolBarRender={false} tableRender={(_, dom) => ( {dom} )} pagination={false} />
{/* setState({ ...state, immediate: true, params: { ...state.params, cyclical: e } }) } />
{state.loading ? ( ) : ( handleRatioCard(cardTypeMap.COMPANY)}>
{state.customerChainRatio.count}
{state.customerChainRatio.percentage}
新增客户
{cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
)}
{state.loading ? ( ) : ( handleRatioCard(cardTypeMap.CLIENT)}>
{state.clientChainRatio.count}
{state.clientChainRatio.percentage}
新增联系人
{cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
)}
{state.loading ? ( ) : ( handleRatioCard(cardTypeMap.BUSINESS)}>
{state.businessChainRatio.count}
{state.businessChainRatio.percentage}
新增商机
{cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
)}
{state.loading ? ( ) : ( handleRatioCard(cardTypeMap.SERVICE)} className="cursor-pointer">
{state.serviceLogChainRatio.count}
{state.serviceLogChainRatio.percentage}
服务记录
{cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
)}
  • 新增客户{state.aggregation.customerCount}个,服务 {state.aggregation.customerServiceCount}
  • 新增联系人{state.aggregation.clientCount}个,服务 {state.aggregation.clientServiceCount}
  • 新增商机{state.aggregation.businessCount}个,金额 {state.aggregation.businessSum} 元,服务 {state.aggregation.businessServiceCount} 条,赢单{state.aggregation.businessWinCount}
) } export default Dashboard