index.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import PageContent from '@/components/PageContent';
  2. import TabsContent from '@/components/TabsContent';
  3. import { queryMainChartList } from '@/services/StorageManagement';
  4. import {
  5. queryDeviceList,
  6. queryMaintainRecord,
  7. queryRepairRecord,
  8. } from '@/services/device';
  9. import { RightOutlined } from '@ant-design/icons';
  10. import { useNavigate, useParams, useRequest } from '@umijs/max';
  11. import { Collapse, List, Space, Table } from 'antd';
  12. import dayjs from 'dayjs';
  13. import { useMemo, useState } from 'react';
  14. import styles from './index.less';
  15. const deviceIcon = require('@/assets/deviceManager/deviceIcon.png');
  16. const spareIcon = require('@/assets/deviceManager/spareIcon.png');
  17. const chartIcon = require('@/assets/deviceManager/chartIcon.png');
  18. const DeviceManager = () => {
  19. const { projectId } = useParams();
  20. const year = dayjs().format('YYYY');
  21. const params = {
  22. project_id: Number(projectId),
  23. month: 0,
  24. year: Number(year),
  25. };
  26. //请求备品列表
  27. const { data, run, loading } = useRequest(() => queryMainChartList(params), {
  28. manual: true,
  29. });
  30. const onChange = (tab) => {
  31. if (tab == '2') {
  32. run();
  33. }
  34. };
  35. return (
  36. <PageContent tabs>
  37. <TabsContent
  38. defaultActiveKey="1"
  39. onChange={onChange}
  40. items={[
  41. {
  42. label: `设备管理`,
  43. key: '1',
  44. children: <Device projectId={projectId} />,
  45. },
  46. {
  47. label: `备品管理`,
  48. key: '2',
  49. children: (
  50. <SparePart data={data} loading={loading} projectId={projectId} />
  51. ),
  52. },
  53. ]}
  54. />
  55. </PageContent>
  56. );
  57. };
  58. const Device = ({ projectId }) => {
  59. const [type, setType] = useState(0); //0 全部 1维修 2保养
  60. const [activeCode, setActiveCode] = useState();
  61. const columnsRepair = [
  62. {
  63. title: '设备位号',
  64. dataIndex: 'DeviceCode',
  65. key: 'DeviceCode',
  66. align: 'center',
  67. },
  68. {
  69. title: '设备名称',
  70. dataIndex: 'DeviceName',
  71. key: 'DeviceName',
  72. align: 'center',
  73. },
  74. {
  75. title: '维修时间',
  76. dataIndex: 'RepairTime',
  77. key: 'RepairTime',
  78. align: 'center',
  79. render: (text) => {
  80. return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null;
  81. },
  82. },
  83. {
  84. title: '维修状态',
  85. dataIndex: 'AcceptanceStatus',
  86. render: (text) => {
  87. switch (text) {
  88. case 0:
  89. return '维修中';
  90. case 1:
  91. return '已提交';
  92. case 2:
  93. return '已维修';
  94. default:
  95. return '';
  96. }
  97. },
  98. },
  99. ];
  100. const columns = [
  101. {
  102. title: '设备位号',
  103. dataIndex: 'DeviceCode',
  104. },
  105. {
  106. title: '设备名称',
  107. dataIndex: 'DeviceName',
  108. },
  109. {
  110. title: '保养日期',
  111. dataIndex: 'MaintainTime',
  112. render: (text) => {
  113. return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null;
  114. },
  115. },
  116. {
  117. title: '保养人',
  118. dataIndex: 'Operators',
  119. width: 300,
  120. render: (text) => {
  121. let arr = [];
  122. if (text && text.length > 0) {
  123. text.map((item) => {
  124. if (item && item.Operator && item.Operator.CName) {
  125. arr.push(item.Operator.CName);
  126. }
  127. });
  128. }
  129. return arr && arr.join(',');
  130. },
  131. },
  132. ];
  133. //请求 全部设备列表
  134. const {
  135. data,
  136. run: runDevice,
  137. loading: loadingDevice,
  138. } = useRequest(queryDeviceList, {
  139. defaultParams: [projectId],
  140. });
  141. const allData = useMemo(() => {
  142. console.log(activeCode);
  143. const total = data?.reduce((total, item) => item.Count, 0);
  144. const items = data?.map((item, idx) => {
  145. const itemLen = item?.List?.length;
  146. return {
  147. key: `${idx + 1}`,
  148. label: (
  149. <div className={styles.lineContent}>
  150. <span>{item.Type}</span>
  151. <span>{itemLen}个</span>
  152. </div>
  153. ),
  154. children: (
  155. <div style={{ position: 'relative' }}>
  156. <List
  157. header={null}
  158. footer={null}
  159. dataSource={item.List}
  160. renderItem={(cur) => (
  161. <List.Item
  162. className={`${styles.itemText} ${
  163. activeCode == cur.Code ? styles.itemTextActive : ''
  164. }`}
  165. onClick={() => handleItemClick(cur.Code)}
  166. >
  167. <span style={{ marginRight: '166px' }}> {cur.Code} </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. // acceptanceStatus: 0,
  187. pageSize: 9999,
  188. recordId: Number(projectId),
  189. }),
  190. {
  191. manual: true,
  192. },
  193. );
  194. //请求保养记录
  195. const {
  196. data: maintainData,
  197. run: runMaintain,
  198. loading: maintaiLoading,
  199. } = useRequest(
  200. () =>
  201. queryMaintainRecord({
  202. pageSize: 9999,
  203. recordId: Number(projectId),
  204. }),
  205. {
  206. manual: true,
  207. },
  208. );
  209. const handleItemClick = (code) => {
  210. console.log(code);
  211. setActiveCode(code);
  212. };
  213. const renderChildlen = (item) => {
  214. console.log(activeCode);
  215. return (
  216. <div style={{ position: 'relative' }}>
  217. <List
  218. header={null}
  219. footer={null}
  220. dataSource={item.List}
  221. renderItem={(cur) => (
  222. <List.Item
  223. className={`${styles.listText} ${
  224. activeCode == cur.Code ? styles.lineTextActive : ''
  225. }`}
  226. onClick={() => handleItemClick(cur.Code)}
  227. >
  228. <span style={{ marginRight: '166px' }}> {cur.Code} </span>
  229. <span> {cur.Name} </span>
  230. </List.Item>
  231. )}
  232. />
  233. </div>
  234. );
  235. };
  236. const handleBtnClick = (type) => {
  237. setType(type);
  238. switch (type) {
  239. case 0:
  240. runDevice(projectId);
  241. break;
  242. case 1:
  243. runRepair();
  244. break;
  245. case 2:
  246. runMaintain();
  247. break;
  248. }
  249. };
  250. const onChange = () => {};
  251. return (
  252. <div className={styles.sparePart}>
  253. <div className={`card-box ${styles.titleContent}`}>
  254. <img className={styles.img} src={deviceIcon} />
  255. <div>
  256. <div className={styles.num}>{allData?.total}</div>
  257. <div className={styles.text}>设备总数</div>
  258. </div>
  259. </div>
  260. <Space className={styles.btns} size={28}>
  261. <div
  262. className={`${styles.btn} ${type == 0 ? styles.active : ''}`}
  263. onClick={() => handleBtnClick(0)}
  264. >
  265. 全部
  266. </div>
  267. <div
  268. className={`${styles.btn} ${type == 1 ? styles.active : ''}`}
  269. onClick={() => handleBtnClick(1)}
  270. >
  271. 维修
  272. </div>
  273. <div
  274. className={`${styles.btn} ${type == 2 ? styles.active : ''}`}
  275. onClick={() => handleBtnClick(2)}
  276. >
  277. 保养
  278. </div>
  279. </Space>
  280. {type == 0 && (
  281. <Collapse bordered={false} onChange={onChange} items={allData?.items} />
  282. )}
  283. {type == 1 && (
  284. <Table
  285. loading={repairLoading}
  286. style={{ marginTop: '10px' }}
  287. dataSource={repairData?.filter((item) => item.DeviceCode)}
  288. columns={columnsRepair}
  289. pagination={false}
  290. />
  291. )}
  292. {type == 2 && (
  293. <Table
  294. loading={maintaiLoading}
  295. style={{ marginTop: '10px' }}
  296. dataSource={maintainData?.filter((item) => item.DeviceCode)}
  297. columns={columns}
  298. pagination={false}
  299. />
  300. )}
  301. </div>
  302. );
  303. };
  304. const SparePart = ({ data, loading, projectId }) => {
  305. const navigate = useNavigate();
  306. const PageType = {
  307. in: 0, //入库管理
  308. out: 1, //出库管理
  309. scrap: 2, //报废处置
  310. existing: 3, //基础库存
  311. };
  312. const changePage = (type) => {
  313. navigate(`/device/detail/${projectId}/${type}`);
  314. };
  315. const list = useMemo(() => {
  316. const result = [
  317. {
  318. title: '入库数量',
  319. type: PageType.in,
  320. num: data?.in_amount || 0,
  321. },
  322. {
  323. title: '出库数量',
  324. type: PageType.out,
  325. num: data?.out_amount || 0,
  326. },
  327. {
  328. title: '报废数量',
  329. type: PageType.scrap,
  330. num: data?.scrap_amount || 0,
  331. },
  332. {
  333. title: '报警数量',
  334. type: PageType.existing,
  335. num: data?.warning_stat || 0,
  336. },
  337. ];
  338. return result;
  339. }, [data]);
  340. return (
  341. <Space direction="vertical" size={16} className={styles.sparePart}>
  342. <div className={`card-box ${styles.titleContent}`}>
  343. <img className={styles.img} src={spareIcon} />
  344. <div>
  345. <div className={styles.num}>{data?.on_amount || 0}</div>
  346. <div className={styles.text}>在库数量(个)</div>
  347. </div>
  348. <img className={styles.rightIcon} src={chartIcon} />
  349. </div>
  350. {list.map((item) => (
  351. <div
  352. className={`card-box ${styles.cardItem}`}
  353. onClick={() => changePage(item.type)}
  354. >
  355. <span className={styles.spareText}>{item.title}</span>
  356. <Space size={30}>
  357. <span className={styles.spareText}>{item.num}个</span>
  358. <RightOutlined style={{ fontSize: '28px' }} />
  359. </Space>
  360. </div>
  361. ))}
  362. </Space>
  363. );
  364. };
  365. export default DeviceManager;