skyouc
2025-07-24 bfc43ca0e4683c1c0322a6cad5d5be2bc07decc3
rsf-admin/src/page/statistics/stockManage/WarehouseHistories.jsx
@@ -1,4 +1,4 @@
import { Dialog, DialogActions, DialogContent, DialogTitle, Box } from "@mui/material";
import { Dialog, DialogActions, DialogContent, DialogTitle, Box, LinearProgress } from "@mui/material";
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
    List,
@@ -40,7 +40,7 @@
} from 'react-admin';
import DialogCloseButton from "../../components/DialogCloseButton";
import { styled } from '@mui/material/styles';
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting';
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting';
import { Grid, Stack, width } from "@mui/system";
import request from '@/utils/request';
import SaveIcon from '@mui/icons-material/Save';
@@ -118,7 +118,7 @@
                aria-hidden
                fullWidth
                disableRestoreFocus
                maxWidth="lg"
                maxWidth="xl"
            >
                <DialogTitle id="form-dialog-title" sx={{
                    position: 'sticky',
@@ -133,58 +133,32 @@
                <Grid container rowSpacing={2} columnSpacing={2}>
                    <DialogContent>
                        <Grid item sx={24}>
                            <List
                                storeKey="selectPurchase"
                                resource="purchase/filters"
                                sx={{
                                    flexGrow: 1,
                                    marginTop: 8,
                                    height: 500,
                                    transition: (theme) =>
                                        theme.transitions.create(['all'], {
                                            duration: theme.transitions.duration.enteringScreen,
                                        }),
                                    marginRight: 0,
                                }}
                                // filters={<CustomFilter />}
                                queryOptions={{ meta: { ...params } }}
                                empty={false}
                                sort={{ field: "create_time", order: "desc" }}
                                actions={false}
                                perPage={DEFAULT_PAGE_SIZE}
                            >
                                <StyledDatagrid
                                    preferenceKey='selectPurchase'
                                    bulkActionButtons={
                                        <>
                                            <ConfirmSelectButton
                                                setOpen={setOpen}
                                                setPoItemDialog={setPoItemDialog}
                                                setItem={setItem}
                                                mutationMode="pessimistic" />
                                        </>
                                    }
                                    rowClick={false}
                                    expand={false}
                                    expandSingle={true}
                                    omit={['id', 'createTime', 'createBy', 'channel', 'platCode', 'memo', 'channel', 'startTime', 'workQty', 'endTime']}
                            <Box display="flex">
                                <List
                                    resource="warehouse/stock/histories"
                                    sx={{
                                        flexGrow: 1,
                                        transition: (theme) =>
                                            theme.transitions.create(['all'], {
                                                duration: theme.transitions.duration.enteringScreen,
                                            }),
                                        marginRight: 0,
                                    }}
                                    title={"menu.stockItem"}
                                    empty={false}
                                    filter={{ stock: record, aggType: record?.aggType }}
                                    sort={{ field: "create_time", order: "desc" }}
                                    actions={(
                                        <TopToolbar>
                                            <SelectColumnsButton preferenceKey='stockHistories' />
                                            {/* <MyExportButton /> */}
                                        </TopToolbar>
                                    )}
                                    perPage={DEFAULT_ITEM_PAGE_SIZE}
                                >
                                    <NumberField source="id" />
                                    <TextField source="code" label="table.field.purchase.code" />
                                    <TextField source="type$" label="table.field.purchase.type" />
                                    <TextField source="wkType$" label="table.field.purchase.wkType" />
                                    <TextField source="source" label="table.field.purchase.source" />
                                    <NumberField source="anfme" label="table.field.purchase.anfme" />
                                    <NumberField source="qty" label="table.field.purchase.qty" />
                                    <TextField source="channel" label="table.field.purchase.channel" />
                                    <TextField source="platCode" label="table.field.purchase.platCode" />
                                    <DateField source="preArr" label="table.field.purchase.preArr" showTime />
                                    <DateField source="startTime" label="table.field.purchase.startTime" showTime />
                                    <DateField source="endTime" label="table.field.purchase.endTime" showTime />
                                    <TextField source="project" label="table.field.purchase.project" />
                                    <TextField source="memo" label="common.field.memo" sortable={false} />
                                </StyledDatagrid>
                            </List>
                                   <DynamicFields />
                                </List>
                            </Box>
                        </Grid>
                    </DialogContent>
                </Grid>
@@ -209,3 +183,93 @@
        <Button label={"toolbar.confirm"} variant="contained" color="primary" size="medium" startIcon={<SaveIcon />} onClick={confirmSelect} />
    )
}
const DynamicFields = (props) => {
    const { setDrawerVal, setCreateDialog, setSelect, filters } = 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="orderId" label="table.field.stockItem.orderId" />,
                <TextField source="orderCode" label="table.field.stockItem.orderCode" />,
                <TextField source="sourceItemId" label="table.field.stockItem.sourceItemId" />,
                <TextField source="matnrId" label="table.field.stockItem.matnrId" />,
                <TextField source="matnrCode" label="table.field.stockItem.matnrCode" />,
                <TextField source="maktx" label="table.field.stockItem.maktx" />,
                <NumberField source="anfme" label="table.field.stockItem.anfme" />,
                <TextField source="stockUnit" label="table.field.stockItem.stockUnit" />,
                <NumberField source="workQty" label="table.field.stockItem.workQty" />,
                <NumberField source="qty" label="table.field.stockItem.qty" />,
                <TextField source="splrCode" label="table.field.stockItem.splrCode" />,
                <TextField source="batch" label="table.field.stockItem.batch" />,
                <TextField source="splrBatch" label="table.field.stockItem.splrBatch" />,
                <TextField source="splrName" label="table.field.stockItem.splrName" />,
                <TextField source="trackCode" label="table.field.stockItem.trackCode" />,
                <TextField source="barcode" label="table.field.stockItem.barcode" />,
                <TextField source="prodTime" label="table.field.stockItem.prodTime" />,
                <TextField source="packName" label="table.field.stockItem.packName" />,
            ]
            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 />,
                <TextField source="createBy$" label="common.field.createBy" />,
                <DateField source="createTime" label="common.field.createTime" showTime />,
                <TextField source="memo" label="common.field.memo" sortable={false} />,
            ]
            setColumns([...arr, ...fields, ...lastArr]);
            data.map(el => {
                var i = 0;
                filters.map((item) => {
                    if (item.key === el.fields) {
                        i = 1;
                    }
                })
                i === 0 && filters.push(<TextInput key={el.fields} source={el.fields} label={el.fieldsAlise} />)
            })
            // setFilters([...filters, ...inputFields])
        } 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='stockHistories'
                    bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />}
                    rowClick={(id, resource, record) => false}
                    expand={false}
                    expandSingle={true}
                    omit={['id', 'createTime', 'orderId', 'sourceItemId', 'matnrId', 'createBy', 'barcode', 'splrCode', 'splrBatch', 'updateBy$', 'createBy$', 'memo']}
                >
                    {columns.map((column) => column)}
                </StyledDatagrid>}
        </Box>
    )
}