index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import Header from '@/components/Header'
  2. import { tenderStore } from '@/store/mobx'
  3. import consts from '@/utils/consts'
  4. import dayjs from 'dayjs'
  5. import React, { useEffect, useState, useMemo } from 'react'
  6. import { Link } from 'react-router-dom'
  7. import { apiGetSafeSurvey } from './api'
  8. import ColumnChart from './columnChart'
  9. import './index.scss'
  10. import PieChart from './pieChart'
  11. export interface SafeColumnCharType {
  12. name: 'rectifyed' | 'submit'
  13. month: string
  14. count: number
  15. }
  16. export interface SafeLineChartType {
  17. month: string
  18. percentage: number
  19. }
  20. interface iRectifyData {
  21. auditName: string
  22. createTime: string
  23. id: string
  24. inspectionDetail: string
  25. status: number
  26. }
  27. interface iSummaryState {
  28. approvalTotal: number
  29. rectifyTotal: number
  30. rectifyedTotal: number
  31. rectifylist: iRectifyData[]
  32. columnarData: SafeColumnCharType[]
  33. lineData: SafeLineChartType[]
  34. }
  35. const Summary: React.FC<{}> = () => {
  36. const [ state, setState ] = useState<iSummaryState>({
  37. approvalTotal: 0,
  38. rectifyTotal: 0,
  39. rectifyedTotal: 0,
  40. rectifylist: [],
  41. columnarData: [],
  42. lineData: []
  43. })
  44. useEffect(() => {
  45. initData()
  46. }, [])
  47. const initData = async () => {
  48. const { data, code = -1 } = await apiGetSafeSurvey(tenderStore.bid)
  49. if (code === consts.RET_CODE.SUCCESS) {
  50. setState({ ...state, ...data })
  51. }
  52. }
  53. const pieData = useMemo(() => {
  54. const data = [
  55. {
  56. type: '审批中',
  57. value: state.approvalTotal
  58. },
  59. {
  60. type: '整改中',
  61. value: state.rectifyTotal
  62. },
  63. {
  64. type: '已完成',
  65. value: state.rectifyedTotal
  66. }
  67. ]
  68. return data
  69. }, [ state.approvalTotal, state.rectifyTotal, state.rectifyedTotal ])
  70. const columnCharData = useMemo(() => {
  71. return { columnData: state.columnarData, lineData: state.lineData }
  72. }, [ state.columnarData, state.lineData ])
  73. const handleDate = (createTime: string) => {
  74. return dayjs(new Date()).diff(dayjs(createTime), 'day') + '天'
  75. }
  76. return (
  77. <div className="wrap-contaniner">
  78. <Header title="巡检概况" />
  79. <div className="wrap-content m-3 pi-flex-column pi-justify-start">
  80. <div className="pi-justify-start">
  81. <div className="pi-flex-twice card pi-flex-column">
  82. <header className="card-title">整改中 ({state.rectifyTotal}) </header>
  83. <div>
  84. {state.rectifylist.map(item => {
  85. return (
  86. <div key={item.id} className="pi-justify-between pi-lh-18 pi-height-18 pi-mg-2">
  87. <Link to={{ pathname: '/console/safe/content/detail/info', state: { id: item.id } }}>{item.inspectionDetail}</Link>
  88. <div className="pi-align-center">
  89. <span className="pi-mg-right-5">{item.auditName}</span>
  90. <span className="pi-badge danger">{handleDate(item.createTime)}</span>
  91. </div>
  92. </div>
  93. )
  94. })}
  95. </div>
  96. </div>
  97. <div className="pi-flex-treble pi-mg-left-30 card">
  98. <PieChart data={pieData} />
  99. </div>
  100. </div>
  101. <div className="card echarts-column-chart mt-3">
  102. <h5 className="pi-fz-25 pi-fw-5">整改趋势</h5>
  103. <div className="pi-width-100P">
  104. <ColumnChart data={columnCharData} />
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. )
  110. }
  111. export default Summary