tsg-web/src/views/sz/szzf/ajtj/bincharts.js

125 lines
4.1 KiB
JavaScript
Raw Normal View History

2024-09-24 14:37:41 +08:00
import { Space, Table, Tag, DatePicker, Form, Select, Button, Card } from 'antd';
import ReactECharts from 'echarts-for-react';
2024-09-24 16:52:00 +08:00
import { useEffect, useState, useMemo } from 'react';
2024-09-26 17:59:26 +08:00
import { httpget, httppost } from '../../../../utils/request';
import apiurl from '../../../../service/apiurl';
import dayjs from 'dayjs';
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'
2024-09-24 14:37:41 +08:00
2024-09-26 17:59:26 +08:00
dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)
let obj={0:'巡查上报',1:'自主发现',2:'公共举报',3:'电话举报',4:'其他'}
2024-09-24 16:52:00 +08:00
const Page = ({ title = '标题' }) => {
2024-09-24 14:37:41 +08:00
const [echart2, setEchart2] = useState(Object())
const [inspectordata, setInspectorData] = useState([{}])
const [plandata, setPlanData] = useState(Object())
const [problemdata, setProblemData] = useState(Object())
2024-09-26 17:59:26 +08:00
const [sumTotal, setSum] = useState(0)
2024-09-24 14:37:41 +08:00
const getPlanOption = useMemo((name, data) => {
// let total = 0
// for (let i = 0; i < data.length; i++) {
// total = total + Number(data[i].value)
// }
return {
title: {},
tooltip: {},
2024-09-26 17:59:26 +08:00
legend: {
data:Object.values(obj)
},
2024-09-24 14:37:41 +08:00
graphic: {
type: 'text',
top: 'center',
left: 'center',
style: {
2024-09-26 17:59:26 +08:00
text: `总计\n${sumTotal}`,
2024-09-24 14:37:41 +08:00
fontSize: 20,
fontWeight: 'bold',
2024-09-26 17:59:26 +08:00
textAlign: 'center'
2024-09-24 14:37:41 +08:00
}
},
series: {
name: '圆环图系列名称',
type: 'pie',
center: ['50%', '50%'],
radius: ['60%', '80%'],
hoverAnimation: true,
data: plandata,
label: {
normal: {
show: true,
position: 'outside',
formatter: '{c}'
}
}
}
}
2024-09-24 16:52:00 +08:00
}, [plandata])
2024-09-24 14:37:41 +08:00
console.log(getPlanOption);
2024-09-24 16:52:00 +08:00
2024-09-24 14:37:41 +08:00
const onOk = (event, index) => {
if (event !== null) {
let params = {
2024-09-26 17:59:26 +08:00
stm: dayjs(new Date(event[0])).format('YYYY-MM-DD HH:mm:ss'),
etm: dayjs(new Date(event[1])).format('YYYY-MM-DD HH:mm:ss'),
2024-09-24 14:37:41 +08:00
}
// getStm(params, index)
2024-09-26 17:59:26 +08:00
getInfo(params)
2024-09-24 14:37:41 +08:00
}
}
2024-09-26 17:59:26 +08:00
const getInfo=(params)=>{
let obj1=[]
let sum=0
httppost(apiurl.szzf.ajtj.info+0,params).then(res=>{
res.data.map(item=>{
obj1.push({value:item.count,name:obj[item.type]})
sum=sum+item.count
})
// debugger;
setPlanData(obj1)
setSum(sum)
})
}
2024-09-24 16:52:00 +08:00
useEffect(() => {
2024-09-26 17:59:26 +08:00
let params = {
stm: dayjs().startOf("year").format('YYYY-MM-DD HH:mm:ss'),
etm: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}
getInfo(params)
},[])
2024-09-24 14:37:41 +08:00
return (
<>
<div className='top' style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
2024-09-24 16:52:00 +08:00
<div style={{ fontSize: 20, fontWeight: 'bold', display: 'flex', alignItems: 'center' }}>
<div style={{ width: 5, height: 25, backgroundColor: '#259def', marginRight: 10 }}></div>
2024-09-26 17:59:26 +08:00
案件来源
2024-09-24 16:52:00 +08:00
</div>
2024-09-24 14:37:41 +08:00
<DatePicker.RangePicker
style={{ width: 220, }}
onChange={(e, index) => onOk(e, 2)}
defaultValue={[dayjs().startOf("year"), dayjs()]}
></DatePicker.RangePicker>
</div>
<ReactECharts
ref={(e) => setEchart2(e)}
option={getPlanOption}
style={{ height: 350 }}
/>
</>
)
}
export default Page