|  |  |  | 
|---|
|  |  |  | NumberInput, | 
|---|
|  |  |  | BooleanInput, | 
|---|
|  |  |  | DateInput, | 
|---|
|  |  |  | DateTimeInput, | 
|---|
|  |  |  | SaveButton, | 
|---|
|  |  |  | SelectInput, | 
|---|
|  |  |  | ReferenceInput, | 
|---|
|  |  |  | 
|---|
|  |  |  | useNotify, | 
|---|
|  |  |  | Form, | 
|---|
|  |  |  | useCreateController, | 
|---|
|  |  |  | ArrayInput, | 
|---|
|  |  |  | SimpleFormIterator, | 
|---|
|  |  |  | } from 'react-admin'; | 
|---|
|  |  |  | import { | 
|---|
|  |  |  | Dialog, | 
|---|
|  |  |  | 
|---|
|  |  |  | import DialogCloseButton from "../components/DialogCloseButton"; | 
|---|
|  |  |  | import StatusSelectInput from "../components/StatusSelectInput"; | 
|---|
|  |  |  | import MemoInput from "../components/MemoInput"; | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const BusCreate = (props) => { | 
|---|
|  |  |  | const { open, setOpen } = props; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const [locStsIdByStock, setLocStsIdByStock] = useState(null); | 
|---|
|  |  |  | const [locStsIdByIdle, setLocStsIdByIdle] = useState(null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | useEffect(() => { | 
|---|
|  |  |  | const queryLocStsByStock = async () => { | 
|---|
|  |  |  | request.post('/locSts/list', { | 
|---|
|  |  |  | uuid: 'STOCK' | 
|---|
|  |  |  | }, { | 
|---|
|  |  |  | headers: { | 
|---|
|  |  |  | 'Content-Type': 'application/x-www-form-urlencoded' | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }).then(res => { | 
|---|
|  |  |  | setLocStsIdByStock(res.data.data[0]?.id); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const queryLocStsByIdle = async () => { | 
|---|
|  |  |  | request.post('/locSts/list', { | 
|---|
|  |  |  | uuid: 'IDLE' | 
|---|
|  |  |  | }, { | 
|---|
|  |  |  | headers: { | 
|---|
|  |  |  | 'Content-Type': 'application/x-www-form-urlencoded' | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }).then(res => { | 
|---|
|  |  |  | setLocStsIdByIdle(res.data.data[0]?.id); | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (open) { | 
|---|
|  |  |  | queryLocStsByStock(); | 
|---|
|  |  |  | queryLocStsByIdle(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, [open]) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleClose = (event, reason) => { | 
|---|
|  |  |  | if (reason !== "backdropClick") { | 
|---|
|  |  |  | 
|---|
|  |  |  | notify('common.response.success'); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleError = async (data) => { | 
|---|
|  |  |  | notify('common.response.fail'); | 
|---|
|  |  |  | const handleError = async (error) => { | 
|---|
|  |  |  | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <> | 
|---|
|  |  |  | <CreateBase | 
|---|
|  |  |  | record={{}} | 
|---|
|  |  |  | transform={(data) => { | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | mutationOptions={{ onSuccess: handleSuccess, onError: handleError }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <Dialog | 
|---|
|  |  |  | open={open} | 
|---|
|  |  |  | onClose={handleClose} | 
|---|
|  |  |  | aria-labelledby="form-dialog-title" | 
|---|
|  |  |  | fullWidth | 
|---|
|  |  |  | disableRestoreFocus | 
|---|
|  |  |  | maxWidth="md"   // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 
|---|
|  |  |  | {(locStsIdByStock && locStsIdByIdle) && ( | 
|---|
|  |  |  | <CreateBase | 
|---|
|  |  |  | record={{}} | 
|---|
|  |  |  | transform={(data) => { | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | mutationOptions={{ onSuccess: handleSuccess, onError: handleError }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <Form> | 
|---|
|  |  |  | <DialogTitle id="form-dialog-title" sx={{ | 
|---|
|  |  |  | position: 'sticky', | 
|---|
|  |  |  | top: 0, | 
|---|
|  |  |  | backgroundColor: 'background.paper', | 
|---|
|  |  |  | zIndex: 1000 | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {translate('create.title')} | 
|---|
|  |  |  | <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}> | 
|---|
|  |  |  | <DialogCloseButton onClose={handleClose} /> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | </DialogTitle> | 
|---|
|  |  |  | <DialogContent> | 
|---|
|  |  |  | <Grid container rowSpacing={2} columnSpacing={2}> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.bus.uuid" | 
|---|
|  |  |  | source="uuid" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | autoFocus | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.bus.seqNum" | 
|---|
|  |  |  | source="seqNum" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <DateInput | 
|---|
|  |  |  | label="table.field.bus.startTime" | 
|---|
|  |  |  | source="startTime" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <DateInput | 
|---|
|  |  |  | label="table.field.bus.endTime" | 
|---|
|  |  |  | source="endTime" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="busSts" | 
|---|
|  |  |  | reference="busSts" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.bus.busSts" | 
|---|
|  |  |  | optionText="name" | 
|---|
|  |  |  | filterToQuery={(val) => ({ name: val })} | 
|---|
|  |  |  | <Dialog | 
|---|
|  |  |  | open={open} | 
|---|
|  |  |  | onClose={handleClose} | 
|---|
|  |  |  | aria-labelledby="form-dialog-title" | 
|---|
|  |  |  | fullWidth | 
|---|
|  |  |  | disableRestoreFocus | 
|---|
|  |  |  | maxWidth="md"   // 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <Form> | 
|---|
|  |  |  | <DialogTitle id="form-dialog-title" sx={{ | 
|---|
|  |  |  | position: 'sticky', | 
|---|
|  |  |  | top: 0, | 
|---|
|  |  |  | backgroundColor: 'background.paper', | 
|---|
|  |  |  | zIndex: 1000 | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | {translate('create.title')} | 
|---|
|  |  |  | <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}> | 
|---|
|  |  |  | <DialogCloseButton onClose={handleClose} /> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | </DialogTitle> | 
|---|
|  |  |  | <DialogContent> | 
|---|
|  |  |  | <Grid container rowSpacing={2} columnSpacing={2}> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.bus.busNo" | 
|---|
|  |  |  | source="busNo" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | validate={required()} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <TextInput | 
|---|
|  |  |  | label="table.field.bus.phase" | 
|---|
|  |  |  | source="phase" | 
|---|
|  |  |  | parse={v => v} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | {/* <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <DateTimeInput | 
|---|
|  |  |  | label="table.field.bus.startTime" | 
|---|
|  |  |  | source="startTime" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Grid> */} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <Grid item xs={6} display="flex" gap={1}> | 
|---|
|  |  |  | <StatusSelectInput /> | 
|---|
|  |  |  | <Grid item xs={12} display="flex" gap={1}> | 
|---|
|  |  |  | <ArrayInput | 
|---|
|  |  |  | label="table.field.bus.taskList" | 
|---|
|  |  |  | source="taskList" | 
|---|
|  |  |  | validate={[required()]} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <SimpleFormIterator fullWidth getItemLabel={index => `#${index + 1}`}> | 
|---|
|  |  |  | <Box mt={1} /> | 
|---|
|  |  |  | <Stack direction="row" spacing={2}> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="oriSta" | 
|---|
|  |  |  | reference="sta" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.task.oriSta" | 
|---|
|  |  |  | optionText="staNo" | 
|---|
|  |  |  | filterToQuery={(val) => ({ staNo: val })} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="oriLoc" | 
|---|
|  |  |  | reference="loc" | 
|---|
|  |  |  | filter={{ locSts: locStsIdByStock }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.task.oriLoc" | 
|---|
|  |  |  | optionText="locNo" | 
|---|
|  |  |  | filterToQuery={(val) => ({ locNo: val })} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | <Stack direction="row" spacing={2}> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="destSta" | 
|---|
|  |  |  | reference="sta" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.task.destSta" | 
|---|
|  |  |  | optionText="staNo" | 
|---|
|  |  |  | filterToQuery={(val) => ({ staNo: val })} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | <ReferenceInput | 
|---|
|  |  |  | source="destLoc" | 
|---|
|  |  |  | reference="loc" | 
|---|
|  |  |  | filter={{ locSts: locStsIdByIdle }} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <AutocompleteInput | 
|---|
|  |  |  | label="table.field.task.destLoc" | 
|---|
|  |  |  | optionText="locNo" | 
|---|
|  |  |  | filterToQuery={(val) => ({ locNo: val })} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </ReferenceInput> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | <Stack direction="row" spacing={2} sx={{ maxWidth: '50%' }}> | 
|---|
|  |  |  | {/* <TextInput source="seqNum" /> */} | 
|---|
|  |  |  | <NumberInput | 
|---|
|  |  |  | label="table.field.task.priority" | 
|---|
|  |  |  | source="priority" | 
|---|
|  |  |  | defaultValue={1} | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | </SimpleFormIterator> | 
|---|
|  |  |  | </ArrayInput> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={12} display="flex" gap={1}> | 
|---|
|  |  |  | <Stack direction="column" spacing={1} width={'100%'}> | 
|---|
|  |  |  | <MemoInput /> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | <Grid item xs={12} display="flex" gap={1}> | 
|---|
|  |  |  | <Stack direction="column" spacing={1} width={'100%'}> | 
|---|
|  |  |  | <MemoInput /> | 
|---|
|  |  |  | </Stack> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </Grid> | 
|---|
|  |  |  | </DialogContent> | 
|---|
|  |  |  | <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> | 
|---|
|  |  |  | <Toolbar sx={{ width: '100%', justifyContent: 'space-between' }}  > | 
|---|
|  |  |  | <SaveButton /> | 
|---|
|  |  |  | </Toolbar> | 
|---|
|  |  |  | </DialogActions> | 
|---|
|  |  |  | </Form> | 
|---|
|  |  |  | </Dialog> | 
|---|
|  |  |  | </CreateBase> | 
|---|
|  |  |  | </DialogContent> | 
|---|
|  |  |  | <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> | 
|---|
|  |  |  | <Toolbar sx={{ width: '100%', justifyContent: 'space-between' }}  > | 
|---|
|  |  |  | <SaveButton /> | 
|---|
|  |  |  | </Toolbar> | 
|---|
|  |  |  | </DialogActions> | 
|---|
|  |  |  | </Form> | 
|---|
|  |  |  | </Dialog> | 
|---|
|  |  |  | </CreateBase> | 
|---|
|  |  |  | )} | 
|---|
|  |  |  | </> | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | } | 
|---|