|  |  | 
 |  |  |     required, | 
 |  |  |     useRecordContext, | 
 |  |  |     DeleteButton, | 
 |  |  |     useNotify, | 
 |  |  | } from 'react-admin'; | 
 |  |  | import PropTypes from 'prop-types'; | 
 |  |  | import { useWatch, useFormContext } from "react-hook-form"; | 
 |  |  | import { useWatch, useFormContext, useForm, useFormState } 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 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(); | 
 |  |  |     const { getValues } = useFormState(); | 
 |  |  |     return ( | 
 |  |  |         <Toolbar sx={{ justifyContent: 'space-between' }}> | 
 |  |  |             <SaveButton /> | 
 |  |  | 
 |  |  | 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); | 
 |  |  |     }; | 
 |  |  | 
 |  |  |             redirect="list" | 
 |  |  |             mutationMode={EDIT_MODE} | 
 |  |  |             actions={<CustomerTopToolBar />} | 
 |  |  |             aside={<EditBaseAside />} | 
 |  |  |             title={"menu.matnr"} | 
 |  |  |         > | 
 |  |  |             <SimpleForm | 
 |  |  |                 shouldUnregister | 
 |  |  | 
 |  |  |                 defaultValues={{}} | 
 |  |  |             // validate={(values) => { }} | 
 |  |  |             > | 
 |  |  |                 <Grid container width={{ xs: '20%', xl: '80%' }} rowSpacing={3} columnSpacing={3}> | 
 |  |  |                 <Grid container rowSpacing={3} columnSpacing={3}> | 
 |  |  |  | 
 |  |  |                     <Grid item xs={12} md={10}> | 
 |  |  |                         <Typography variant="h6" gutterBottom> | 
 |  |  | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                                 <Grid item xs={6} display="flex" gap={1}> | 
 |  |  |                                     <ReferenceInput | 
 |  |  |                                         source="shipperId" | 
 |  |  |                                         reference="shipper" | 
 |  |  |                                         perPage={REFERENCE_INPUT_PAGESIZE} | 
 |  |  |                                     > | 
 |  |  |                                     <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 | 
 |  |  |                                     {/* <ReferenceInput | 
 |  |  |                                         source="groupId" | 
 |  |  |                                         reference="matnrGroup" | 
 |  |  |                                         perPage={REFERENCE_INPUT_PAGESIZE} | 
 |  |  |                                     > | 
 |  |  |                                         <AutocompleteInput | 
 |  |  |                                             label="table.field.matnr.groupId" | 
 |  |  |                                             optionText="code" | 
 |  |  |                                             optionText="label" | 
 |  |  |                                             validate={[required()]} | 
 |  |  |                                             filterToQuery={(val) => ({ code: val })} | 
 |  |  |                                         /> | 
 |  |  |                                     </ReferenceInput> | 
 |  |  |                                     </ReferenceInput> */} | 
 |  |  |  | 
 |  |  |                                     <TreeSelectInput | 
 |  |  |                                         label="table.field.matnr.groupId" | 
 |  |  |                                         resource={'matnrGroup'} | 
 |  |  |                                         source="groupId" | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                                 <Grid item xs={6} display="flex" gap={1}> | 
 |  |  |                                     <ReferenceInput | 
 |  |  |                                         source="rglarId" | 
 |  |  |                                         reference="batchRegular" | 
 |  |  |                                         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" | 
 |  |  |                                         label="table.field.matnr.platCode" | 
 |  |  |                                         source="platCode" | 
 |  |  |                                         parse={v => v} | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  | 
 |  |  |                                 <Grid item xs={6} display="flex" gap={1}> | 
 |  |  |                                     <SelectInput | 
 |  |  |                                         label="table.field.matnr.isLabelMange" | 
 |  |  |                                         source="isLabelMange" | 
 |  |  |                                         source="flagLabelMange" | 
 |  |  |                                         choices={[ | 
 |  |  |                                             { id: 0, name: ' 否' }, | 
 |  |  |                                             { id: 1, name: ' 是' }, | 
 |  |  | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                                 {dynamicFields.map((item) => { | 
 |  |  |                                     return ( | 
 |  |  |                                         <Grid key={item.id} item xs={6} display="flex" gap={1}> | 
 |  |  |                                             <DynamicFields | 
 |  |  |                                                 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}> | 
 |  |  |                                     <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}> | 
 |  |  |                                     <NumberInput | 
 |  |  |                                         label="table.field.matnr.safeQty" | 
 |  |  | 
 |  |  |                                         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}> | 
 |  |  |                                     <NumberInput | 
 |  |  |                                         label="table.field.matnr.flagCheck" | 
 |  |  |                                         source="flagCheck" | 
 |  |  |                             <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="rglarId" | 
 |  |  |                                         reference="serialRule" | 
 |  |  |                                         perPage={REFERENCE_INPUT_PAGESIZE} | 
 |  |  |                                     > | 
 |  |  |                                         <AutocompleteInput | 
 |  |  |                                             label="table.field.matnr.rglarId" | 
 |  |  |                                             optionText="name" | 
 |  |  |                                             filterToQuery={(val) => ({ name: val })} | 
 |  |  |                                         /> | 
 |  |  |                                     </ReferenceInput> | 
 |  |  |                                 </Grid> | 
 |  |  |                             </Grid> | 
 |  |  |                         </CustomTabPanel> | 
 |  |  | 
 |  |  | } | 
 |  |  |  | 
 |  |  | export default MatnrEdit; | 
 |  |  |  | 
 |  |  | const DynamicFields = (props) => { | 
 |  |  |     const { ...parmas } = props; | 
 |  |  |     const form = useFormContext(); | 
 |  |  |     const field = `extendFields.${parmas.source}`; | 
 |  |  |  | 
 |  |  |     const value = form.getValues(field) || form.formState.defaultValues?.extendFields?.[parmas.source]; | 
 |  |  |  | 
 |  |  |     value && form.setValue(parmas.source, value); | 
 |  |  |     return ( | 
 |  |  |         <TextInput | 
 |  |  |             {...parmas} | 
 |  |  |         /> | 
 |  |  |     ) | 
 |  |  | } |