import PageContent from '@/components/PageContent'; import TabsContent from '@/components/TabsContent'; import { queryMainChartList } from '@/services/StorageManagement'; import { queryDeviceList, queryMaintainRecord, queryRepairRecord, } from '@/services/device'; import { UnityAction } from '@/utils/utils'; import { RightOutlined } from '@ant-design/icons'; import { useNavigate, useParams, useRequest } from '@umijs/max'; import { Collapse, List, Space, Table } from 'antd'; import dayjs from 'dayjs'; import { useEffect, useMemo, useState } from 'react'; import styles from './index.less'; const deviceIcon = require('@/assets/deviceManager/deviceIcon.png'); const spareIcon = require('@/assets/deviceManager/spareIcon.png'); // const chartIcon = require('@/assets/deviceManager/chartIcon.png'); const DeviceManager = () => { const { projectId } = useParams(); const [defaultActiveKey, setDefaultActiveKey] = useState( localStorage.deviceTab || '1', ); const onChange = (tab) => { setDefaultActiveKey(tab); }; useEffect(() => { // 重置默认显示tab localStorage.deviceTab = '1'; }, []); return ( , }, { label: `备品管理`, key: '2', children: , }, ]} /> ); }; const Device = ({ projectId }) => { const [type, setType] = useState(0); //0 全部 1维修 2保养 const [activeCode, setActiveCode] = useState(); const columnsRepair = [ { title: '设备位号', dataIndex: 'DeviceCode', key: 'DeviceCode', align: 'center', }, { title: '设备名称', dataIndex: 'DeviceName', key: 'DeviceName', align: 'center', }, { title: '维修时间', dataIndex: 'RepairTime', key: 'RepairTime', align: 'center', render: (text) => { return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null; }, }, { title: '维修状态', dataIndex: 'AcceptanceStatus', render: (text) => { switch (text) { case 0: return '维修中'; case 1: return '已提交'; case 2: return '已维修'; default: return ''; } }, }, ]; const columns = [ { title: '设备位号', dataIndex: 'DeviceCode', }, { title: '设备名称', dataIndex: 'DeviceName', }, { title: '保养日期', dataIndex: 'MaintainTime', render: (text) => { return text ? dayjs(text).format('YYYY-MM-DD HH:mm') : null; }, }, { title: '保养人', dataIndex: 'Operators', width: 300, render: (text) => { let arr = []; if (text && text.length > 0) { text.map((item) => { if (item && item.Operator && item.Operator.CName) { arr.push(item.Operator.CName); } }); } return arr && arr.join(','); }, }, ]; //请求 全部设备列表 const { data, run: runDevice, loading: loadingDevice, } = useRequest(queryDeviceList, { defaultParams: [projectId], }); const allData = useMemo(() => { const total = data?.reduce((total, item) => item.Count, 0); const items = data?.map((item, idx) => { const itemLen = item?.List?.length; return { key: `${idx + 1}`, label: (
{item.Type} {itemLen}个
), children: (
( handleItemClick(cur.Code)} > {cur.Code} {cur.Name} )} />
), }; }); return { total, items }; }, [data, activeCode]); //请求维修中设备列表queryRepairRecord const { data: repairData, run: runRepair, loading: repairLoading, } = useRequest( () => queryRepairRecord({ // acceptanceStatus: 0, pageSize: 9999, recordId: Number(projectId), }), { manual: true, }, ); //请求保养记录 const { data: maintainData, run: runMaintain, loading: maintaiLoading, } = useRequest( () => queryMaintainRecord({ pageSize: 9999, recordId: Number(projectId), }), { manual: true, }, ); const handleItemClick = (code) => { UnityAction.sendMsg('deviceCode', code); console.log(code); setActiveCode(code); }; const renderChildlen = (item) => { console.log(activeCode); return (
( handleItemClick(cur.Code)} > {cur.Code} {cur.Name} )} />
); }; const handleBtnClick = (type) => { setType(type); switch (type) { case 0: runDevice(projectId); break; case 1: runRepair(); break; case 2: runMaintain(); break; } }; const onChange = () => {}; return (
{allData?.total}
设备总数(个)
handleBtnClick(0)} > 全部
handleBtnClick(1)} > 维修
handleBtnClick(2)} > 保养
{type == 0 && ( )} {type == 1 && ( item.DeviceCode)} columns={columnsRepair} pagination={false} /> )} {type == 2 && (
item.DeviceCode)} columns={columns} pagination={false} /> )} ); }; const SparePart = ({ projectId }) => { const navigate = useNavigate(); const year = dayjs().format('YYYY'); const params = { project_id: Number(projectId), month: 0, year: Number(year), }; //请求备品列表 const { data } = useRequest(() => queryMainChartList(params)); const PageType = { in: 0, //入库管理 out: 1, //出库管理 scrap: 2, //报废处置 existing: 3, //基础库存 }; const changePage = (type) => { navigate(`/device/detail/${projectId}/${type}`); // 设置默认显示tab为备品管理 localStorage.deviceTab = '2'; }; const handletotalPage = () => { navigate(`/device/storage/${projectId}`); // 设置默认显示tab为备品管理 localStorage.deviceTab = '2'; }; const list = useMemo(() => { const result = [ { title: '入库数量', type: PageType.in, num: data?.in_amount || 0, }, { title: '出库数量', type: PageType.out, num: data?.out_amount || 0, }, { title: '报废数量', type: PageType.scrap, num: data?.scrap_amount || 0, }, { title: '报警数量', type: PageType.existing, num: data?.warning_stat || 0, }, ]; return result; }, [data]); return (
{data?.on_amount || 0}
在库数量(个)
{/* */}
{list.map((item) => (
changePage(item.type)} > {item.title} {item.num}个
))}
); }; export default DeviceManager;