verou
2025-03-27 fb6a6482b156527afc4f78ac900c14e4bd63327d
rsf-admin/src/page/basicInfo/matnr/MatnrEdit.jsx
@@ -19,19 +19,21 @@
    required,
    useRecordContext,
    DeleteButton,
    useNotify,
} from 'react-admin';
import PropTypes from 'prop-types';
import { useWatch, useFormContext } from "react-hook-form";
import { Stack, Grid, Box, Typography } from '@mui/material';
import { Stack, Grid, Box, Typography, Tabs, Tab, } from '@mui/material';
import * as Common from '@/utils/common';
import { EDIT_MODE, REFERENCE_INPUT_PAGESIZE } from '@/config/setting';
import EditBaseAside from "@/page/components/EditBaseAside";
import CustomerTopToolBar from "@/page/components/EditTopToolBar";
import MemoInput from "@/page/components/MemoInput";
import StatusSelectInput from "@/page/components/StatusSelectInput";
import TreeSelectInput from "@/page/components/TreeSelectInput";
import request from '@/utils/request';
const FormToolbar = () => {
    const { getValues } = useFormContext();
    return (
        <Toolbar sx={{ justifyContent: 'space-between' }}>
            <SaveButton />
@@ -40,15 +42,65 @@
    )
}
function CustomTabPanel(props) {
    const { children, value, index, ...other } = props;
    return (
        <div
            role="tabpanel"
            hidden={value !== index}
            id={`simple-tabpanel-${index}`}
            aria-labelledby={`simple-tab-${index}`}
            {...other}
        >
            {value === index && <Box sx={{ p: 3 }}>{children}</Box>}
        </div>
    );
}
CustomTabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.number.isRequired,
    value: PropTypes.number.isRequired,
};
function a11yProps(index) {
    return {
        id: `simple-tab-${index}`,
        'aria-controls': `simple-tabpanel-${index}`,
    };
}
const MatnrEdit = () => {
    const translate = useTranslate();
    const [value, setValue] = React.useState(0);
    const notify = useNotify();
    const [dynamicFields, setDynamicFields] = useState([]);
    useEffect(() => {
        getDynamicFields();
    }, []);
    const getDynamicFields = async () => {
        const {
            data: { code, data, msg },
        } = await request.get("/fields/enable/list");
        if (code === 200) {
            setDynamicFields(data || [])
        } else {
            notify(msg);
        }
    };
    const handleChange = (event, newValue) => {
        setValue(newValue);
    };
    return (
        <Edit
            redirect="list"
            mutationMode={EDIT_MODE}
            actions={<CustomerTopToolBar />}
            aside={<EditBaseAside />}
            title={"menu.matnr"}
        >
            <SimpleForm
                shouldUnregister
@@ -58,208 +110,247 @@
                defaultValues={{}}
            // validate={(values) => { }}
            >
                <Grid container width={{ xs: '100%', xl: '80%' }} rowSpacing={3} columnSpacing={3}>
                    <Grid item xs={12} md={8}>
                <Grid container rowSpacing={3} columnSpacing={3}>
                    <Grid item xs={12} md={10}>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.main')}
                        </Typography>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.name"
                                source="name"
                                parse={v => v}
                                autoFocus
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.code"
                                source="code"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <ReferenceInput
                                source="shipperId"
                                reference="shipper"
                                perPage={REFERENCE_INPUT_PAGESIZE}
                            >
                                <AutocompleteInput
                                    label="table.field.matnr.shipperId"
                                    optionText="name"
                                    filterToQuery={(val) => ({ name: val })}
                                />
                            </ReferenceInput>
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <ReferenceInput
                                source="groupId"
                                reference="matnrGroup"
                                perPage={REFERENCE_INPUT_PAGESIZE}
                            >
                                <AutocompleteInput
                                    label="table.field.matnr.groupId"
                                    optionText="code"
                                    filterToQuery={(val) => ({ code: val })}
                                />
                            </ReferenceInput>
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <ReferenceInput
                                source="rglarId"
                                reference="rglarId"
                                perPage={REFERENCE_INPUT_PAGESIZE}
                            >
                                <AutocompleteInput
                                    label="table.field.matnr.rglarId"
                                    optionText="code"
                                    filterToQuery={(val) => ({ code: val })}
                                />
                            </ReferenceInput>
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.erpCode"
                                source="erpCode"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.spec"
                                source="spec"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.model"
                                source="model"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.weight"
                                source="weight"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.color"
                                source="color"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.size"
                                source="size"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.describle"
                                source="describle"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.nromNum"
                                source="nromNum"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.unit"
                                source="unit"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.purUnit"
                                source="purUnit"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <TextInput
                                label="table.field.matnr.stockUnit"
                                source="stockUnit"
                                parse={v => v}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <SelectInput
                                label="table.field.matnr.stockLevel"
                                source="stockLevel"
                                choices={[
                                    { id: 0, name: ' A' },
                                    { id:   1, name: ' B' },
                                    { id:   2, name: 'C' },
                                ]}
                                validate={required()}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <SelectInput
                                label="table.field.matnr.isLabelMange"
                                source="isLabelMange"
                                choices={[
                                    { id: 0, name: ' 否' },
                                    { id:  1, name: ' 是' },
                                ]}
                                validate={required()}
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.safeQty"
                                source="safeQty"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.minQty"
                                source="minQty"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.maxQty"
                                source="maxQty"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.stagn"
                                source="stagn"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.valid"
                                source="valid"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.validWarn"
                                source="validWarn"
                            />
                        </Stack>
                        <Stack direction='row' gap={2}>
                            <NumberInput
                                label="table.field.matnr.flagCheck"
                                source="flagCheck"
                            />
                        </Stack>
                        <Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
                            <Tab label={translate('page.matnr.title.basic')} {...a11yProps(0)} />
                            <Tab label={translate('page.matnr.title.control')} {...a11yProps(1)} />
                            <Tab label={translate('page.matnr.title.batchRole')} {...a11yProps(2)} />
                        </Tabs>
                        <CustomTabPanel value={value} index={0}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.name"
                                        source="name"
                                        parse={v => v}
                                        required
                                        autoFocus
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.code"
                                        source="code"
                                        required
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <ReferenceInput source="shipperId" reference="companys" filter={{ type: 'shipper' }}>
                                        <AutocompleteInput
                                            label="table.field.matnr.shipperId"
                                            optionText="name"
                                            filterToQuery={(val) => ({ name: val })}
                                        />
                                    </ReferenceInput>
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    {/* <ReferenceInput
                                        source="groupId"
                                        reference="matnrGroup"
                                        perPage={REFERENCE_INPUT_PAGESIZE}
                                    >
                                        <AutocompleteInput
                                            label="table.field.matnr.groupId"
                                            optionText="label"
                                            validate={[required()]}
                                            filterToQuery={(val) => ({ code: val })}
                                        />
                                    </ReferenceInput> */}
                                    <TreeSelectInput
                                        label="table.field.matnr.groupId"
                                        resource={'matnrGroup'}
                                        source="groupId"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.platCode"
                                        source="platCode"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.spec"
                                        source="spec"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.weight"
                                        source="weight"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.color"
                                        source="color"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.size"
                                        source="size"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.describle"
                                        source="describle"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.nromNum"
                                        source="nromNum"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.unit"
                                        source="unit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.purUnit"
                                        source="purUnit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.stockUnit"
                                        source="stockUnit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.stockLevel"
                                        source="stockLevel"
                                        choices={[
                                            { id: 0, name: ' A' },
                                            { id: 1, name: ' B' },
                                            { id: 2, name: 'C' },
                                        ]}
                                        validate={required()}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.isLabelMange"
                                        source="flagLabelMange"
                                        choices={[
                                            { id: 0, name: ' 否' },
                                            { id: 1, name: ' 是' },
                                        ]}
                                        validate={required()}
                                    />
                                </Grid>
                                {dynamicFields.map((item) => {
                                    return (
                                        <Grid key={item.id} item xs={6} display="flex" gap={1}>
                                            <TextInput
                                                label={item.fieldsAlise}
                                                source={item.fields}
                                                validate={item.unique === 1 ? required() : false}
                                            />
                                        </Grid>
                                    )
                                })}
                            </Grid>
                        </CustomTabPanel>
                        <CustomTabPanel value={value} index={1}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.safeQty"
                                        source="safeQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.minQty"
                                        source="minQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.maxQty"
                                        source="maxQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.stagn"
                                        source="stagn"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.validWarn"
                                        source="validWarn"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.valid"
                                        source="valid"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.flagCheck"
                                        source="flagCheck"
                                        choices={[
                                            { id: 0, name: ' 否' },
                                            { id: 1, name: ' 是' },
                                        ]}
                                    />
                                </Grid>
                            </Grid>
                        </CustomTabPanel>
                        <CustomTabPanel value={value} index={2}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <ReferenceInput
                                        source="rglar_id"
                                        reference="serialRule"
                                        perPage={REFERENCE_INPUT_PAGESIZE}
                                    >
                                        <AutocompleteInput
                                            label="table.field.matnr.rglarId"
                                            optionText="name"
                                            filterToQuery={(val) => ({ name: val })}
                                        />
                                    </ReferenceInput>
                                </Grid>
                            </Grid>
                        </CustomTabPanel>
                    </Grid>
                    <Grid item xs={12} md={4}>
                    <Grid item xs={12} md={2}>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.common')}
                        </Typography>