#
luxiaotao1123
2024-10-11 54d940c0bfabe90700d0bcc9e72dc93bc8bafaad
zy-acs-flow/src/map/settings/ConfigSettings.jsx
@@ -22,27 +22,49 @@
} from '../constants';
import { useNotification } from '../Notification';
export const getFormDefaultValues = (data) => {
    return {
        row: data?.row ?? '',
        bay: data?.bay ?? '',
        no: data?.no ?? '',
        ...data,
    }
};
const ConfigSettings = (props) => {
    const { sprite, onSubmit } = props;
    const notify = useNotification();
    const translate = useTranslate();
    const { control, handleSubmit, reset, watch, setValue } = useForm({
        defaultValues: {
            ...sprite.data,
        },
        defaultValues: getFormDefaultValues(sprite?.data),
    });
    useEffect(() => {
        if (sprite?.data) {
            reset(getFormDefaultValues(sprite.data));
        }
    }, [sprite, reset]);
    const deviceType = sprite?.data?.type;
    const rowValue = watch('row');
    const bayValue = watch('bay');
    useEffect(() => {
        if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') {
            setValue('no', `${rowValue}-${bayValue}`);
        } else {
            setValue('no', '');
        if (deviceType === DEVICE_TYPE.SHELF) {
            if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') {
                setValue('no', `${rowValue}-${bayValue}`);
            } else {
                setValue('no', '');
            }
        }
    }, [rowValue, bayValue, setValue]);
    }, [
        setValue,
        deviceType,
        rowValue,
        bayValue,
    ]);
    const onFormSubmit = (data) => {
        if (sprite && sprite.data) {
@@ -61,7 +83,7 @@
        <>
            <Box component="form" onSubmit={handleSubmit(onFormSubmit)} noValidate sx={{ mt: 0 }}>
                <Grid container spacing={1.4}>
                    {sprite?.data?.type === DEVICE_TYPE.SHELF && (
                    {deviceType === DEVICE_TYPE.SHELF && (
                        <>
                            <Grid item xs={6}>
                                <Controller
@@ -100,20 +122,21 @@
                        </>
                    )}
                    {sprite?.data?.type === DEVICE_TYPE.CHARGE && (
                    {deviceType === DEVICE_TYPE.CHARGE && (
                        <>
                        </>
                    )}
                    {sprite?.data?.type === DEVICE_TYPE.STATION && (
                    {deviceType === DEVICE_TYPE.STATION && (
                        <>
                        </>
                    )}
                    {sprite?.data?.type === DEVICE_TYPE.POINT && (
                    {deviceType === DEVICE_TYPE.POINT && (
                        <>
                        </>
                    )}
                    <Grid item xs={12}>
                        <Divider />
                    </Grid>
@@ -127,18 +150,20 @@
                        <Controller
                            name="no"
                            control={control}
                            render={({ field }) => (
                                <TextField
                                    {...field}
                                    label="No"
                                    type="text"
                                    value={field.value || ''}
                                    fullWidth
                                    onChange={(e) => {
                                        field.onChange(e);
                                    }}
                                />
                            )}
                            render={({ field }) => {
                                return (
                                    <TextField
                                        {...field}
                                        label="No"
                                        type="text"
                                        value={field.value || ''}
                                        fullWidth
                                        onChange={(e) => {
                                            field.onChange(e);
                                        }}
                                    />
                                )
                            }}
                        />
                    </Grid>