WarningTable.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import ThresholdDetail from '@/components/ThresholdDetail';
  2. import ThresholdModal from '@/components/ThresholdDetail/ThresholdModal';
  3. import { changeRecordStatus } from '@/services/eqSelfInspection';
  4. import { Table, message } from 'antd';
  5. import { useState } from 'react';
  6. import styles from '../PatrolReportDetail.less';
  7. import Empty from './Empty';
  8. import ErrorHandleModal from './ErrorHandleModal';
  9. export default function WarningTable(props) {
  10. const { data, userList, items, mandate = [] } = props;
  11. const [loading, setLoading] = useState(false);
  12. const [visible, setVisible] = useState(false);
  13. const [errVisible, setErrVisible] = useState(false);
  14. const [currentItem, setCurrentItem] = useState({});
  15. const handleError = async (values) => {
  16. setLoading(true);
  17. var res = await changeRecordStatus({
  18. ...values,
  19. Id: currentItem.Id,
  20. DeviceCode: currentItem.DeviceCode,
  21. DeviceName: currentItem.DeviceName,
  22. RecordId: data.Id,
  23. RepairMan: values.RepairMan * 1,
  24. });
  25. setLoading(false);
  26. if (res) {
  27. message.success('操作成功');
  28. setErrVisible(false);
  29. }
  30. };
  31. const columns = [
  32. {
  33. title: '设备名称',
  34. width: '20%',
  35. dataIndex: 'DeviceName',
  36. },
  37. {
  38. title: '巡检项',
  39. dataIndex: ['TemplateItem', 'Name'],
  40. },
  41. {
  42. title: '设定值范围',
  43. width: '30%',
  44. render: (record) => (
  45. <ThresholdDetail current={record.Value || 0} data={record || {}} />
  46. ),
  47. },
  48. {
  49. title: '状态',
  50. dataIndex: 'Status',
  51. width: '1.25rem',
  52. render: (Status) => {
  53. switch (Status) {
  54. case -1:
  55. case 0:
  56. return (
  57. <div>
  58. <i
  59. className={styles.iconStatus}
  60. style={{ background: '#12CEB3' }}
  61. ></i>
  62. 正常
  63. </div>
  64. );
  65. case 1:
  66. return (
  67. <div>
  68. <i
  69. className={styles.iconStatus}
  70. style={{ background: '#FE5850' }}
  71. ></i>
  72. 异常
  73. </div>
  74. );
  75. case 2:
  76. return (
  77. <div>
  78. <i
  79. className={styles.iconStatus}
  80. style={{ background: '#FFE26D' }}
  81. ></i>
  82. 警告
  83. </div>
  84. );
  85. }
  86. },
  87. },
  88. {
  89. title: '关联任务',
  90. render: (record) => <a>{mandate?.find(item => item.source == record.Id)?.id}</a>,
  91. },
  92. ];
  93. return (
  94. <div>
  95. <Table
  96. columns={columns}
  97. dataSource={items}
  98. rowKey="Id"
  99. locale={{
  100. emptyText: <Empty />,
  101. }}
  102. pagination={false}
  103. />
  104. <ThresholdModal
  105. open={visible}
  106. data={currentItem.JsonNumThreshold}
  107. onClose={() => setVisible(false)}
  108. />
  109. <ErrorHandleModal
  110. open={errVisible}
  111. userList={userList}
  112. onCancel={() => setErrVisible(false)}
  113. onOk={handleError}
  114. />
  115. </div>
  116. );
  117. }