RatioPanels.jsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. import React, { useState } from 'react'
  2. import ProTable from '@ant-design/pro-table'
  3. import CustomModal from '@/components/Modal/src/components/CustomModal'
  4. import { queryRatioPanelsList, queryServiceRatioPanelsList } from '@/services/dashboard'
  5. import consts from '@/consts'
  6. import { servicelogEnum } from '@/pages/Customer/Company/components/CompanyDetail/LowerList'
  7. import ClientDetail from '@/pages/Customer/Client/components/ClientDetail'
  8. import CompanyDetail from '@/pages/Customer/Company/components/CompanyDetail'
  9. import { Badge } from 'antd'
  10. import { cardTypeMap } from '../consts'
  11. import { useModal } from '@/components/Modal'
  12. const dataTypeEunm = {
  13. 0: {
  14. key: 'client',
  15. title: '新增客户'
  16. },
  17. 1: {
  18. key: 'customer',
  19. title: '新增单位'
  20. },
  21. 2: {
  22. key: 'business',
  23. title: '新增商机'
  24. },
  25. 3: {
  26. key: 'service',
  27. title: '新增服务记录'
  28. }
  29. }
  30. const renderBadge = (count, active = false) => {
  31. return active ? (
  32. <Badge
  33. count={count}
  34. style={{
  35. marginTop: -2,
  36. marginLeft: 4,
  37. color: '#531dab',
  38. backgroundColor: '#f9f0ff'
  39. }}
  40. />
  41. ) : null
  42. }
  43. /** 服务环比数据Tab切换表格 */
  44. const ServiceRatioPanels = ({ staffIds, cyclical, dataPermission }) => {
  45. const { toggleDrawer, setDrawerProps } = useModal()
  46. const activeKeyMap = {
  47. 0: { key: 'clientName', title: '客户', id: 'clientId' },
  48. 1: { key: 'customerName', title: '单位', id: 'customerId' },
  49. 2: { key: 'businessName', title: '商机', id: 'businessId' }
  50. }
  51. const [state, setState] = useState({
  52. orderIds: [],
  53. activeKey: '0',
  54. total: 0
  55. })
  56. const showDrawer = id => {
  57. let children = null
  58. if (state.activeKey === '0') {
  59. children = <ClientDetail dataId={id} orderIds={state.orderIds} />
  60. }
  61. if (state.activeKey === '1') {
  62. children = <CompanyDetail dataId={id} orderIds={state.orderIds} />
  63. }
  64. setDrawerProps({
  65. zIndex: 1001,
  66. closable: true,
  67. onClose: () => toggleDrawer(),
  68. bodyStyle: {
  69. height: '100vh',
  70. overflowY: 'hidden'
  71. },
  72. children
  73. })
  74. toggleDrawer()
  75. }
  76. const columns = [
  77. {
  78. dataIndex: activeKeyMap[state.activeKey].key,
  79. title: `${activeKeyMap[state.activeKey].title}名称`,
  80. width: '15%',
  81. render: (text, record) => (
  82. <span
  83. onClick={() => showDrawer(record[activeKeyMap[state.activeKey].id])}
  84. className="text-primary cursor-pointer hover:text-[#967bbd]">
  85. {text}
  86. </span>
  87. )
  88. },
  89. {
  90. dataIndex: 'status',
  91. title: '服务类型',
  92. width: '8%',
  93. render: type => servicelogEnum[type]
  94. },
  95. {
  96. dataIndex: 'date',
  97. title: '服务日期',
  98. width: '9%',
  99. valueType: 'date'
  100. },
  101. {
  102. dataIndex: 'mark',
  103. width: '38%',
  104. ellipsis: true,
  105. title: '服务内容'
  106. },
  107. {
  108. dataIndex: 'staffName',
  109. title: '创建人',
  110. width: '7%'
  111. }
  112. ]
  113. return (
  114. <ProTable
  115. size="small"
  116. params={{ dataType: state.activeKey, cyclical, dataPermission, staffIds }}
  117. rowKey={record => record.id}
  118. scroll={{ y: 400 }}
  119. bordered={true}
  120. columns={columns}
  121. search={false}
  122. toolbar={{
  123. settings: false,
  124. menu: {
  125. type: 'tab',
  126. activeKey: state.activeKey,
  127. items: [
  128. {
  129. key: '0',
  130. label: (
  131. <span>
  132. 客户
  133. {renderBadge(state.total, state.activeKey === '0')}
  134. </span>
  135. )
  136. },
  137. {
  138. key: '1',
  139. label: (
  140. <span>
  141. 单位
  142. {renderBadge(state.total, state.activeKey === '1')}
  143. </span>
  144. )
  145. },
  146. {
  147. key: '2',
  148. label: (
  149. <span>
  150. 商机
  151. {renderBadge(state.total, state.activeKey === '2')}
  152. </span>
  153. )
  154. }
  155. ],
  156. onChange: key => {
  157. setState({ ...state, activeKey: key })
  158. // redoHeight()
  159. }
  160. }
  161. }}
  162. pagination={{ defaultPageSize: 10, showQuickJumper: true }}
  163. request={async params => {
  164. const { code = -1, data } = await queryServiceRatioPanelsList(params)
  165. setState({ ...state, total: data.total || 0 })
  166. return {
  167. data: data.log,
  168. success: code === consts.RET_CODE.SUCCESS,
  169. total: data.total
  170. }
  171. }}
  172. />
  173. )
  174. }
  175. const RatioPanels = ({ dataType, staffIds, retioCyclical, dataPermission }) => {
  176. const { toggleDrawer, setDrawerProps } = useModal()
  177. const state = {
  178. orderIds: []
  179. }
  180. const showDrawer = id => {
  181. setDrawerProps({
  182. zIndex: 1001,
  183. closable: true,
  184. onClose: () => toggleDrawer(),
  185. bodyStyle: {
  186. height: '100vh',
  187. overflowY: 'hidden'
  188. },
  189. children: <ClientDetail dataId={id} orderIds={state.orderIds} />
  190. })
  191. toggleDrawer()
  192. }
  193. // 展示单位
  194. const showDrawerComapny = id => {
  195. setDrawerProps({
  196. zIndex: 1001,
  197. closable: true,
  198. onClose: () => toggleDrawer(),
  199. bodyStyle: {
  200. height: '100vh',
  201. overflowY: 'hidden'
  202. },
  203. children: <CompanyDetail dataId={id} orderIds={state.orderIds} />
  204. })
  205. toggleDrawer()
  206. }
  207. const columnsMap = {
  208. 0: [
  209. {
  210. dataIndex: 'clientName',
  211. title: '客户名称',
  212. width: '10%',
  213. render: (clientName, record) => (
  214. <span
  215. onClick={() => showDrawer(record.id)}
  216. className="text-primary cursor-pointer hover:text-[#967bbd]">
  217. {clientName}
  218. </span>
  219. )
  220. },
  221. {
  222. dataIndex: 'companyName',
  223. title: '单位名称',
  224. ellipsis: true,
  225. width: '16%'
  226. },
  227. {
  228. dataIndex: 'districtName',
  229. title: '地区',
  230. width: '15%',
  231. ellipsis: true,
  232. renderText: text => text && text?.replaceAll(' / ', ' , ')
  233. },
  234. {
  235. dataIndex: 'phone',
  236. title: '手机',
  237. ellipsis: true,
  238. width: '5%'
  239. },
  240. {
  241. dataIndex: 'email',
  242. title: '邮箱',
  243. ellipsis: true,
  244. width: '7%'
  245. },
  246. {
  247. dataIndex: 'qq',
  248. title: 'QQ',
  249. ellipsis: true,
  250. width: '5%'
  251. },
  252. {
  253. dataIndex: 'staffName',
  254. title: '创建人',
  255. ellipsis: true,
  256. width: '7%'
  257. },
  258. {
  259. dataIndex: 'createTime',
  260. title: '创建时间',
  261. ellipsis: true,
  262. width: '7%'
  263. }
  264. ],
  265. 1: [
  266. {
  267. dataIndex: 'companyName',
  268. title: '单位名称',
  269. width: '16%',
  270. render: (companyName, record) => (
  271. <span
  272. onClick={() => showDrawerComapny(record.id)}
  273. className="text-primary cursor-pointer hover:text-[#967bbd]">
  274. {companyName}
  275. </span>
  276. )
  277. },
  278. {
  279. dataIndex: 'districtName',
  280. title: '地区',
  281. width: '15%',
  282. ellipsis: true,
  283. renderText: text => text && text?.replaceAll(' / ', ' , ')
  284. },
  285. {
  286. dataIndex: 'nature',
  287. title: '单位性质',
  288. ellipsis: true,
  289. width: '14%'
  290. },
  291. {
  292. dataIndex: 'phone',
  293. title: '单位电话',
  294. ellipsis: true,
  295. width: '5%'
  296. },
  297. {
  298. dataIndex: 'staffName',
  299. title: '创建人',
  300. ellipsis: true,
  301. width: '7%'
  302. },
  303. {
  304. dataIndex: 'createTime',
  305. title: '创建时间',
  306. ellipsis: true,
  307. width: '7%'
  308. }
  309. ],
  310. 2: [
  311. {
  312. dataIndex: 'name',
  313. title: '商机名称',
  314. width: '15%'
  315. },
  316. {
  317. dataIndex: 'customerName',
  318. title: '单位名称',
  319. ellipsis: true,
  320. width: '20%'
  321. },
  322. {
  323. dataIndex: 'businessStatusName',
  324. title: '商机状态',
  325. ellipsis: true,
  326. width: '5%'
  327. },
  328. {
  329. dataIndex: 'price',
  330. title: '商机金额',
  331. ellipsis: true,
  332. width: '5%'
  333. },
  334. {
  335. dataIndex: 'staffName',
  336. title: '创建人',
  337. ellipsis: true,
  338. width: '7%'
  339. },
  340. {
  341. dataIndex: 'createTime',
  342. title: '创建时间',
  343. ellipsis: true,
  344. width: '7%'
  345. }
  346. ]
  347. }
  348. return (
  349. <CustomModal title={`卡片详情(${dataTypeEunm[dataType].title})`}>
  350. <div className="pb-4">
  351. {dataType === cardTypeMap.SERVICE ? (
  352. <ServiceRatioPanels
  353. cyclical={retioCyclical}
  354. dataPermission={dataPermission}
  355. staffIds={staffIds}
  356. />
  357. ) : (
  358. <div className="mx-4">
  359. <ProTable
  360. size="small"
  361. bordered={true}
  362. pagination={{ defaultPageSize: 10 }}
  363. rowKey={record => record.id}
  364. scroll={{ y: 400 }}
  365. columns={columnsMap[dataType]}
  366. params={{ dataType, dataPermission, cyclical: retioCyclical, staffIds }}
  367. request={async params => {
  368. const { code = -1, data } = await queryRatioPanelsList(params)
  369. return {
  370. data: data[dataTypeEunm[dataType].key],
  371. success: code === consts.RET_CODE.SUCCESS,
  372. total: data.total
  373. }
  374. }}
  375. search={false}
  376. toolBarRender={false}
  377. />
  378. </div>
  379. )}
  380. </div>
  381. {/* <div className={styles.modalFooter}>
  382. <div className="text-right">
  383. <Button type="button" onClick={closeModal}>
  384. 关闭
  385. </Button>
  386. </div>
  387. </div> */}
  388. </CustomModal>
  389. )
  390. }
  391. export default RatioPanels