index.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Row, Col, Spin } from 'antd'
  2. import React, { useState, useEffect } from 'react'
  3. import '../index.scss'
  4. import ContanctForm from '@/components/PopContent/Contacts/ContanctForm.jsx'
  5. import ContanctTabList from '@/components/PopContent/Contacts/ContanctTabList.jsx'
  6. import ContanctLowerList from '@/components/PopContent/Contacts/ContanctLowerList.jsx'
  7. import { apiContactDetail } from '@/services/contact'
  8. import consts from '@/consts'
  9. import { connect } from 'dva'
  10. const PopContent = props => {
  11. const { dispatch, shouldUpdate, visible, id = '' } = props
  12. const [state, setState] = useState({
  13. loading: false,
  14. client: {},
  15. log: [],
  16. serviceLog: []
  17. })
  18. const initData = async () => {
  19. setState({ ...state, loading: true })
  20. const {
  21. data: { client = {}, log = [], serviceLog = [] },
  22. code = -1
  23. } = await apiContactDetail(id)
  24. if (code === consts.RET_CODE.SUCCESS) {
  25. if (shouldUpdate) {
  26. dispatch({
  27. type: 'refresh/commitAction',
  28. payload: 'contact'
  29. })
  30. }
  31. setState({ ...state, client, log, serviceLog, loading: false })
  32. }
  33. }
  34. useEffect(() => {
  35. if (shouldUpdate) {
  36. initData()
  37. }
  38. }, [shouldUpdate])
  39. useEffect(() => {
  40. visible && initData()
  41. }, [])
  42. return (
  43. <Spin spinning={state.loading}>
  44. <div className="sheet-box">
  45. <Row>
  46. <Col span={12} className="sheet-box-left">
  47. <div className="sheet-left-panel zh-pd-right-15">
  48. <ContanctForm client={state.client} />
  49. </div>
  50. </Col>
  51. <Col span={12}>
  52. <ContanctTabList />
  53. <ContanctLowerList log={state.log} servicelist={state.serviceLog} />
  54. </Col>
  55. </Row>
  56. </div>
  57. </Spin>
  58. )
  59. }
  60. export default connect(({ refresh, single }) => ({
  61. visible: single.drawer.visible,
  62. shouldUpdate: refresh.contact
  63. }))(PopContent)