import React, { useState, useRef, useEffect, useMemo, useCallback } from "react";
|
import { useNavigate } from 'react-router-dom';
|
import {
|
List,
|
DatagridConfigurable,
|
SearchInput,
|
TopToolbar,
|
SelectColumnsButton,
|
EditButton,
|
FilterButton,
|
CreateButton,
|
ExportButton,
|
BulkDeleteButton,
|
WrapperField,
|
useRecordContext,
|
useTranslate,
|
useNotify,
|
useListContext,
|
FunctionField,
|
TextField,
|
NumberField,
|
DateField,
|
BooleanField,
|
ReferenceField,
|
TextInput,
|
DateTimeInput,
|
DateInput,
|
SelectInput,
|
NumberInput,
|
ReferenceInput,
|
ReferenceArrayInput,
|
useRefresh,
|
AutocompleteInput,
|
required,
|
DeleteButton,
|
Button,
|
} from 'react-admin';
|
import { Box, Typography, Card, Stack, LinearProgress } from '@mui/material';
|
import { styled } from '@mui/material/styles';
|
import MyExportButton from '../../components/MyExportButton';
|
import MyField from "../../components/MyField";
|
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting';
|
import request from '@/utils/request';
|
import WarehouseStockInfo from "./WarehouseStockInfo";
|
import MatnrListAside from "./WarehouseAside";
|
import WarehouseHistories from "./WarehouseHistories";
|
|
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
|
'& .css-1vooibu-MuiSvgIcon-root': {
|
height: '.9em'
|
},
|
'& .RaDatagrid-row': {
|
cursor: 'auto'
|
},
|
'& .column-name': {
|
},
|
'& .opt': {
|
width: 180
|
},
|
}));
|
|
|
const WarehouseStockList = () => {
|
const translate = useTranslate();
|
const [createDialog, setCreateDialog] = useState(false);
|
const [select, setSelect] = useState({});
|
const [drawerVal, setDrawerVal] = useState(false);
|
|
const filters = [
|
<SearchInput source="condition" alwaysOn />,
|
<NumberInput source="locId" label="table.field.locItem.locId" />,
|
<TextInput source="locCode" label="table.field.locItem.locCode" />,
|
<TextInput source="type" label="table.field.locItem.type" />,
|
<ReferenceInput source="aggType" reference="dictData" filter={{ dictTypeCode: 'sys_stock_summary_code' }} alwaysOn>
|
<AutocompleteInput optionText='label' optionValue="value" label="table.field.locItem.aggType" />
|
</ReferenceInput>,
|
<NumberInput source="orderItemId" label="table.field.locItem.orderItemId" />,
|
<NumberInput source="wkType" label="table.field.locItem.wkType" />,
|
<NumberInput source="matnrId" label="table.field.locItem.matnrId" />,
|
<TextInput source="maktx" label="table.field.locItem.maktx" />,
|
<TextInput source="unit" label="table.field.locItem.unit" />,
|
<NumberInput source="anfme" label="table.field.locItem.anfme" />,
|
<NumberInput source="workQty" label="table.field.locItem.workQty" />,
|
<TextInput source="batch" label="table.field.locItem.batch" />,
|
<TextInput source="spec" label="table.field.locItem.spec" />,
|
<TextInput source="model" label="table.field.locItem.model" />,
|
<TextInput source="fieldsIndex" label="table.field.locItem.fieldsIndex" />,
|
<TextInput label="common.field.memo" source="memo" />,
|
]
|
|
return (
|
<>
|
<Box display="flex">
|
<List
|
sx={{
|
flexGrow: 1,
|
transition: (theme) =>
|
theme.transitions.create(['all'], {
|
duration: theme.transitions.duration.enteringScreen,
|
}),
|
marginRight: 0,
|
}}
|
resource="warehouse/stock"
|
title={"common.button.detail"}
|
empty={false}
|
filters={filters}
|
sort={{ field: "create_time", order: "desc" }}
|
actions={(
|
<TopToolbar>
|
<FilterButton />
|
<SelectColumnsButton preferenceKey='viewStockManage' />
|
<MyExportButton />
|
</TopToolbar>
|
)}
|
perPage={DEFAULT_PAGE_SIZE}
|
aside={<MatnrListAside />}
|
>
|
<DynamicFields
|
setDrawerVal={setDrawerVal}
|
setCreateDialog={setCreateDialog}
|
setSelect={setSelect}
|
/>
|
</List>
|
<WarehouseStockInfo
|
open={createDialog}
|
setOpen={setCreateDialog}
|
record={select}
|
/>
|
<WarehouseHistories
|
open={drawerVal}
|
setOpen={setDrawerVal}
|
record={select}
|
/>
|
</Box>
|
</>
|
)
|
}
|
|
export default WarehouseStockList;
|
|
|
const DynamicFields = (props) => {
|
const {setDrawerVal, setCreateDialog, setSelect} = props
|
const translate = useTranslate();
|
const notify = useNotify();
|
const [columns, setColumns] = useState([]);
|
const { isLoading } = useListContext();
|
const refresh = useRefresh();
|
useEffect(() => {
|
getDynamicFields();
|
}, []);
|
|
const getDynamicFields = async () => {
|
const { data: { code, data, msg }, } = await request.get("/fields/enable/list");
|
if (code == 200) {
|
const arr = [
|
<NumberField source="id" />,
|
<NumberField source="locId" label="table.field.warehouseStock.locId" />,
|
<TextField source="locCode" label="table.field.warehouseStock.locCode" />,
|
<NumberField source="orderId" label="table.field.warehouseStock.orderId" />,
|
<NumberField source="orderItemId" label="table.field.warehouseStock.orderItemId" />,
|
<NumberField source="matnrId" label="table.field.warehouseStock.matnrId" />,
|
<TextField source="matnrCode" label="table.field.warehouseStock.matnrCode" />,
|
<TextField source="maktx" label="table.field.warehouseStock.maktx" />,
|
<NumberField source="anfme" label="table.field.warehouseStock.anfme" />,
|
<NumberField source="workQty" label="table.field.warehouseStock.qty" />,
|
<TextField source="spec" label="table.field.warehouseStock.spec" />,
|
<TextField source="model" label="table.field.warehouseStock.model" />,
|
<TextField source="batch" label="table.field.warehouseStock.batch" />,
|
<TextField source="unit" label="table.field.warehouseStock.unit" />,
|
<TextField source="fieldsIndex" label="table.field.warehouseStock.fieldsIndex" />,
|
]
|
const fields = data.map(el => <TextField key={el.fields} source={`extendFields.[${el.fields}]`} label={el.fieldsAlise} />)
|
const lastArr = [
|
<TextField source="updateBy$" label="common.field.updateBy" />,
|
<DateField source="updateTime" label="common.field.updateTime" showTime />,
|
<WrapperField cellClassName="opt" label="common.field.opt">
|
<HistoriesButton setDrawerVal={setDrawerVal} setSelect={setSelect} />
|
<StockInfoButton setCreateDialog={setCreateDialog} setSelect={setSelect} />
|
</WrapperField>
|
]
|
setColumns([...arr, ...fields, ...lastArr]);
|
} else {
|
notify(msg);
|
}
|
}
|
|
return (
|
<Box sx={{ position: 'relative', minHeight: "60vh", }}>
|
{isLoading && (
|
<LinearProgress
|
sx={{
|
height: "2px",
|
position: 'absolute',
|
top: 0,
|
left: 0,
|
right: 0,
|
}}
|
/>
|
)}
|
{columns.length > 0 &&
|
<StyledDatagrid
|
preferenceKey='viewStockManage'
|
bulkActionButtons={false}
|
rowClick={false}
|
expand={false}
|
expandSingle={true}
|
omit={['id', 'createTime', 'locId', 'spec', 'model', 'locCode', 'orderId', 'orderItemId', 'matnrId', 'splrBatch', 'createBy', 'memo', 'fieldsIndex']}
|
>
|
{columns.map((column) => column)}
|
</StyledDatagrid>}
|
</Box>
|
)
|
}
|
|
|
const HistoriesButton = ({ setDrawerVal, setSelect }) => {
|
const record = useRecordContext();
|
const historyClick = (event) => {
|
event.stopPropagation();
|
setDrawerVal(true)
|
setSelect(record)
|
}
|
return (
|
<Button label="common.button.histories" onClick={historyClick}></Button>
|
)
|
}
|
|
const StockInfoButton = ({ setCreateDialog, setSelect }) => {
|
const record = useRecordContext();
|
const {filterValues} = useListContext();
|
const stockClick = (event) => {
|
event.stopPropagation();
|
setCreateDialog(true)
|
const objRecord = {...record, ...filterValues}
|
setSelect(objRecord)
|
}
|
|
return (
|
<Button label="common.button.detail" onClick={stockClick}></Button>
|
)
|
}
|