sparePart.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import { RightOutlined } from '@ant-design/icons';
  4. import { useNavigate, useParams, useRequest } from '@umijs/max';
  5. import { Space, Spin } from 'antd';
  6. import dayjs from 'dayjs';
  7. import { useMemo } from 'react';
  8. import { PageType } from './index';
  9. import styles from './index.less';
  10. const spareIcon = require('@/assets/deviceManager/spareIcon.png');
  11. const SparePart = () => {
  12. const { projectId } = useParams();
  13. const navigate = useNavigate();
  14. const year = dayjs().format('YYYY');
  15. const currentMonth = dayjs().format('MM');
  16. const defaultParams = {
  17. project_id: Number(projectId),
  18. month: Number(currentMonth),
  19. year: Number(year),
  20. };
  21. //请求备品列表
  22. const { data, loading } = useRequest(() => queryMainChartList(defaultParams));
  23. const changePage = (type) => {
  24. navigate(`/device/detail/${projectId}/${type}`);
  25. // 设置默认显示tab为备品管理
  26. localStorage.deviceTab = '2';
  27. };
  28. const handleTotalPage = () => {
  29. navigate(`/device/storage/${projectId}`);
  30. // 设置默认显示tab为备品管理
  31. localStorage.deviceTab = '2';
  32. };
  33. const list = useMemo(() => {
  34. const result = [
  35. {
  36. title: '基础库存',
  37. type: PageType.base,
  38. },
  39. {
  40. title: '入库数量',
  41. type: PageType.in,
  42. num: data?.in_amount || 0,
  43. },
  44. {
  45. title: '出库数量',
  46. type: PageType.out,
  47. num: data?.out_amount || 0,
  48. },
  49. {
  50. title: '报废数量',
  51. type: PageType.scrap,
  52. num: data?.scrap_amount || 0,
  53. },
  54. {
  55. title: '报警数量',
  56. type: PageType.warning,
  57. num: data?.warning_stat || 0,
  58. },
  59. ];
  60. return result;
  61. }, [data]);
  62. return (
  63. <PageContent closeable={false}>
  64. <PageTitle returnable>备品详情</PageTitle>
  65. <Spin spinning={loading}>
  66. <div className="content-tab">
  67. <Space direction="vertical" size={16} className={styles.sparePart}>
  68. <div className={styles.titleContent}>
  69. <img className={styles.img} src={spareIcon} />
  70. <div>
  71. <div className="value-number">{data?.on_amount || 0}</div>
  72. <div className={styles.text}>在库数量(个)</div>
  73. </div>
  74. {/* <div
  75. onClick={handleTotalPage}
  76. className={styles.iconFundFilled}
  77. ></div> */}
  78. </div>
  79. {list.map((item) => (
  80. <div
  81. className={`card-box ${styles.cardItem}`}
  82. onClick={() => changePage(item.type)}
  83. >
  84. <span className={styles.spareText}>{item.title}</span>
  85. <Space size={30}>
  86. {/* <span className={styles.spareText}>{item.num}个</span> */}
  87. <RightOutlined style={{ fontSize: '0.28rem' }} />
  88. </Space>
  89. </div>
  90. ))}
  91. </Space>
  92. </div>
  93. </Spin>
  94. </PageContent>
  95. );
  96. };
  97. export default SparePart;