index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import { queryWorkReport } from '@/services/smartReport';
  4. import { useNavigate, useParams, useRequest } from '@umijs/max';
  5. import { ConfigProvider, DatePicker, Select, Spin } from 'antd';
  6. import zhCN from 'antd/es/locale/zh_CN';
  7. import dayjs from 'dayjs';
  8. import * as echarts from 'echarts';
  9. import { useEffect, useRef, useState } from 'react';
  10. import styles from './index.less';
  11. const { RangePicker } = DatePicker;
  12. const SmartReport = () => {
  13. const navigate = useNavigate();
  14. const { projectId } = useParams();
  15. const FORMAT = 'YYYY-MM-DD';
  16. const [showRange, setShowRange] = useState(false);
  17. const [date, setDate] = useState({
  18. stime: dayjs().subtract(7, 'day').format(FORMAT),
  19. etime: dayjs().subtract(1, 'day').format(FORMAT),
  20. });
  21. const eqDomRef = useRef(null);
  22. const eqChartRef = useRef(null);
  23. const taskDomRef = useRef(null);
  24. const taskChartRef = useRef(null);
  25. const workDomRef = useRef(null);
  26. const workChartRef = useRef(null);
  27. const workScoreDomRef = useRef(null);
  28. const workScoreChartRef = useRef(null);
  29. const {
  30. data = {},
  31. run,
  32. loading,
  33. } = useRequest(
  34. (date) =>
  35. queryWorkReport({
  36. project_id: projectId,
  37. ...date,
  38. }),
  39. {
  40. defaultParams: [{ project_id: projectId, ...date }],
  41. formatResult: (res) => {
  42. const data = res.data;
  43. return {
  44. ...data,
  45. eqData: [
  46. { name: '安全隐患', value: data.patrol_safe },
  47. { name: '工艺异常', value: data.patrol_section },
  48. { name: '设备异常', value: data.push_complete_task },
  49. ],
  50. taskData: [
  51. { name: '工况任务', value: data.mandate_type_con },
  52. { name: '集团任务', value: data.mandate_type_group },
  53. { name: '系统自检', value: data.mandate_type_pat },
  54. { name: '生产任务', value: data.mandate_type_pro },
  55. ],
  56. workOrderData: [
  57. { name: '盘点', value: data.chart_check },
  58. { name: '备品备件', value: data.chart_part },
  59. { name: '工艺工单', value: data.chart_section },
  60. { name: '维修工单', value: data.repair_record },
  61. { name: '保养工单', value: data.maintain_record },
  62. { name: '巡检工单', value: data.patrol_mandate_record },
  63. { name: '加药工单', value: data.reagent_record },
  64. ],
  65. workScoreData: [
  66. { name: '较差', value: data.con_level_five },
  67. { name: '一般', value: data.con_level_four },
  68. { name: '优秀', value: data.con_level_one },
  69. { name: '较好', value: data.con_level_three },
  70. { name: '良好', value: data.con_level_two },
  71. ],
  72. };
  73. },
  74. },
  75. );
  76. const handleChange = (value) => {
  77. const date = { ...date };
  78. switch (value) {
  79. case '1':
  80. date.stime = dayjs().subtract(7, 'day').format(FORMAT);
  81. date.etime = dayjs().subtract(1, 'day').format(FORMAT);
  82. setDate(date);
  83. setShowRange(false);
  84. run(date);
  85. break;
  86. case '2':
  87. date.stime = dayjs().subtract(1, 'month').format(FORMAT);
  88. date.etime = dayjs().subtract(1, 'day').format(FORMAT);
  89. setDate(date);
  90. setShowRange(false);
  91. run(date);
  92. break;
  93. case '3':
  94. setShowRange(true);
  95. break;
  96. }
  97. };
  98. const {
  99. ele_65,
  100. ele_66,
  101. electricity,
  102. in_water,
  103. maintain_record,
  104. medicine,
  105. out_water,
  106. push_optimize_task,
  107. push_complete_task,
  108. push_complete_task_per,
  109. push_task,
  110. repair_record,
  111. self_inspection_abnormal_task,
  112. self_inspection_normal_task,
  113. self_inspection_task,
  114. water_electricity,
  115. water_medicine,
  116. work_order_complete_task,
  117. work_order_complete_task_per,
  118. work_order_task,
  119. } = data;
  120. useEffect(() => {
  121. initData();
  122. }, [data]);
  123. useEffect(() => {
  124. eqChartRef.current = echarts.init(eqDomRef.current);
  125. taskChartRef.current = echarts.init(taskDomRef.current);
  126. workChartRef.current = echarts.init(workDomRef.current);
  127. workScoreChartRef.current = echarts.init(workScoreDomRef.current);
  128. return () => {
  129. eqChartRef.current.dispose();
  130. taskChartRef.current.dispose();
  131. workChartRef.current.dispose();
  132. workScoreChartRef.current.dispose();
  133. };
  134. }, []);
  135. const initData = () => {
  136. const eqOption = getPieOption(data.eqData, '异常类型统计');
  137. if (eqChartRef.current) eqChartRef.current.setOption(eqOption);
  138. const taskOption = getPieOption(data.taskData, '任务类型统计');
  139. if (taskChartRef.current) taskChartRef.current.setOption(taskOption);
  140. const workOption = getPieOption(data.workOrderData, '工况评估统计');
  141. if (workChartRef.current) workChartRef.current.setOption(workOption);
  142. const workScoreOption = getPieOption(data.workScoreData, '工况评估统计');
  143. if (workScoreChartRef.current)
  144. workScoreChartRef.current.setOption(workScoreOption);
  145. };
  146. const onChange = (value) => {
  147. if (!value) return;
  148. const date = { ...date };
  149. date.stime = value[0].format(FORMAT);
  150. date.etime = value[1].format(FORMAT);
  151. run(date);
  152. setDate(date);
  153. };
  154. const handleOnClick = () => {
  155. history.back();
  156. };
  157. const Box = ({ title, children }) => {
  158. return (
  159. <div className={styles.box}>
  160. <div className={styles.main_in}>
  161. <div className={styles.titleContent}>{title}</div>
  162. {children}
  163. </div>
  164. </div>
  165. );
  166. };
  167. return (
  168. <PageContent closeable={false}>
  169. <ConfigProvider locale={zhCN}>
  170. <PageTitle children="智慧运营报告" returnable />
  171. <div className={styles.head}>
  172. {/* <div className={styles.name}>智慧运营报告</div> */}
  173. <div className={styles.photo}>
  174. {dayjs(date.stime).format('MM月DD日')}-
  175. {dayjs(date.etime).format('MM月DD日')}
  176. </div>
  177. <div className={styles.headRight}>
  178. <div>
  179. 时间:
  180. <Select
  181. className={styles.headRightSelect}
  182. defaultValue="1"
  183. style={{ width: 180 }}
  184. onChange={handleChange}
  185. popupClassName={styles.headRightSelect}
  186. options={[
  187. {
  188. value: '1',
  189. label: '近7天',
  190. },
  191. {
  192. value: '2',
  193. label: '近30天',
  194. },
  195. {
  196. value: '3',
  197. label: '自定义时间',
  198. },
  199. ]}
  200. />
  201. </div>
  202. <div>
  203. {showRange && <RangePicker inputReadOnly onChange={onChange} />}
  204. </div>
  205. </div>
  206. </div>
  207. <div className={styles.title}>无锡锡山水厂</div>
  208. <Spin spinning={loading}>
  209. <Box title="概览">
  210. <div className={styles.content}>
  211. <div className={styles.item}>累计进水:{in_water}</div>
  212. <div className={styles.item}>累计出水:{out_water}</div>
  213. <div className={styles.item}>吨水能耗:{water_electricity}</div>
  214. <div className={styles.item}>吨水药耗:{water_medicine}kg/m³</div>
  215. <div className={styles.item}>
  216. 系统自检次数:{self_inspection_task}次
  217. </div>
  218. <div className={styles.item}>
  219. 优化建议: {push_optimize_task}条
  220. </div>
  221. <div className={styles.item}>
  222. 任务完成:{push_complete_task}个
  223. </div>
  224. <div className={styles.item}>
  225. 工单完成:{work_order_complete_task}个
  226. </div>
  227. <div className={styles.item}>设备维修:{repair_record}个</div>
  228. <div className={styles.item}>设备保养:{maintain_record}个</div>
  229. </div>
  230. </Box>
  231. <Box title="水量">
  232. <div className={styles.content}>
  233. <div className={styles.item}>累计进水:{in_water}</div>
  234. <div className={styles.item}>累计出水:{out_water}</div>
  235. </div>
  236. </Box>
  237. <Box title="能耗">
  238. <div className={styles.content}>
  239. <div className={styles.item}>吨水能耗:{water_electricity}</div>
  240. <div className={styles.item}>累计耗电量:{electricity}kwh</div>
  241. </div>
  242. </Box>
  243. <Box title="药耗">
  244. <div className={styles.content}>
  245. <div className={styles.item}>吨水药耗:{water_medicine}kg/m³</div>
  246. <div className={styles.item}>累计用药量:{medicine}</div>
  247. </div>
  248. </Box>
  249. <Box title="系统自检">
  250. <div className={styles.threeContent}>
  251. <div className={styles.numItem}>
  252. <div>{self_inspection_task}</div>
  253. <div>自检次数</div>
  254. </div>
  255. <div className={styles.numItem}>
  256. <div>{self_inspection_abnormal_task}</div>
  257. <div>异常次数</div>
  258. </div>
  259. <div className={styles.numItem}>
  260. <div>{self_inspection_normal_task}</div>
  261. <div>正常次数</div>
  262. </div>
  263. </div>
  264. <div
  265. ref={eqDomRef}
  266. style={{ height: '340px', margin: '10px 0 10px 0' }}
  267. ></div>
  268. {/* <div>异常类型统计(设备异常、工艺异常、安全隐患异常)</div> */}
  269. </Box>
  270. <Box title="智慧运营">
  271. <div style={{ padding: '20px 20px 0 20px' }}>
  272. <div className={styles.smartText}>
  273. 优化条数:{push_optimize_task}条
  274. </div>
  275. <div className={styles.smartText}>超滤能耗:{ele_65}</div>
  276. <div className={styles.smartText}>反渗透能耗:{ele_66}</div>
  277. </div>
  278. <div
  279. ref={workScoreDomRef}
  280. style={{ height: '340px', margin: '10px 0 10px 0' }}
  281. ></div>
  282. </Box>
  283. <Box title="任务工单">
  284. <div className={styles.content}>
  285. <div className={styles.item}>任务数量:{push_task}</div>
  286. <div className={styles.item}>工单数量:{work_order_task}</div>
  287. <div className={styles.item}>
  288. 任务完成数量:{push_complete_task}
  289. </div>
  290. <div className={styles.item}>
  291. 工单完成数量:{work_order_complete_task}
  292. </div>
  293. <div className={styles.item}>
  294. 任务完成率:{Number(push_complete_task_per)}%
  295. </div>
  296. <div className={styles.item}>
  297. 工单完成率:{Number(work_order_complete_task_per)}%
  298. </div>
  299. <div className={styles.item}>
  300. <div ref={taskDomRef} style={{ height: '400px' }}></div>
  301. </div>
  302. <div className={styles.item}>
  303. <div ref={workDomRef} style={{ height: '400px' }}></div>
  304. </div>
  305. </div>
  306. </Box>
  307. <Box title="设备维修保养">
  308. <div className={styles.content}>
  309. <div className={styles.item}>维修数量:{repair_record}</div>
  310. <div className={styles.item}>保养数量:{maintain_record}</div>
  311. </div>
  312. </Box>
  313. </Spin>
  314. </ConfigProvider>
  315. </PageContent>
  316. );
  317. };
  318. export default SmartReport;
  319. const getPieOption = (chartData, name) => {
  320. const option = {
  321. title: {
  322. text: name,
  323. top: '92%',
  324. left: '50%',
  325. textAlign: 'center',
  326. textStyle: {
  327. color: '#000000',
  328. fontWeight: 'normal',
  329. fontSize: 18,
  330. },
  331. },
  332. color: [
  333. '#5470c6',
  334. '#91cc75',
  335. '#fac858',
  336. '#ee6666',
  337. '#73c0de',
  338. '#3ba272',
  339. '#fc8452',
  340. '#9a60b4',
  341. '#ea7ccc',
  342. ],
  343. tooltip: {
  344. trigger: 'item',
  345. },
  346. legend: {
  347. orient: 'horizontal',
  348. // left: 'left',
  349. textStyle: {
  350. color: '#000000',
  351. fontSize: 18,
  352. },
  353. },
  354. series: [
  355. {
  356. type: 'pie',
  357. radius: '50%',
  358. data: chartData,
  359. emphasis: {
  360. itemStyle: {
  361. shadowBlur: 10,
  362. shadowOffsetX: 0,
  363. shadowColor: 'rgba(0, 0, 0, 0.5)',
  364. },
  365. },
  366. },
  367. ],
  368. };
  369. return option;
  370. };