storage.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import BarChartModule from '@/components/ManagementPage/BarChartModule';
  2. import PieChartModule from '@/components/ManagementPage/PieChartModule';
  3. import RadarChartModule from '@/components/ManagementPage/RadarChartModule';
  4. import ModuleTitle from '@/components/ManagementPage/moduleTitle';
  5. import { queryMainChartList } from '@/services/StorageManagement';
  6. import { useNavigate, useRequest } from '@umijs/max';
  7. import { Button, Empty, Spin } from 'antd';
  8. import dayjs from 'dayjs';
  9. import { useRef } from 'react';
  10. import styles from './index.less';
  11. const StorageOverview = ({ projectId }) => {
  12. const navigate = useNavigate();
  13. const yearRef = useRef(Number(dayjs().format('YYYY')));
  14. const monthRef = useRef(0);
  15. const statistics = [
  16. {
  17. title: '在库数量(个)',
  18. key: 'on_amount',
  19. },
  20. {
  21. title: '入库数量(个)',
  22. key: 'in_amount',
  23. },
  24. {
  25. title: '出库数量(个)',
  26. key: 'out_amount',
  27. },
  28. {
  29. title: '报废数量(个)',
  30. key: 'scrap_amount',
  31. },
  32. {
  33. title: '报警数量(个)',
  34. key: 'warning_stat',
  35. },
  36. ];
  37. const { data, loading } = useRequest(
  38. () =>
  39. queryMainChartList({
  40. project_id: Number(projectId),
  41. year: yearRef.current,
  42. month: monthRef.current,
  43. }),
  44. {
  45. formatResult: (res) => {
  46. const data = res.data;
  47. const values =
  48. data?.scrap?.length > 0
  49. ? data?.scrap?.map((item) => item.value)
  50. : [0];
  51. const radarMax = Math.max(...values);
  52. return {
  53. maxKind:
  54. data?.kind?.length > 0
  55. ? data?.kind?.sort((a, b) => b.value - a.value)[0].value
  56. : 1,
  57. kind: data.kind,
  58. statistics: statistics.map((item) => {
  59. return { ...item, value: data[item.key] };
  60. }),
  61. barData:
  62. data?.in?.length > 0 && data?.out?.length > 0
  63. ? {
  64. xData: data.in?.map((cur) => cur.item),
  65. dataList: [
  66. {
  67. name: '入库',
  68. data: data.in?.map((cur) => cur.value),
  69. },
  70. {
  71. name: '出库',
  72. data: data.out?.map((cur) => cur.value),
  73. },
  74. ],
  75. }
  76. : {},
  77. pieData: data?.rank?.map((cur) => {
  78. return { name: cur.item, value: cur.value };
  79. }),
  80. radarData:
  81. data?.scrap?.length > 0
  82. ? {
  83. indicator: data?.scrap?.map((item) => {
  84. return { name: item.item, max: radarMax };
  85. }),
  86. data: [
  87. {
  88. value: data?.scrap?.map((item) => {
  89. return item.value;
  90. }),
  91. },
  92. ],
  93. }
  94. : {},
  95. lineData:
  96. data?.on?.length > 0 && data.check?.length > 0
  97. ? {
  98. closeTime: true,
  99. yName: '数量',
  100. xData: data.on?.map((item) => item.item),
  101. dataList: [
  102. {
  103. type: 2,
  104. name: '库存',
  105. data: data.on?.map((item) => item.value),
  106. },
  107. {
  108. type: 1,
  109. name: '盘点',
  110. data: data.check?.map((item) => item.value),
  111. },
  112. ],
  113. }
  114. : null,
  115. };
  116. },
  117. },
  118. );
  119. const goDetail = () => {
  120. navigate(`/device/spare-part/${projectId}`);
  121. // 设置默认显示tab为备品管理
  122. localStorage.deviceTab = '2';
  123. };
  124. return (
  125. <Spin className="content-title" spinning={loading}>
  126. <div className={`card-box ${styles.tipContent}`}>
  127. <span>备品报告:当前库存状态良好,暫无需要补充货物。</span>
  128. <Button type="primary" onClick={goDetail}>
  129. 详情
  130. </Button>
  131. </div>
  132. <div className={`card-box ${styles.itemContent}`}>
  133. <ModuleTitle title="物料种类库存占比" />
  134. <div style={{ height: '3.3rem' }}>
  135. {data?.pieData && <PieChartModule data={data.pieData} />}
  136. </div>
  137. </div>
  138. <div className={`card-box ${styles.itemContent}`}>
  139. <ModuleTitle title="物料库存排名前十统计" />
  140. <ul
  141. style={{
  142. height: '3.3rem',
  143. display: 'flex',
  144. flexDirection: 'column',
  145. }}
  146. >
  147. {data?.kind && data.kind.length != 0 ? (
  148. data.kind
  149. ?.sort((a, b) => b.value - a.value)
  150. .map((item) => {
  151. return (
  152. <li
  153. className={styles.li}
  154. key={`kind_${item.item}`}
  155. style={{ flexGrow: 1 }}
  156. >
  157. <div
  158. style={{
  159. width: '0.8rem',
  160. textAlign: 'right',
  161. fontSize: '0.18rem',
  162. whiteSpace: 'nowrap',
  163. }}
  164. >
  165. {item.item}
  166. </div>
  167. <div
  168. className={styles.line}
  169. style={{
  170. width: `${(70 * item.value) / data?.maxKind}%`,
  171. }}
  172. />
  173. {item.value}
  174. </li>
  175. );
  176. })
  177. ) : (
  178. <Empty />
  179. )}
  180. </ul>
  181. </div>
  182. <div className={`card-box ${styles.itemContent}`}>
  183. <ModuleTitle title="物料报废统计" />
  184. <div style={{ height: '4.4rem' }}>
  185. {data?.radarData && <RadarChartModule {...data.radarData} />}
  186. </div>
  187. </div>
  188. <div className={`card-box ${styles.itemContent}`}>
  189. <ModuleTitle title="出入库统计" />
  190. <div style={{ height: '4rem' }}>
  191. {data?.barData && <BarChartModule {...data.barData} />}
  192. </div>
  193. </div>
  194. </Spin>
  195. );
  196. };
  197. export default StorageOverview;