| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- 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: () => <ReminderList dataType={dataType} reminderCyclical={reminderCyclical} />,
- onCancel: () => toggleModal()
- })
- toggleModal()
- }
- // 展示卡片详情
- const handleRatioCard = dataType => {
- setModalProps({
- width: '90vw',
- modalRender: () => (
- <RatioPanels
- dataType={dataType}
- retioCyclical={state.params.cyclical}
- dataPermission={state.params.dataPermission}
- />
- ),
- 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) => (
- <span
- onClick={() => handleReminderList(record.type, '7day')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- },
- {
- title: '15天',
- dataIndex: 'day15',
- render: (name, record) => (
- <span
- onClick={() => handleReminderList(record.type, '15day')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- },
- {
- title: '30天',
- dataIndex: 'day30',
- render: (name, record) => (
- <span
- onClick={() => handleReminderList(record.type, '30day')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- },
- {
- title: '3个月',
- dataIndex: 'month3',
- render: (name, record) => (
- <span
- onClick={() => handleReminderList(record.type, '3month')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- },
- {
- title: '6个月',
- dataIndex: 'month6',
- render: (name, record) => (
- <span
- onClick={() => handleReminderList(record.type, '6month')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- },
- {
- title: '备忘',
- dataIndex: 'remind',
- render: (name, record) => (
- <span
- onClick={() => handleReminderList(record.type, 'reminder')}
- className="text-primary cursor-pointer hover:text-[#967bbd]">
- {name}
- </span>
- )
- }
- ]
- 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 (
- <div>
- <div className="shadow-card">
- <ProTable
- bordered
- loading={state.loading}
- rowKey={record => record.type + Date.now()}
- columns={columns}
- dataSource={state.reminderData}
- search={false}
- toolBarRender={false}
- tableRender={(_, dom) => (
- <Card bodyStyle={{ padding: state.loading ? '24px' : 0 }} loading={state.loading}>
- {dom}
- </Card>
- )}
- pagination={false}
- />
- </div>
- <div className="mt-4">
- <PermSelect loading={state.loading} onConfirm={handlePermChange} dataType="workbench" />
- {/* <Select
- loading={state.loading}
- options={permData?.workbench || []}
- dropdownMatchSelectWidth={false}
- defaultValue="oneself"
- onChange={e =>
- setState({ ...state, immediate: true, params: { ...state.params, dataPermission: e } })
- }
- /> */}
- <span className="ml-4">
- <Select
- loading={state.loading}
- options={cyclicalOp}
- dropdownMatchSelectWidth={false}
- defaultValue="week"
- onChange={e =>
- setState({ ...state, immediate: true, params: { ...state.params, cyclical: e } })
- }
- />
- </span>
- </div>
- <div className="mt-4">
- <Row gutter={16}>
- <Col className="gutter-row" span={6}>
- <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
- {state.loading ? (
- <Skeleton active avatar />
- ) : (
- <Row
- className="cursor-pointer"
- onClick={() => handleRatioCard(cardTypeMap.COMPANY)}>
- <Col span={6}>
- <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
- <City size="26" fill="#fff" />
- </div>
- </Col>
- <Col span={18} flex="wrap">
- <div className="flex items-center justify-between ">
- <div className="text-2xl">{state.customerChainRatio.count}</div>
- <span
- className={[
- 'text-xl',
- state.customerChainRatio.percentage.startsWith('-')
- ? 'text-green-500'
- : 'text-red-500'
- ].join(' ')}>
- {state.customerChainRatio.percentage}
- </span>
- </div>
- <div className="flex justify-between items-center">
- <div>新增客户</div>
- <span>
- {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
- </span>
- </div>
- </Col>
- </Row>
- )}
- </div>
- </Col>
- <Col className="gutter-row" span={6}>
- <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
- {state.loading ? (
- <Skeleton active avatar />
- ) : (
- <Row className="cursor-pointer" onClick={() => handleRatioCard(cardTypeMap.CLIENT)}>
- <Col span={6}>
- <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
- <AddressBook size="26" fill="#fff" />
- </div>
- </Col>
- <Col span={18} flex="wrap">
- <div className="flex items-center justify-between ">
- <div className="text-2xl">{state.clientChainRatio.count}</div>
- <span
- className={[
- 'text-xl',
- state.clientChainRatio.percentage.startsWith('-')
- ? 'text-green-500'
- : 'text-red-500'
- ].join(' ')}>
- {state.clientChainRatio.percentage}
- </span>
- </div>
- <div className="flex justify-between items-center">
- <div>新增联系人</div>
- <span>
- {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
- </span>
- </div>
- </Col>
- </Row>
- )}
- </div>
- </Col>
- <Col className="gutter-row" span={6}>
- <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
- {state.loading ? (
- <Skeleton active avatar />
- ) : (
- <Row
- className="cursor-pointer"
- onClick={() => handleRatioCard(cardTypeMap.BUSINESS)}>
- <Col span={6}>
- <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
- <Finance size="26" fill="#fff" />
- </div>
- </Col>
- <Col span={18} flex="wrap">
- <div className="flex items-center justify-between ">
- <div className="text-2xl">{state.businessChainRatio.count}</div>
- <span
- className={[
- 'text-xl',
- state.businessChainRatio.percentage.startsWith('-')
- ? 'text-green-500'
- : 'text-red-500'
- ].join(' ')}>
- {state.businessChainRatio.percentage}
- </span>
- </div>
- <div className="flex justify-between items-center">
- <div>新增商机</div>
- <span>
- {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
- </span>
- </div>
- </Col>
- </Row>
- )}
- </div>
- </Col>
- <Col className="gutter-row" span={6}>
- <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
- {state.loading ? (
- <Skeleton active avatar />
- ) : (
- <Row
- onClick={() => handleRatioCard(cardTypeMap.SERVICE)}
- className="cursor-pointer">
- <Col span={6}>
- <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
- <Comment size="26" fill="#fff" />
- </div>
- </Col>
- <Col span={18} flex="wrap">
- <div className="flex items-center justify-between ">
- <div className="text-2xl">{state.serviceLogChainRatio.count}</div>
- <span
- className={[
- 'text-xl',
- state.serviceLogChainRatio.percentage.startsWith('-')
- ? 'text-green-500'
- : 'text-red-500'
- ].join(' ')}>
- {state.serviceLogChainRatio.percentage}
- </span>
- </div>
- <div className="flex justify-between items-center">
- <div>服务记录</div>
- <span>
- {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
- </span>
- </div>
- </Col>
- </Row>
- )}
- </div>
- </Col>
- </Row>
- </div>
- <div className="mt-4">
- <Row gutter={16}>
- <Col className="gutter-row" span={16}>
- <BusinessChar
- loading={state.loading}
- data={state.businessChar}
- changeGroupId={handleChangeGroupId}
- />
- </Col>
- <Col className="gutter-row" span={8}>
- <Card
- headStyle={{ padding: '0 12px' }}
- title="数据汇总"
- className="shadow-card"
- bodyStyle={{ padding: state.loading ? '24px' : 0 }}
- loading={state.loading}>
- <ul>
- <li className="px-12px py-16px border-b-1">
- 新增客户<b className="px-1">{state.aggregation.customerCount}</b>个,服务
- <b className="px-1">{state.aggregation.customerServiceCount}</b>条
- </li>
- <li className="px-12px py-16px border-b-1">
- 新增联系人<b className="px-1">{state.aggregation.clientCount}</b>个,服务
- <b className="px-1">{state.aggregation.clientServiceCount}</b> 条
- </li>
- <li className="px-12px py-16px">
- 新增商机<b className="px-1">{state.aggregation.businessCount}</b>个,金额
- <b className="px-1">{state.aggregation.businessSum}</b> 元,服务
- <b className="px-1">{state.aggregation.businessServiceCount}</b>
- 条,赢单<b className="px-1">{state.aggregation.businessWinCount}</b>个
- </li>
- </ul>
- </Card>
- </Col>
- </Row>
- </div>
- <div className="mt-4">
- <Row gutter={24}>
- <Col className="gutter-row" span={12}>
- <LeaderBoard dataList={state.leaderboard} loading={state.loading} />
- </Col>
- <Col className="gutter-row" span={12}>
- <SoftLeaderboard
- productLeaderBoard={state.productLeaderBoard}
- loading={state.loading}
- />
- </Col>
- </Row>
- </div>
- </div>
- )
- }
- export default Dashboard
|