index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import PageContent from '@/components/PageContent';
  2. import TabsContent from '@/components/TabsContent';
  3. import {
  4. queryDeviceList,
  5. queryMaintainRecord,
  6. queryRepairRecord,
  7. } from '@/services/device';
  8. import { UnityAction } from '@/utils/utils';
  9. import { useParams, useRequest } from '@umijs/max';
  10. import { Collapse, List, Space, Spin, Table } from 'antd';
  11. import dayjs from 'dayjs';
  12. import { useEffect, useMemo, useState } from 'react';
  13. import styles from './index.less';
  14. import StorageOverview from './storage';
  15. const deviceIcon = require('@/assets/deviceManager/deviceIcon.png');
  16. export const PageType = {
  17. in: 0, //入库管理
  18. out: 1, //出库管理
  19. scrap: 2, //报废处置
  20. warning: 3, //报警数量
  21. base: 4, //基础库存
  22. };
  23. const DeviceManager = () => {
  24. const { projectId } = useParams();
  25. const [defaultActiveKey, setDefaultActiveKey] = useState(
  26. localStorage.deviceTab || '1',
  27. );
  28. useEffect(() => {
  29. // 重置默认显示tab
  30. localStorage.deviceTab = '1';
  31. }, []);
  32. const onChange = (tab) => {
  33. setDefaultActiveKey(tab);
  34. UnityAction.sendMsg('SparePart');
  35. };
  36. return (
  37. <PageContent tabs>
  38. <TabsContent
  39. defaultActiveKey={defaultActiveKey}
  40. onChange={onChange}
  41. items={[
  42. {
  43. label: `设备管理`,
  44. key: '1',
  45. children: <Device projectId={projectId} />,
  46. },
  47. {
  48. label: `备品管理`,
  49. key: '2',
  50. children: <StorageOverview projectId={projectId} />, //<SparePart projectId={projectId} />,
  51. },
  52. ]}
  53. />
  54. </PageContent>
  55. );
  56. };
  57. const Device = ({ projectId }) => {
  58. const [type, setType] = useState(0); //0 全部 1维修 2保养
  59. const [activeCode, setActiveCode] = useState();
  60. const columnsRepair = [
  61. {
  62. title: '设备位号',
  63. dataIndex: 'DeviceCode',
  64. key: 'DeviceCode',
  65. align: 'center',
  66. },
  67. {
  68. title: '设备名称',
  69. dataIndex: 'DeviceName',
  70. key: 'DeviceName',
  71. align: 'center',
  72. },
  73. {
  74. title: '维修时间',
  75. dataIndex: 'RepairTime',
  76. key: 'RepairTime',
  77. align: 'center',
  78. render: (text) => {
  79. return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null;
  80. },
  81. },
  82. {
  83. title: '维修状态',
  84. dataIndex: 'AcceptanceStatus',
  85. render: (text) => {
  86. switch (text) {
  87. case 0:
  88. return '维修中';
  89. case 1:
  90. return '已提交';
  91. case 2:
  92. return '已维修';
  93. default:
  94. return '';
  95. }
  96. },
  97. },
  98. ];
  99. const columns = [
  100. {
  101. title: '设备位号',
  102. dataIndex: 'DeviceCode',
  103. },
  104. {
  105. title: '设备名称',
  106. dataIndex: 'DeviceName',
  107. },
  108. {
  109. title: '保养日期',
  110. dataIndex: 'MaintainTime',
  111. render: (text) => {
  112. return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null;
  113. },
  114. },
  115. {
  116. title: '保养人',
  117. dataIndex: 'Operators',
  118. // width: 300,
  119. render: (text) => {
  120. let arr = [];
  121. if (text && text.length > 0) {
  122. text.map((item) => {
  123. if (item && item.Operator && item.Operator.CName) {
  124. arr.push(item.Operator.CName);
  125. }
  126. });
  127. }
  128. return arr && arr.join(',');
  129. },
  130. },
  131. ];
  132. //请求 全部设备列表
  133. const {
  134. data,
  135. run: runDevice,
  136. loading: loadingDevice,
  137. } = useRequest(queryDeviceList, {
  138. defaultParams: [projectId],
  139. });
  140. const allData = useMemo(() => {
  141. const total = data?.reduce((total, item) => item.Count, 0);
  142. const items = data?.map((item, idx) => {
  143. const itemLen = item?.List?.length;
  144. return {
  145. key: `${idx + 1}`,
  146. label: (
  147. <div className={styles.lineContent}>
  148. <span>{item.Type}</span>
  149. <span>{itemLen}个</span>
  150. </div>
  151. ),
  152. children: (
  153. <div style={{ position: 'relative' }}>
  154. <List
  155. header={null}
  156. footer={null}
  157. dataSource={item.List}
  158. renderItem={(cur) => (
  159. <List.Item
  160. className={`${styles.itemText} ${
  161. activeCode == cur.Code ? styles.itemTextActive : ''
  162. }`}
  163. onClick={() => handleItemClick(cur.Code)}
  164. >
  165. <span style={{ width: '30%', textAlign: 'left' }}>
  166. {cur.Code}
  167. </span>
  168. <span> {cur.Name} </span>
  169. </List.Item>
  170. )}
  171. />
  172. </div>
  173. ),
  174. };
  175. });
  176. return { total, items };
  177. }, [data, activeCode]);
  178. //请求维修中设备列表queryRepairRecord
  179. const {
  180. data: repairData,
  181. run: runRepair,
  182. loading: repairLoading,
  183. } = useRequest(
  184. () =>
  185. queryRepairRecord({
  186. pageSize: 9999,
  187. recordId: Number(projectId),
  188. }),
  189. {
  190. manual: true,
  191. },
  192. );
  193. //请求保养记录
  194. const {
  195. data: maintainData,
  196. run: runMaintain,
  197. loading: maintaiLoading,
  198. } = useRequest(
  199. () =>
  200. queryMaintainRecord({
  201. pageSize: 9999,
  202. recordId: Number(projectId),
  203. }),
  204. {
  205. manual: true,
  206. },
  207. );
  208. const handleItemClick = (code) => {
  209. UnityAction.sendMsg('deviceCode', code);
  210. console.log(code);
  211. setActiveCode(code);
  212. };
  213. const handleBtnClick = (type) => {
  214. setType(type);
  215. switch (type) {
  216. case 0:
  217. runDevice(projectId);
  218. break;
  219. case 1:
  220. runRepair();
  221. break;
  222. case 2:
  223. runMaintain();
  224. break;
  225. }
  226. };
  227. return (
  228. <div className={`content-tab ${styles.sparePart}`}>
  229. <Spin spinning={loadingDevice}>
  230. <div className={styles.top}>
  231. <div className={styles.left}>
  232. <img
  233. className={styles.img}
  234. src={require('@/assets/air-conditioner.png')}
  235. />
  236. <div>
  237. <div className="value-number">{allData?.total}</div>
  238. 设备总数(个)
  239. </div>
  240. </div>
  241. <div className={styles.right}>
  242. <div>
  243. <i className={styles.icon}></i>正常:{allData?.total}
  244. </div>
  245. <div>
  246. <i className={`${styles.icon} ${styles.offline}`}></i>异常:{0}
  247. </div>
  248. </div>
  249. </div>
  250. <Space className={styles.btns} size={28}>
  251. <div
  252. className={`${styles.btn} ${type == 0 ? styles.active : ''}`}
  253. onClick={() => handleBtnClick(0)}
  254. >
  255. <span style={{ lineHeight: '0.6rem' }}>全部</span>
  256. </div>
  257. <div
  258. className={`${styles.btn} ${type == 1 ? styles.active : ''}`}
  259. onClick={() => handleBtnClick(1)}
  260. >
  261. <span style={{ lineHeight: '0.6rem' }}>维修</span>
  262. </div>
  263. <div
  264. className={`${styles.btn} ${type == 2 ? styles.active : ''}`}
  265. onClick={() => handleBtnClick(2)}
  266. >
  267. <span style={{ lineHeight: '0.6rem' }}>保养</span>
  268. </div>
  269. </Space>
  270. </Spin>
  271. {type == 0 && <Collapse bordered={false} items={allData?.items} />}
  272. {type == 1 && (
  273. <Table
  274. loading={repairLoading}
  275. style={{ marginTop: '0.1rem' }}
  276. dataSource={repairData?.filter((item) => item.DeviceCode)}
  277. columns={columnsRepair}
  278. pagination={false}
  279. onRow={(record, index) => ({
  280. onClick: () => console.log(record),
  281. })}
  282. />
  283. )}
  284. {type == 2 && (
  285. <Table
  286. loading={maintaiLoading}
  287. style={{ marginTop: '0.1rem' }}
  288. dataSource={maintainData?.filter((item) => item.DeviceCode)}
  289. columns={columns}
  290. pagination={false}
  291. />
  292. )}
  293. </div>
  294. );
  295. };
  296. export default DeviceManager;