LiquidLevelCom.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import TabsContent from '@/components/TabsContent';
  2. import ThresholdDetail from '@/components/ThresholdDetail';
  3. import { Popover, Table } from 'antd';
  4. import dayjs from 'dayjs';
  5. import { useEffect, useMemo, useState } from 'react';
  6. import styles from '../PatrolReportDetail.less';
  7. import Empty from './Empty';
  8. import MandateBtn from './MandateBtn';
  9. export default function LiquidLevelCom(props) {
  10. const {
  11. sendMessageToUnity,
  12. select,
  13. allData,
  14. type,
  15. statusCheck,
  16. changeStatus,
  17. } = props;
  18. const [activeKey, setActiveKey] = useState('1');
  19. const handleTabsChange = (activeKey) => {
  20. setActiveKey(activeKey);
  21. };
  22. const { errorTableData, normalData } = useMemo(() => {
  23. let data = { errorTableData: [], normalData: [] };
  24. allData?.forEach((item) => {
  25. if (!item.history && item.status == 1 && statusCheck.includes(1)) {
  26. data.errorTableData.push(item);
  27. } else if (item.history && item.status == 0 && statusCheck.includes(0)) {
  28. data.normalData.push(item);
  29. }
  30. });
  31. return data;
  32. }, [statusCheck, allData]);
  33. const items = useMemo(() => {
  34. let items = [];
  35. let showAllTabs = statusCheck.length == 3;
  36. if (showAllTabs || errorTableData.length > 0) {
  37. items.push({
  38. key: '1',
  39. label: `异常(${errorTableData.length || 0})`,
  40. children: <div></div>,
  41. });
  42. }
  43. if (showAllTabs || normalData.length > 0) {
  44. items.push({
  45. key: '0',
  46. label: `历史记录(${normalData.length || 0})`,
  47. children: <div></div>,
  48. });
  49. }
  50. return items;
  51. }, [statusCheck, allData]);
  52. useEffect(() => {
  53. if (items.length == 0) {
  54. changeStatus(0);
  55. } else {
  56. setActiveKey(items[0].key);
  57. changeStatus(1);
  58. }
  59. }, [items]);
  60. const content = (
  61. <div className={styles.popoverContent}>
  62. <p>固定液位1为H1,固定液位2为H2,实际液位为H实</p>
  63. <p>液位差值:液位标准值(H1)与液位实际值(H2)的差值</p>
  64. <p>液位差比值:H1标准值与实际值的差值与H2的标准值与实际值的差值的比值</p>
  65. </div>
  66. );
  67. if (items.length == 0) return null;
  68. return (
  69. <div className={styles.detailCard}>
  70. <div className={styles.tableTop}>
  71. <div className={styles.tipTitle}>
  72. 液位校验
  73. <Popover content={content}>
  74. <i></i>
  75. </Popover>
  76. </div>
  77. <TabsContent
  78. active={activeKey}
  79. onChange={handleTabsChange}
  80. small
  81. items={items}
  82. ></TabsContent>
  83. </div>
  84. {activeKey === '1' && (
  85. <LiquidTable
  86. onClickItem={sendMessageToUnity}
  87. select={select}
  88. items={errorTableData}
  89. key={type}
  90. type={type}
  91. />
  92. )}
  93. {activeKey === '0' && (
  94. <LiquidTable
  95. onClickItem={sendMessageToUnity}
  96. select={select}
  97. items={normalData}
  98. key={type}
  99. type={type}
  100. />
  101. )}
  102. </div>
  103. );
  104. }
  105. function LiquidTable(props) {
  106. const { items } = props;
  107. const columns = [
  108. {
  109. title: '设备名称',
  110. width: '12%',
  111. dataIndex: 'device_name',
  112. },
  113. {
  114. title: '时间',
  115. dataIndex: 'record_time',
  116. render: (text) => {
  117. if (text) {
  118. return dayjs(text).format('YYYY.MM.DD HH:mm');
  119. }
  120. return '-';
  121. },
  122. },
  123. {
  124. title: '类型',
  125. key: 'template_item_name',
  126. dataIndex: 'template_item_name',
  127. },
  128. {
  129. title: '液位数',
  130. dataIndex: 'origin_value',
  131. },
  132. {
  133. title: '差值/比值',
  134. dataIndex: 'value',
  135. },
  136. {
  137. title: '设定值范围',
  138. width: '18%',
  139. render: (record) => (
  140. <ThresholdDetail
  141. current={record.value || 0}
  142. data={{
  143. JsonNumThreshold: record?.json_num_threshold,
  144. Type: record.type || 2,
  145. }}
  146. />
  147. ),
  148. },
  149. {
  150. title: '状态',
  151. dataIndex: 'status',
  152. render: (status, record) => {
  153. switch (status) {
  154. case -1:
  155. case 0:
  156. return (
  157. <div>
  158. <i
  159. className={styles.iconStatus}
  160. style={{ background: '#12CEB3' }}
  161. ></i>
  162. 正常
  163. </div>
  164. );
  165. case 1:
  166. return (
  167. <div>
  168. <i
  169. className={styles.iconStatus}
  170. style={{ background: '#FFE26D' }}
  171. ></i>
  172. 异常
  173. <MandateBtn relationId={record.id} />
  174. </div>
  175. );
  176. case 2:
  177. return (
  178. <div>
  179. <i
  180. className={styles.iconStatus}
  181. style={{ background: '#FFE26D' }}
  182. ></i>
  183. 警告
  184. </div>
  185. );
  186. }
  187. },
  188. },
  189. ];
  190. return (
  191. <Table
  192. columns={columns}
  193. dataSource={items}
  194. rowKey="device_code"
  195. locale={{
  196. emptyText: <Empty />,
  197. }}
  198. pagination={false}
  199. />
  200. );
  201. }