index.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. import React, { useState, useEffect, useRef } from 'react'
  2. import ProTable from '@ant-design/pro-table'
  3. import { Row, Col, Select, Card, Skeleton } from 'antd'
  4. import { AddressBook, City, Finance, Comment } from '@icon-park/react'
  5. import consts from '@/consts'
  6. import { useModal } from '@/components/Modal'
  7. import { queryDashboard } from '@/services/dashboard'
  8. import ReminderList from './components/ReminderList'
  9. import LeaderBoard from './components/LeaderBoard'
  10. import SoftLeaderboard from './components/SoftLeaderboard'
  11. import { cardTypeMap, cyclicalOp } from './consts'
  12. import BusinessChar from './components/BusinessChar'
  13. import RatioPanels from './components/RatioPanels'
  14. import PermSelect from '@/pages/Customer/Company/components/PermSelect'
  15. const Dashboard = () => {
  16. const timer = useRef(null)
  17. const [state, setState] = useState({
  18. loading: true,
  19. staffIds: null,
  20. immediate: false,
  21. visible: false,
  22. reminderData: [],
  23. leaderboard: [],
  24. productLeaderBoard: [],
  25. clientChainRatio: {},
  26. customerChainRatio: {},
  27. businessChainRatio: {},
  28. serviceLogChainRatio: {},
  29. aggregation: {},
  30. businessChar: {},
  31. params: { businessGroupId: '', dataPermission: 'oneself', cyclical: 'week' }
  32. })
  33. const { toggleModal, setModalProps } = useModal()
  34. // 展示服务弹窗详情
  35. const handleReminderList = (dataType, reminderCyclical) => {
  36. setModalProps({
  37. width: '90vw',
  38. modalRender: () => <ReminderList dataType={dataType} reminderCyclical={reminderCyclical} />,
  39. onCancel: () => toggleModal()
  40. })
  41. toggleModal()
  42. }
  43. // 展示卡片详情
  44. const handleRatioCard = dataType => {
  45. setModalProps({
  46. width: '90vw',
  47. modalRender: () => (
  48. <RatioPanels
  49. dataType={dataType}
  50. retioCyclical={state.params.cyclical}
  51. dataPermission={state.params.dataPermission}
  52. />
  53. ),
  54. onCancel: () => toggleModal()
  55. })
  56. toggleModal()
  57. }
  58. const initData = async payload => {
  59. if (timer.current) clearTimeout(timer.current)
  60. const {
  61. code = -1,
  62. data: {
  63. reminderData = [],
  64. leaderboard = [],
  65. productLeaderBoard = {},
  66. clientChainRatio = [],
  67. customerChainRatio = {},
  68. businessChainRatio = {},
  69. serviceLogChainRatio = {},
  70. aggregation = {},
  71. businessChar = {}
  72. }
  73. } = await queryDashboard(payload)
  74. if (code === consts.RET_CODE.SUCCESS) {
  75. if (state.immediate) {
  76. setState({
  77. ...state,
  78. loading: false,
  79. immediate: false,
  80. reminderData,
  81. leaderboard,
  82. productLeaderBoard,
  83. clientChainRatio,
  84. customerChainRatio,
  85. businessChainRatio,
  86. serviceLogChainRatio,
  87. aggregation,
  88. businessChar
  89. })
  90. return
  91. }
  92. timer.current = setTimeout(() => {
  93. setState({
  94. ...state,
  95. loading: false,
  96. reminderData,
  97. leaderboard,
  98. productLeaderBoard,
  99. clientChainRatio,
  100. customerChainRatio,
  101. businessChainRatio,
  102. serviceLogChainRatio,
  103. aggregation,
  104. businessChar
  105. })
  106. }, 1000)
  107. }
  108. }
  109. useEffect(() => {
  110. initData(state.params)
  111. }, [state.params.businessGroupId, state.params.dataPermission, state.params.cyclical])
  112. const columns = [
  113. {
  114. title: '超过周期未服务提醒',
  115. dataIndex: 'name'
  116. },
  117. {
  118. title: '7天',
  119. dataIndex: 'day7',
  120. render: (name, record) => (
  121. <span
  122. onClick={() => handleReminderList(record.type, '7day')}
  123. className="text-primary cursor-pointer hover:text-[#967bbd]">
  124. {name}
  125. </span>
  126. )
  127. },
  128. {
  129. title: '15天',
  130. dataIndex: 'day15',
  131. render: (name, record) => (
  132. <span
  133. onClick={() => handleReminderList(record.type, '15day')}
  134. className="text-primary cursor-pointer hover:text-[#967bbd]">
  135. {name}
  136. </span>
  137. )
  138. },
  139. {
  140. title: '30天',
  141. dataIndex: 'day30',
  142. render: (name, record) => (
  143. <span
  144. onClick={() => handleReminderList(record.type, '30day')}
  145. className="text-primary cursor-pointer hover:text-[#967bbd]">
  146. {name}
  147. </span>
  148. )
  149. },
  150. {
  151. title: '3个月',
  152. dataIndex: 'month3',
  153. render: (name, record) => (
  154. <span
  155. onClick={() => handleReminderList(record.type, '3month')}
  156. className="text-primary cursor-pointer hover:text-[#967bbd]">
  157. {name}
  158. </span>
  159. )
  160. },
  161. {
  162. title: '6个月',
  163. dataIndex: 'month6',
  164. render: (name, record) => (
  165. <span
  166. onClick={() => handleReminderList(record.type, '6month')}
  167. className="text-primary cursor-pointer hover:text-[#967bbd]">
  168. {name}
  169. </span>
  170. )
  171. },
  172. {
  173. title: '备忘',
  174. dataIndex: 'remind',
  175. render: (name, record) => (
  176. <span
  177. onClick={() => handleReminderList(record.type, 'reminder')}
  178. className="text-primary cursor-pointer hover:text-[#967bbd]">
  179. {name}
  180. </span>
  181. )
  182. }
  183. ]
  184. const handleChangeGroupId = e =>
  185. setState({ ...state, immediate: true, params: { ...state.params, businessGroupId: e } })
  186. // 处理权限Select下拉组件OnChange事件
  187. const handlePermChange = ({ staffIds = [], dataPermission }) => {
  188. if (staffIds?.length) {
  189. setState({
  190. ...state,
  191. immediate: true,
  192. params: { ...state.params, staffIds, dataPermission: null }
  193. })
  194. return
  195. }
  196. setState({
  197. ...state,
  198. immediate: true,
  199. params: { ...state.params, staffIds: null, dataPermission }
  200. })
  201. }
  202. return (
  203. <div>
  204. <div className="shadow-card">
  205. <ProTable
  206. bordered
  207. loading={state.loading}
  208. rowKey={record => record.type + Date.now()}
  209. columns={columns}
  210. dataSource={state.reminderData}
  211. search={false}
  212. toolBarRender={false}
  213. tableRender={(_, dom) => (
  214. <Card bodyStyle={{ padding: state.loading ? '24px' : 0 }} loading={state.loading}>
  215. {dom}
  216. </Card>
  217. )}
  218. pagination={false}
  219. />
  220. </div>
  221. <div className="mt-4">
  222. <PermSelect loading={state.loading} onConfirm={handlePermChange} dataType="workbench" />
  223. {/* <Select
  224. loading={state.loading}
  225. options={permData?.workbench || []}
  226. dropdownMatchSelectWidth={false}
  227. defaultValue="oneself"
  228. onChange={e =>
  229. setState({ ...state, immediate: true, params: { ...state.params, dataPermission: e } })
  230. }
  231. /> */}
  232. <span className="ml-4">
  233. <Select
  234. loading={state.loading}
  235. options={cyclicalOp}
  236. dropdownMatchSelectWidth={false}
  237. defaultValue="week"
  238. onChange={e =>
  239. setState({ ...state, immediate: true, params: { ...state.params, cyclical: e } })
  240. }
  241. />
  242. </span>
  243. </div>
  244. <div className="mt-4">
  245. <Row gutter={16}>
  246. <Col className="gutter-row" span={6}>
  247. <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
  248. {state.loading ? (
  249. <Skeleton active avatar />
  250. ) : (
  251. <Row
  252. className="cursor-pointer"
  253. onClick={() => handleRatioCard(cardTypeMap.COMPANY)}>
  254. <Col span={6}>
  255. <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
  256. <City size="26" fill="#fff" />
  257. </div>
  258. </Col>
  259. <Col span={18} flex="wrap">
  260. <div className="flex items-center justify-between ">
  261. <div className="text-2xl">{state.customerChainRatio.count}</div>
  262. <span
  263. className={[
  264. 'text-xl',
  265. state.customerChainRatio.percentage.startsWith('-')
  266. ? 'text-green-500'
  267. : 'text-red-500'
  268. ].join(' ')}>
  269. {state.customerChainRatio.percentage}
  270. </span>
  271. </div>
  272. <div className="flex justify-between items-center">
  273. <div>新增客户</div>
  274. <span>
  275. {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
  276. </span>
  277. </div>
  278. </Col>
  279. </Row>
  280. )}
  281. </div>
  282. </Col>
  283. <Col className="gutter-row" span={6}>
  284. <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
  285. {state.loading ? (
  286. <Skeleton active avatar />
  287. ) : (
  288. <Row className="cursor-pointer" onClick={() => handleRatioCard(cardTypeMap.CLIENT)}>
  289. <Col span={6}>
  290. <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
  291. <AddressBook size="26" fill="#fff" />
  292. </div>
  293. </Col>
  294. <Col span={18} flex="wrap">
  295. <div className="flex items-center justify-between ">
  296. <div className="text-2xl">{state.clientChainRatio.count}</div>
  297. <span
  298. className={[
  299. 'text-xl',
  300. state.clientChainRatio.percentage.startsWith('-')
  301. ? 'text-green-500'
  302. : 'text-red-500'
  303. ].join(' ')}>
  304. {state.clientChainRatio.percentage}
  305. </span>
  306. </div>
  307. <div className="flex justify-between items-center">
  308. <div>新增联系人</div>
  309. <span>
  310. {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
  311. </span>
  312. </div>
  313. </Col>
  314. </Row>
  315. )}
  316. </div>
  317. </Col>
  318. <Col className="gutter-row" span={6}>
  319. <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
  320. {state.loading ? (
  321. <Skeleton active avatar />
  322. ) : (
  323. <Row
  324. className="cursor-pointer"
  325. onClick={() => handleRatioCard(cardTypeMap.BUSINESS)}>
  326. <Col span={6}>
  327. <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
  328. <Finance size="26" fill="#fff" />
  329. </div>
  330. </Col>
  331. <Col span={18} flex="wrap">
  332. <div className="flex items-center justify-between ">
  333. <div className="text-2xl">{state.businessChainRatio.count}</div>
  334. <span
  335. className={[
  336. 'text-xl',
  337. state.businessChainRatio.percentage.startsWith('-')
  338. ? 'text-green-500'
  339. : 'text-red-500'
  340. ].join(' ')}>
  341. {state.businessChainRatio.percentage}
  342. </span>
  343. </div>
  344. <div className="flex justify-between items-center">
  345. <div>新增商机</div>
  346. <span>
  347. {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
  348. </span>
  349. </div>
  350. </Col>
  351. </Row>
  352. )}
  353. </div>
  354. </Col>
  355. <Col className="gutter-row" span={6}>
  356. <div className="p-4 bg-white border rounded-2px border-hex-f0f0f0 shadow-card">
  357. {state.loading ? (
  358. <Skeleton active avatar />
  359. ) : (
  360. <Row
  361. onClick={() => handleRatioCard(cardTypeMap.SERVICE)}
  362. className="cursor-pointer">
  363. <Col span={6}>
  364. <div className="w-full max-w-48px h-48px border rounded-48px bg-[#0c7cd5] flex items-center justify-center">
  365. <Comment size="26" fill="#fff" />
  366. </div>
  367. </Col>
  368. <Col span={18} flex="wrap">
  369. <div className="flex items-center justify-between ">
  370. <div className="text-2xl">{state.serviceLogChainRatio.count}</div>
  371. <span
  372. className={[
  373. 'text-xl',
  374. state.serviceLogChainRatio.percentage.startsWith('-')
  375. ? 'text-green-500'
  376. : 'text-red-500'
  377. ].join(' ')}>
  378. {state.serviceLogChainRatio.percentage}
  379. </span>
  380. </div>
  381. <div className="flex justify-between items-center">
  382. <div>服务记录</div>
  383. <span>
  384. {cyclicalOp.find(item => item.value === state.params.cyclical)?.title}
  385. </span>
  386. </div>
  387. </Col>
  388. </Row>
  389. )}
  390. </div>
  391. </Col>
  392. </Row>
  393. </div>
  394. <div className="mt-4">
  395. <Row gutter={16}>
  396. <Col className="gutter-row" span={16}>
  397. <BusinessChar
  398. loading={state.loading}
  399. data={state.businessChar}
  400. changeGroupId={handleChangeGroupId}
  401. />
  402. </Col>
  403. <Col className="gutter-row" span={8}>
  404. <Card
  405. headStyle={{ padding: '0 12px' }}
  406. title="数据汇总"
  407. className="shadow-card"
  408. bodyStyle={{ padding: state.loading ? '24px' : 0 }}
  409. loading={state.loading}>
  410. <ul>
  411. <li className="px-12px py-16px border-b-1">
  412. 新增客户<b className="px-1">{state.aggregation.customerCount}</b>个,服务
  413. <b className="px-1">{state.aggregation.customerServiceCount}</b>条
  414. </li>
  415. <li className="px-12px py-16px border-b-1">
  416. 新增联系人<b className="px-1">{state.aggregation.clientCount}</b>个,服务
  417. <b className="px-1">{state.aggregation.clientServiceCount}</b> 条
  418. </li>
  419. <li className="px-12px py-16px">
  420. 新增商机<b className="px-1">{state.aggregation.businessCount}</b>个,金额
  421. <b className="px-1">{state.aggregation.businessSum}</b> 元,服务
  422. <b className="px-1">{state.aggregation.businessServiceCount}</b>
  423. 条,赢单<b className="px-1">{state.aggregation.businessWinCount}</b>个
  424. </li>
  425. </ul>
  426. </Card>
  427. </Col>
  428. </Row>
  429. </div>
  430. <div className="mt-4">
  431. <Row gutter={24}>
  432. <Col className="gutter-row" span={12}>
  433. <LeaderBoard dataList={state.leaderboard} loading={state.loading} />
  434. </Col>
  435. <Col className="gutter-row" span={12}>
  436. <SoftLeaderboard
  437. productLeaderBoard={state.productLeaderBoard}
  438. loading={state.loading}
  439. />
  440. </Col>
  441. </Row>
  442. </div>
  443. </div>
  444. )
  445. }
  446. export default Dashboard