From 1ec363b2a7195cb47e35a7e119012e20366aa71a Mon Sep 17 00:00:00 2001
From: verou <857149855@qq.com>
Date: 星期二, 18 三月 2025 10:00:33 +0800
Subject: [PATCH] feat:字典选择器

---
 rsf-admin/src/page/basicInfo/loc/InitModal.jsx     |  249 +++++++++++++++++++++--------------------
 rsf-admin/src/page/basicInfo/loc/LocCreate.jsx     |   17 ++
 rsf-admin/src/page/basicInfo/whMat/WhMatList.jsx   |    2 
 rsf-admin/src/page/components/DictionarySelect.jsx |   45 +++++++
 rsf-admin/src/page/basicInfo/loc/LocEdit.jsx       |   19 ++-
 rsf-admin/.env                                     |    4 
 rsf-admin/src/page/asnOrder/AsnOrderModal.jsx      |    2 
 7 files changed, 202 insertions(+), 136 deletions(-)

diff --git a/rsf-admin/.env b/rsf-admin/.env
index a8ce658..9669b2c 100644
--- a/rsf-admin/.env
+++ b/rsf-admin/.env
@@ -1,3 +1,3 @@
-VITE_BASE_IP=192.168.4.24
-# VITE_BASE_IP=47.76.147.249
+# VITE_BASE_IP=192.168.4.24
+VITE_BASE_IP=47.76.147.249
 VITE_BASE_PORT=8080
diff --git a/rsf-admin/src/page/asnOrder/AsnOrderModal.jsx b/rsf-admin/src/page/asnOrder/AsnOrderModal.jsx
index 2942d22..1b23e74 100644
--- a/rsf-admin/src/page/asnOrder/AsnOrderModal.jsx
+++ b/rsf-admin/src/page/asnOrder/AsnOrderModal.jsx
@@ -183,7 +183,7 @@
                                         onBlur={requestSetHead}
                                         variant="outlined"
                                         size="small"
-                                        validate={required()}
+                                        required
                                     />
                                 </Grid>
 
diff --git a/rsf-admin/src/page/basicInfo/loc/InitModal.jsx b/rsf-admin/src/page/basicInfo/loc/InitModal.jsx
index ef64347..ed84903 100644
--- a/rsf-admin/src/page/basicInfo/loc/InitModal.jsx
+++ b/rsf-admin/src/page/basicInfo/loc/InitModal.jsx
@@ -43,6 +43,7 @@
 
 } 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';
@@ -61,14 +62,14 @@
     const notify = useNotify();
 
     const [formData, setFormData] = useState({
-        "areaId": "",
-        "endBay": "",
-        "endLev": "",
-        "endRow": "",
+        "areaId": undefined,
+        "endBay": undefined,
+        "endLev": undefined,
+        "endRow": undefined,
         "locType": "",
-        "startBay": "",
-        "startLev": "",
-        "startRow": "",
+        "startBay": undefined,
+        "startLev": undefined,
+        "startRow": undefined,
         "type": ""
     });
 
@@ -82,11 +83,10 @@
         e.preventDefault();
     };
 
