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,
|
useNotify,
|
} 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";
|
import TreeSelectInput from "@/page/components/TreeSelectInput";
|
import request from '@/utils/request';
|
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 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 />}
|
>
|
<SimpleForm
|
shouldUnregister
|
warnWhenUnsavedChanges
|
toolbar={<FormToolbar />}
|
mode="onTouched"
|
defaultValues={{}}
|
// validate={(values) => { }}
|
>
|
<Grid container 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="companys" filter={{ type: 'shipper' }}>
|
<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="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}
|
/>
|
</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}>
|
<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={2}>
|
<Typography variant="h6" gutterBottom>
|
{translate('common.edit.title.common')}
|
</Typography>
|
<StatusSelectInput />
|
<Box mt="2em" />
|
<MemoInput />
|
</Grid>
|
</Grid>
|
</SimpleForm>
|
</Edit >
|
)
|
}
|
|
export default MatnrEdit;
|