EscalationCharts.jsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { useState } from 'react';
  2. import { Card, Select } from 'antd';
  3. import * as echarts from 'echarts/core';
  4. import Chart from '@/components/chart';
  5. import { getStatEscalation } from "@/service/stat";
  6. import { getSysOrg } from "@/service/sysorg";
  7. export default (props) => {
  8. const [option, setOption] = useState({});
  9. const [orgList, setOrgList] = useState([]);
  10. const [orgId, setOrgId] = useState();
  11. const [condition, setCondition] = useState();
  12. React.useEffect(() => {
  13. if (orgList.length > 0) {
  14. const e = orgList[0]?.orgId
  15. setCondition({ orgId: e })
  16. setOrgId(e)
  17. }
  18. }, [orgList])
  19. React.useEffect(() => {
  20. getSysOrg({ pageSize: 500 }).then((res) => {
  21. setOrgList(res.records || [])
  22. })
  23. }, []);
  24. //选择下拉框将条件参数set给condition
  25. const onChange = e => {
  26. setCondition({ orgId: e })
  27. setOrgId(e)
  28. }
  29. React.useEffect(() => {
  30. getStatEscalation(condition).then((res) => {
  31. setOption({
  32. tooltip: {
  33. trigger: 'axis',
  34. axisPointer: {
  35. type: 'cross',
  36. label: {
  37. backgroundColor: '#F772D1'
  38. }
  39. }
  40. },
  41. grid: {
  42. left: '3%',
  43. bottom: '3%',
  44. width: '90%',
  45. height: '90%',
  46. containLabel: true
  47. },
  48. xAxis: [
  49. {
  50. type: 'category',
  51. data: res.map(x => x.name),
  52. boundaryGap: true,
  53. name: '状态',
  54. axisTick: {
  55. alignWithLabel: true,
  56. }
  57. }
  58. ],
  59. yAxis: [
  60. {
  61. type: 'value',
  62. minInterval: 1,
  63. name: '交办次数'
  64. }
  65. ],
  66. series: [
  67. {
  68. type: 'bar',
  69. barWidth: '15%',
  70. itemStyle: {
  71. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  72. { offset: 0, color: '#F772D1' },
  73. { offset: 0.5, color: '#C872F2' },
  74. { offset: 1, color: '#E5BEF8' }
  75. ])
  76. },
  77. data: res.map(x => x.value),
  78. }
  79. ]
  80. })
  81. })
  82. }, [condition]);
  83. return (
  84. <Card
  85. title="交办统计"
  86. extra={
  87. <Select style={{ width: "200px" }} value={orgId} placeholder="请选择单位" onChange={onChange}>
  88. {
  89. orgList.map((item) => (
  90. <Select.Option key={item.orgId} value={item.orgId}>
  91. {item.name}
  92. </Select.Option>
  93. )
  94. )
  95. }
  96. </Select>
  97. }
  98. >
  99. <Chart option={option} style={props.style}></Chart>
  100. </Card>
  101. )
  102. }