|  |  | 
 |  |  |  | 
 |  |  | } from '@mui/material'; | 
 |  |  | import DialogCloseButton from "../../components/DialogCloseButton"; | 
 |  |  | import DictionarySelect from "../../components/DictionarySelect"; | 
 |  |  | import { useForm, Controller, useWatch, FormProvider, useFormContext } from "react-hook-form"; | 
 |  |  | import SaveIcon from '@mui/icons-material/Save'; | 
 |  |  | import request from '@/utils/request'; | 
 |  |  | 
 |  |  | import { DataGrid } from '@mui/x-data-grid'; | 
 |  |  | import StatusSelectInput from "../../components/StatusSelectInput"; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | const InitModal = ({ open, setOpen }) => { | 
 |  |  | const InitModal = ({ open, setOpen, fieldType }) => { | 
 |  |  |     const refresh = useRefresh(); | 
 |  |  |     const translate = useTranslate(); | 
 |  |  |  | 
 |  |  | 
 |  |  |     const notify = useNotify(); | 
 |  |  |  | 
 |  |  |     const [formData, setFormData] = useState({ | 
 |  |  |         'status': null | 
 |  |  |         'status': null, | 
 |  |  |         'stockLevel': null, | 
 |  |  |         'validWarn': null, | 
 |  |  |         'valid': null, | 
 |  |  |         'flagCheck': null, | 
 |  |  |     }); | 
 |  |  |  | 
 |  |  |     const { selectedIds } = useListContext(); | 
 |  |  |     const { selectedIds, onUnselectItems } = useListContext(); | 
 |  |  |  | 
 |  |  |     const handleClose = (event, reason) => { | 
 |  |  |         if (reason !== "backdropClick") { | 
 |  |  |             setOpen(false); | 
 |  |  |             reset() | 
 |  |  |             refresh(); | 
 |  |  |             onUnselectItems() | 
 |  |  |         } | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     const reset = () => { | 
 |  |  |         setFormData({ | 
 |  |  |             'status': null | 
 |  |  |             'status': null, | 
 |  |  |             'stockLevel': null, | 
 |  |  |             'validWarn': null, | 
 |  |  |             'valid': null, | 
 |  |  |             'flagCheck': null, | 
 |  |  |         }) | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     const handleChange = (value, name) => { | 
 |  |  |         setFormData((prevData) => ({ | 
 |  |  |             ...prevData, | 
 |  |  |             [name]: ['locType', 'type'].includes(name) ? value : +value | 
 |  |  |             [name]: value | 
 |  |  |         })); | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  | 
 |  |  |                 const newObj = removeEmptyKeys(value); | 
 |  |  |                 return !_.isEmpty(newObj); | 
 |  |  |             } | 
 |  |  |             return !_.isNil(value) && (_.isNumber(value) ? value !== 0 : !_.isEmpty(value)); | 
 |  |  |             return !_.isNil(value); | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     const handleSubmit = async () => { | 
 |  |  |         const parmas = { | 
 |  |  |             id: selectedIds, | 
 |  |  |             matnr: removeEmptyKeys(formData) | 
 |  |  |             ids: selectedIds, | 
 |  |  |             matnr: { | 
 |  |  |                 ...removeEmptyKeys(formData) | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         const res = await request.post(`/matnr/modify`, parmas); | 
 |  |  |         const res = await request.post(`/matnr/batch/update`, parmas); | 
 |  |  |         if (res?.data?.code === 200) { | 
 |  |  |             handleClose() | 
 |  |  |  | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     return ( | 
 |  |  |         <Dialog open={open} maxWidth="md" fullWidth> | 
 |  |  |         <Dialog open={open} maxWidth="xs" fullWidth> | 
 |  |  |             <Form onSubmit={handleSubmit}> | 
 |  |  |                 <DialogCloseButton onClose={handleClose} /> | 
 |  |  |                 <DialogTitle>{translate('toolbar.batch')}</DialogTitle> | 
 |  |  |                 <DialogContent sx={{ mt: 2 }}> | 
 |  |  |                     <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> | 
 |  |  |                         <Grid container spacing={2}> | 
 |  |  |                             <Grid item xs={4}> | 
 |  |  |                                 <StatusSelectInput | 
 |  |  |                                     onChange={(e) => handleChange(e.target.value, 'status')} | 
 |  |  |                                     defaultValue={''} | 
 |  |  |                                     require={false} | 
 |  |  |                                 /> | 
 |  |  |                             </Grid> | 
 |  |  |                             {fieldType === 'status' && | 
 |  |  |                                 <Grid item xs={6}> | 
 |  |  |                                     <StatusSelectInput | 
 |  |  |                                         onChange={(e) => handleChange(+e.target.value, 'status')} | 
 |  |  |                                         defaultValue={''} | 
 |  |  |                                         require={false} | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                             } | 
 |  |  |                             {fieldType === 'stockLevel' && | 
 |  |  |                                 <Grid item xs={6}> | 
 |  |  |                                     <SelectInput | 
 |  |  |                                         label="table.field.matnr.stockLevel" | 
 |  |  |                                         source="stockLevel" | 
 |  |  |                                         onChange={(e) => handleChange(e.target.value, 'stockLevel')} | 
 |  |  |                                         choices={[ | 
 |  |  |                                             { id: 0, name: ' A' }, | 
 |  |  |                                             { id: 1, name: ' B' }, | 
 |  |  |                                             { id: 2, name: 'C' }, | 
 |  |  |                                         ]} | 
 |  |  |                                         validate={required()} | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                             } | 
 |  |  |                             {fieldType === 'validWarn' && | 
 |  |  |                                 <Grid item xs={6}> | 
 |  |  |                                     <NumberInput | 
 |  |  |                                         onChange={(e) => handleChange(e.target.value, 'validWarn')} | 
 |  |  |                                         label="table.field.matnr.validWarn" | 
 |  |  |                                         source="validWarn" | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                             } | 
 |  |  |                             {fieldType === 'validWarn' && | 
 |  |  |                                 <Grid item xs={6}> | 
 |  |  |                                     <NumberInput | 
 |  |  |                                         onChange={(e) => handleChange(e.target.value, 'valid')} | 
 |  |  |                                         label="table.field.matnr.valid" | 
 |  |  |                                         source="valid" | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                             } | 
 |  |  |                             {fieldType === 'flagCheck' && | 
 |  |  |                                 <Grid item xs={6}> | 
 |  |  |                                     <SelectInput | 
 |  |  |                                         onChange={(e) => handleChange(e.target.value, 'flagCheck')} | 
 |  |  |                                         label="table.field.matnr.flagCheck" | 
 |  |  |                                         source="flagCheck" | 
 |  |  |                                         choices={[ | 
 |  |  |                                             { id: 0, name: ' 否' }, | 
 |  |  |                                             { id: 1, name: ' 是' }, | 
 |  |  |                                         ]} | 
 |  |  |                                     /> | 
 |  |  |                                 </Grid> | 
 |  |  |                             } | 
 |  |  |                         </Grid> | 
 |  |  |  | 
 |  |  |                     </Box> | 
 |  |  | 
 |  |  |                 <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> | 
 |  |  |                     <Box sx={{ width: '100%', display: 'flex', justifyContent: 'space-between' }}> | 
 |  |  |                         <Button type="submit" variant="contained" startIcon={<SaveIcon />}> | 
 |  |  |                             确认 | 
 |  |  |                             {translate('toolbar.confirm')} | 
 |  |  |                         </Button> | 
 |  |  |                     </Box> | 
 |  |  |                 </DialogActions> |