index.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { Row, Col, Spin, Tooltip, Drawer } from 'antd'
  2. import React, { useState, useEffect } from 'react'
  3. import ClientForm from './Form.jsx'
  4. import ClientTabList from './TabList.jsx'
  5. import ClientLowerList from './LowerList.jsx'
  6. import { apiClientDetail } from '@/services/customer'
  7. import consts from '@/consts'
  8. import { connect } from 'umi'
  9. import { Up, Down } from '@icon-park/react'
  10. import { FlipOverEnum, useFlipOver } from '@/hooks/web/useFlipOver'
  11. const ClientDetail = props => {
  12. const { refresh, visible, dispatch, updateKey = 'client', dataId, orderIds = [], ...resetDrawerProps } = props
  13. const shouldUpdate = refresh?.[dataId ?? updateKey] || false
  14. const [state, setState] = useState({
  15. loading: false,
  16. client: {},
  17. log: [],
  18. serviceLog: [],
  19. software: {}
  20. })
  21. const initData = async id => {
  22. setState({ ...state, loading: true })
  23. const {
  24. data: { client = {}, log = [], serviceLog = [], software = {} },
  25. code = -1
  26. } = await apiClientDetail(id)
  27. if (code === consts.RET_CODE.SUCCESS) {
  28. if (shouldUpdate) {
  29. dispatch({
  30. type: 'refresh/commitAction',
  31. payload: {
  32. main: updateKey,
  33. target: dataId
  34. }
  35. })
  36. }
  37. setState({ ...state, client, log, serviceLog, software, loading: false })
  38. }
  39. }
  40. const { flipFn, flipConsts } = useFlipOver(initData, dataId, orderIds)
  41. useEffect(() => {
  42. shouldUpdate && initData(dataId)
  43. }, [shouldUpdate])
  44. useEffect(() => {
  45. visible && initData(dataId)
  46. }, [visible])
  47. return (
  48. <Drawer {...resetDrawerProps} visible={visible} className="zh-drawer" contentWrapperStyle={{ width: 'unset' }}>
  49. <Spin spinning={state.loading}>
  50. <div className="sheet-box">
  51. <Row>
  52. <Col span={9} className="sheet-box-left">
  53. {orderIds.length ? (
  54. <div className="mb-3">
  55. <Tooltip title="上一条记录">
  56. <Up
  57. fill={flipConsts.disableUpBtn ? '#BDBDBE' : '#886ab5'}
  58. size="20"
  59. onClick={() => flipFn(FlipOverEnum.UP)}
  60. className={[flipConsts.disableUpBtn ? 'cursor-not-allowed' : 'cursor-pointer'].join(' ')}
  61. />
  62. </Tooltip>
  63. <Tooltip title="下一条记录">
  64. <Down
  65. fill={flipConsts.disableDownBtn ? '#BDBDBE' : '#886ab5'}
  66. size="20"
  67. onClick={() => flipFn(FlipOverEnum.DOWN)}
  68. className={[flipConsts.disableDownBtn ? 'cursor-not-allowed' : 'cursor-pointer', 'ml-1'].join(
  69. ' '
  70. )}
  71. />
  72. </Tooltip>
  73. </div>
  74. ) : null}
  75. <div className="sheet-left-panel pr-4">
  76. <ClientForm client={state.client} updatePayload={{ main: updateKey, target: dataId }} />
  77. </div>
  78. </Col>
  79. <Col
  80. span={15}
  81. // sm={{ span: 24 }}
  82. // md={{ span: 24 }}
  83. // lg={{ span: 15 }}
  84. // xl={{ span: 15 }}
  85. className="sheet-box-right">
  86. <ClientTabList
  87. clientId={state.client.id}
  88. software={state.software}
  89. updatePayload={{ main: updateKey, target: dataId }}
  90. />
  91. <ClientLowerList log={state.log} servicelist={state.serviceLog} />
  92. </Col>
  93. </Row>
  94. </div>
  95. </Spin>
  96. </Drawer>
  97. )
  98. }
  99. export default connect(({ refresh }) => ({
  100. refresh
  101. }))(ClientDetail)