-    const handleChange = (e) => {
-        const { name, value } = e.target;
+    const handleChange = (value, name) => {
         setFormData((prevData) => ({
             ...prevData,
-            [name]: value
+            [name]: ['locType', 'type'].includes(name) ? value : +value
         }));
     };
 
@@ -106,118 +106,125 @@
             <DialogCloseButton onClose={handleClose} />
             <DialogTitle>{translate('toolbar.locInit')}</DialogTitle>
             <DialogContent sx={{ mt: 2 }}>
-                <Box component="form" sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
-                    <Grid container spacing={2}>
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.areaId")}
-                                name="wkType"
-                                value={formData.areaId}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
+                <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
+                    <Form>
+
+                        <Grid container spacing={2}>
+                            <Grid item xs={4}>
+                                <ReferenceInput
+                                    source="areaId"
+                                    reference="warehouseAreas"
+                                >
+                                    <AutocompleteInput
+                                        label="table.field.loc.areaId"
+                                        optionText="name"
+                                        onChange={(value) => handleChange(value, 'areaId')}
+                                        value={formData.areaId}
+                                        validate={[required()]}
+                                        filterToQuery={(val) => ({ name: val })}
+                                    />
+                                </ReferenceInput>
+
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <DictionarySelect
+                                    label={translate("table.field.loc.locType")}
+                                    name="locType"
+                                    value={formData.locType}
+                                    onChange={(e) => handleChange(e.target.value, 'locType')}
+                                    size="small"
+                                    validate={[required()]}
+                                    dictTypeCode="sys_width_type"
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <DictionarySelect
+                                    label={translate("table.field.loc.type")}
+                                    name="type"
+                                    value={formData.type}
+                                    onChange={(e) => handleChange(e.target.value, 'type')}
+                                    size="small"
+                                    validate={[required()]}
+                                    dictTypeCode="sys_loc_type"
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.startBay")}
+                                    name="startBay"
+                                    value={formData.startBay}
+                                    onChange={(e) => handleChange(e.target.value, 'startBay')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.startLev")}
+                                    name="startLev"
+                                    value={formData.startLev}
+                                    onChange={(e) => handleChange(e.target.value, 'startLev')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.startRow")}
+                                    name="startRow"
+                                    value={formData.startRow}
+                                    onChange={(e) => handleChange(e.target.value, 'startRow')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.endBay")}
+                                    name="endBay"
+                                    value={formData.endBay}
+                                    onChange={(e) => handleChange(e.target.value, 'endBay')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.endLev")}
+                                    name="endLev"
+                                    value={formData.endLev}
+                                    onChange={(e) => handleChange(e.target.value, 'endLev')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
+                            <Grid item xs={4}>
+                                <TextField
+                                    label={translate("table.field.loc.endRow")}
+                                    name="endRow"
+                                    value={formData.endRow}
+                                    onChange={(e) => handleChange(e.target.value, 'endRow')}
+                                    size="small"
+                                    type="number"
+                                    required
+                                />
+                            </Grid>
+
                         </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.locType")}
-                                name="wkType"
-                                value={formData.locType}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.type")}
-                                name="wkType"
-                                value={formData.type}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.startBay")}
-                                name="type"
-                                value={formData.startBay}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.startLev")}
-                                name="wkType"
-                                value={formData.startLev}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.startRow")}
-                                name="wkType"
-                                value={formData.startRow}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.endBay")}
-                                name="wkType"
-                                value={formData.endBay}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.endLev")}
-                                name="wkType"
-                                value={formData.endLev}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-                        <Grid item xs={4}>
-                            <TextField
-                                label={translate("table.field.loc.endRow")}
-                                name="wkType"
-                                value={formData.endRow}
-                                onChange={handleChange}
-                                variant="outlined"
-                                size="small"
-                                validate={required()}
-                            />
-                        </Grid>
-
-
-                    </Grid>
+                    </Form>
                 </Box>
             </DialogContent>
             <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
diff --git a/rsf-admin/src/page/basicInfo/loc/LocCreate.jsx b/rsf-admin/src/page/basicInfo/loc/LocCreate.jsx
index e48599a..0602179 100644
--- a/rsf-admin/src/page/basicInfo/loc/LocCreate.jsx
+++ b/rsf-admin/src/page/basicInfo/loc/LocCreate.jsx
@@ -119,12 +119,19 @@
                                     />
                                 </Grid>
                                 <Grid item xs={6} display="flex" gap={1}>
-                                    <TextInput
-                                        label="table.field.loc.type"
+                                    <ReferenceInput
                                         source="type"
-                                        parse={v => v}
-                                        validate={required()}
-                                    />
+                                        reference="dictData"
+                                        filter={{ dictTypeCode: 'sys_loc_type' }}
+                                    >
+                                        <AutocompleteInput
+                                            label="table.field.loc.type"
+                                            optionText="label"
+                                            optionValue="value"
+                                            parse={v => v}
+                                            validate={[required()]}
+                                        />
+                                    </ReferenceInput>
                                 </Grid>
                                 {/* <Grid item xs={6} display="flex" gap={1}>
                                     <TextInput
diff --git a/rsf-admin/src/page/basicInfo/loc/LocEdit.jsx b/rsf-admin/src/page/basicInfo/loc/LocEdit.jsx
index ab883db..3ea6793 100644
--- a/rsf-admin/src/page/basicInfo/loc/LocEdit.jsx
+++ b/rsf-admin/src/page/basicInfo/loc/LocEdit.jsx
@@ -66,7 +66,7 @@
                         <Grid container rowSpacing={2} columnSpacing={2}>
                             <Grid item xs={6} display="flex" gap={1}>
                                 <ReferenceInput
-                                    source="warehouseId$"
+                                    source="warehouseId"
                                     reference="warehouse"
                                 >
                                     <AutocompleteInput
@@ -99,12 +99,19 @@
                                 />
                             </Grid>
                             <Grid item xs={6} display="flex" gap={1}>
-                                <TextInput
-                                    label="table.field.loc.type"
+                                <ReferenceInput
                                     source="type"
-                                    parse={v => v}
-                                    validate={required()}
-                                />
+                                    reference="dictData"
+                                    filter={{ dictTypeCode: 'sys_loc_type' }}
+                                >
+                                    <AutocompleteInput
+                                        label="table.field.loc.type"
+                                        optionText="label"
+                                        optionValue="value"
+                                        parse={v => v}
+                                        validate={[required()]}
+                                    />
+                                </ReferenceInput>
                             </Grid>
                             <Grid item xs={6} display="flex" gap={1}>
                                 <TextInput
diff --git a/rsf-admin/src/page/basicInfo/whMat/WhMatList.jsx b/rsf-admin/src/page/basicInfo/whMat/WhMatList.jsx
index 16631c9..d0b4c7c 100644
--- a/rsf-admin/src/page/basicInfo/whMat/WhMatList.jsx
+++ b/rsf-admin/src/page/basicInfo/whMat/WhMatList.jsx
@@ -145,7 +145,7 @@
   const getMatnrList = async () => {
     const {
       data: { code, data, msg },
-    } = await request.post("/matnr/list", {}).then();
+    } = await request.post("/matnr/list", {});
     if (code === 200) {
       console.log(data);
     } else {
diff --git a/rsf-admin/src/page/components/DictionarySelect.jsx b/rsf-admin/src/page/components/DictionarySelect.jsx
new file mode 100644
index 0000000..43dc811
--- /dev/null
+++ b/rsf-admin/src/page/components/DictionarySelect.jsx
@@ -0,0 +1,45 @@
+import EditIcon from '@mui/icons-material/Edit';
+import { useState, useEffect } from 'react';
+import {
+    Button, useListContext, SelectInput,
+    required,
+    useTranslate, useNotify
+} from 'react-admin';
+import request from '@/utils/request';
+
+const DictionarySelect = (props) => {
+    const { dictTypeCode, name, ...parmas } = props;
+    const { selectedIds } = useListContext();
+    const translate = useTranslate();
+    const notify = useNotify();
+    const [list, setList] = useState([])
+
+    useEffect(() => {
+        http()
+    }, [dictTypeCode]);
+
+    const http = async () => {
+        const res = await request.post('/dictData/page', { dictTypeCode });
+        if (res?.data?.code === 200) {
+
+            setList(res.data.data.records.map((item) => {
+                return {
+                    id: item.value,
+                    name: item.value
+                }
+            }))
+        } else {
+            notify(res.data.msg);
+        }
+    }
+
+    return (
+        <SelectInput
+            source={name}
+            choices={list}
+            {...parmas}
+        />
+    );
+};
+
+export default DictionarySelect;
\ No newline at end of file

--
Gitblit v1.9.1