index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 { Button, 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 img = require('@/assets/deviceManager/device01.png');
  16. const chartIcon = require('@/assets/deviceManager/chartIcon.png');
  17. const DeviceManager = () => {
  18. const { projectId } = useParams();
  19. const [type, setType] = useState(0); //0 全部 1维修 2保养
  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 style={{ backgroundColor: 'gray' }}>
  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 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: allData,
  135. run: runDevice,
  136. loading: loadingDevice,
  137. } = useRequest(queryDeviceList, {
  138. defaultParams: [projectId],
  139. formatResult: (res) => {
  140. const data = res.data;
  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,
  146. label: (
  147. <div style={{ display: 'flex', justifyContent: 'space-between' }}>
  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 style={{ justifyContent: 'left' }}>
  160. <span style={{ width: '30%' }}> {cur.Code} </span>
  161. <span> {cur.Name} </span>
  162. </List.Item>
  163. )}
  164. />
  165. </div>
  166. ),
  167. };
  168. });
  169. return { total, items };
  170. },
  171. });
  172. //请求维修中设备列表queryRepairRecord
  173. const {
  174. data: repairData,
  175. run: runRepair,
  176. loading: repairLoading,
  177. } = useRequest(
  178. () =>
  179. queryRepairRecord({
  180. // acceptanceStatus: 0,
  181. pageSize: 9999,
  182. recordId: Number(projectId),
  183. }),
  184. {
  185. manual: true,
  186. },
  187. );
  188. //请求保养记录
  189. const {
  190. data: maintainData,
  191. run: runMaintain,
  192. loading: maintaiLoading,
  193. } = useRequest(
  194. () =>
  195. queryMaintainRecord({
  196. pageSize: 9999,
  197. recordId: Number(projectId),
  198. }),
  199. {
  200. manual: true,
  201. },
  202. );
  203. const handleBtnClick = (type) => {
  204. setType(type);
  205. switch (type) {
  206. case 0:
  207. runDevice(projectId);
  208. break;
  209. case 1:
  210. runRepair();
  211. break;
  212. case 2:
  213. runMaintain();
  214. break;
  215. }
  216. };
  217. const onChange = () => {};
  218. return (
  219. <Space direction="vertical" className={styles.sparePart}>
  220. <div className={`card-box ${styles.titleContent}`}>
  221. <img className={styles.img} src={img} />
  222. <div>
  223. <div className={styles.num}>{allData?.total}</div>
  224. <div>设备总数</div>
  225. </div>
  226. </div>
  227. <Space>
  228. <Button shape="round" onClick={() => handleBtnClick(0)}>
  229. 全部
  230. </Button>
  231. <Button shape="round" onClick={() => handleBtnClick(1)}>
  232. 维修
  233. </Button>
  234. <Button shape="round" onClick={() => handleBtnClick(2)}>
  235. 计划保养
  236. </Button>
  237. </Space>
  238. {type == 0 && (
  239. <Collapse
  240. defaultActiveKey={['1']}
  241. bordered={false}
  242. onChange={onChange}
  243. items={allData?.items}
  244. />
  245. )}
  246. {type == 1 && (
  247. <Table
  248. loading={repairLoading}
  249. style={{ marginTop: '10px' }}
  250. dataSource={repairData?.filter((item) => item.DeviceCode)}
  251. columns={columnsRepair}
  252. pagination={false}
  253. />
  254. )}
  255. {type == 2 && (
  256. <Table
  257. loading={repairLoading}
  258. style={{ marginTop: '10px' }}
  259. dataSource={repairData?.filter((item) => item.DeviceCode)}
  260. columns={columns}
  261. pagination={false}
  262. />
  263. )}
  264. </Space>
  265. );
  266. };
  267. const SparePart = ({ data, loading, projectId }) => {
  268. const navigate = useNavigate();
  269. const PageType = {
  270. in: 0, //入库管理
  271. out: 1, //出库管理
  272. scrap: 2, //报废处置
  273. existing: 3, //基础库存
  274. };
  275. const changePage = (type) => {
  276. navigate(`/device/detail/${projectId}/${type}`);
  277. };
  278. const list = useMemo(() => {
  279. const result = [
  280. {
  281. title: '入库数量',
  282. type: PageType.in,
  283. num: data?.in_amount || 0,
  284. },
  285. {
  286. title: '出库数量',
  287. type: PageType.out,
  288. num: data?.out_amount || 0,
  289. },
  290. {
  291. title: '报废数量',
  292. type: PageType.scrap,
  293. num: data?.scrap_amount || 0,
  294. },
  295. {
  296. title: '报警数量',
  297. type: PageType.existing,
  298. num: data?.warning_stat || 0,
  299. },
  300. ];
  301. return result;
  302. }, [data]);
  303. return (
  304. <Space direction="vertical" className={styles.sparePart}>
  305. <div className={`card-box ${styles.titleContent}`}>
  306. <img className={styles.img} src={img} />
  307. <div>
  308. <div className={styles.num}>{data?.on_amount || 0}</div>
  309. <div>在库数量(个)</div>
  310. </div>
  311. <img className={styles.rightIcon} src={chartIcon} />
  312. </div>
  313. {list.map((item) => (
  314. <div className="card-box" onClick={() => changePage(item.type)}>
  315. <div className={styles.cardItem}>
  316. <span>{item.title}</span>
  317. <Space>
  318. <span>{item.num}个</span>
  319. <RightOutlined />
  320. </Space>
  321. </div>
  322. </div>
  323. ))}
  324. </Space>
  325. );
  326. };
  327. export default DeviceManager;