import React, { useState, useRef, useEffect, useMemo } from "react";
|
import {
|
Edit,
|
SimpleForm,
|
FormDataConsumer,
|
useTranslate,
|
TextInput,
|
NumberInput,
|
BooleanInput,
|
DateInput,
|
SelectInput,
|
ReferenceInput,
|
ReferenceArrayInput,
|
AutocompleteInput,
|
SaveButton,
|
Toolbar,
|
Labeled,
|
NumberField,
|
required,
|
useRecordContext,
|
DeleteButton,
|
} from 'react-admin';
|
import PropTypes from 'prop-types';
|
import { useWatch, useFormContext } from "react-hook-form";
|
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";
|
|
const FormToolbar = () => {
|
const { getValues } = useFormContext();
|
return (
|
<Toolbar sx={{ justifyContent: 'space-between' }}>
|
<SaveButton />
|
<DeleteButton mutationMode="optimistic" />
|
</Toolbar>
|
)
|
}
|
|
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 handleChange = (event, newValue) => {
|
setValue(newValue);
|
};
|
const validateForm = (values) => {
|
const errors = {};
|
if (!values.shipperId) {
|
errors.shipperId = translate('form.matnr.shipper');
|
}
|
if (!values.groupId) {
|
errors.groupId = translate('form.matnr.groupId');
|
}
|
return errors;
|
};
|
return (
|
<Edit
|
redirect="list"
|
mutationMode={EDIT_MODE}
|
actions={<CustomerTopToolBar />}
|
aside={<EditBaseAside />}
|
>
|
<SimpleForm
|
shouldUnregister
|
warnWhenUnsavedChanges
|
toolbar={<FormToolbar />}
|
mode="onTouched"
|
defaultValues={{}}
|
validate={validateForm}
|
// validate={(values) => { }}
|
>
|
<Grid container width={{ xs: '20%', xl: '80%' }} rowSpacing={3} columnSpacing={3}>
|
|
<Grid item xs={12} md={10}>
|
<Typography variant="h6" gutterBottom>
|
{translate('common.edit.title.main')}
|
</Typography>
|
<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="shipper"
|
perPage={REFERENCE_INPUT_PAGESIZE}
|
>
|
<AutocompleteInput
|
validate={[required()]}
|
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="code"
|
validate={[required()]}
|
filterToQuery={(val) => ({ code: val })}
|
/>
|
</ReferenceInput>
|
</Grid>
|
<Grid item xs={6} display="flex" gap={1}>
|
<ReferenceInput
|
source="rglarId"
|
reference="rglarId"
|
perPage={REFERENCE_INPUT_PAGESIZE}
|
>
|
<AutocompleteInput
|
label="table.field.matnr.rglarId"
|
optionText="code"
|
filterToQuery={(val) => ({ code: val })}
|
/>
|
</ReferenceInput>
|
</Grid>
|
<Grid item xs={6} display="flex" gap={1}>
|
<TextInput
|
label="table.field.matnr.erpCode"
|
source="erpCode"
|
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="isLabelMange"
|
choices={[
|
{ id: 0, name: ' 否' },
|
{ id: 1, name: ' 是' },
|
]}
|
validate={required()}
|
/>
|
</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>
|
</CustomTabPanel>
|
<CustomTabPanel value={value} index={2}>
|
<Grid container rowSpacing={2} columnSpacing={2}>
|
<Grid item xs={6} display="flex" gap={1}>
|
<NumberInput
|
label="table.field.matnr.flagCheck"
|
source="flagCheck"
|
/>
|
</Grid>
|
</Grid>
|
</CustomTabPanel>
|
</Grid>
|
|
|
<Grid item xs={12} md={2}>
|
<Typography variant="h6" gutterBottom>
|
{translate('common.edit.title.common')}
|
</Typography>
|
<StatusSelectInput />
|
<Box mt="2em" />
|
<MemoInput />
|
</Grid>
|
</Grid>
|
</SimpleForm>
|
</Edit >
|
)
|
}
|
|
export default MatnrEdit;
|