From 6f5a86b74457f2fdad3caa63f3378e81624d47d2 Mon Sep 17 00:00:00 2001
From: lbq <1065079612@qq.com>
Date: 星期三, 11 二月 2026 08:22:14 +0800
Subject: [PATCH] 优化基础信息页面字段

---
 rsf-admin/src/page/basicInfo/basContainer/BasContainerEdit.jsx |   82 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/rsf-admin/src/page/basicInfo/basContainer/BasContainerEdit.jsx b/rsf-admin/src/page/basicInfo/basContainer/BasContainerEdit.jsx
index b493002..b57a119 100644
--- a/rsf-admin/src/page/basicInfo/basContainer/BasContainerEdit.jsx
+++ b/rsf-admin/src/page/basicInfo/basContainer/BasContainerEdit.jsx
@@ -30,6 +30,7 @@
 import MemoInput from "../../components/MemoInput";
 import StatusSelectInput from "../../components/StatusSelectInput";
 import DictionarySelect from "../../components/DictionarySelect";
+import AreasSortInput from "../../components/AreasSortInput";
 
 const FormToolbar = () => {
     const { getValues } = useFormContext();
@@ -51,6 +52,51 @@
             mutationMode={EDIT_MODE}
             actions={<CustomerTopToolBar />}
             aside={<EditBaseAside />}
+            transform={(data) => {
+                // 淇濆瓨鍓嶈浆鎹細灏� areas 浠庣函ID鏁扮粍杞崲涓� [{id, sort}] 鏍煎紡
+                // 浠庨殣钘忓瓧娈� areasSort 鑾峰彇鎺掑簭淇℃伅
+                const areas = data.areas || [];
+                const areasSort = data.areasSort || [];
+                
+                if (areas.length > 0) {
+                    if (typeof areas[0] === 'number') {
+                        // 濡傛灉鏄函ID鏁扮粍锛屼娇鐢� areasSort 涓殑鎺掑簭淇℃伅
+                        if (areasSort.length > 0 && typeof areasSort[0] === 'object') {
+                            // 浣跨敤 areasSort 涓殑鎺掑簭淇℃伅锛屼絾鍙繚鐣� areas 涓瓨鍦ㄧ殑ID
+                            const areaIds = new Set(areas);
+                            const sortedAreas = areasSort
+                                .filter(item => areaIds.has(item.id))
+                                .sort((a, b) => (a.sort || 0) - (b.sort || 0));
+                            
+                            // 濡傛灉 areasSort 涓湁鎵�鏈塈D鐨勬帓搴忎俊鎭紝浣跨敤瀹�
+                            if (sortedAreas.length === areas.length) {
+                                data.areas = sortedAreas;
+                            } else {
+                                // 鍚﹀垯锛屼负缂哄け鐨処D娣诲姞榛樿鎺掑簭
+                                const existingIds = new Set(sortedAreas.map(item => item.id));
+                                const missingIds = areas.filter(id => !existingIds.has(id));
+                                const maxSort = sortedAreas.length > 0 
+                                    ? Math.max(...sortedAreas.map(item => item.sort || 1))
+                                    : 0;
+                                const newItems = missingIds.map((id, index) => ({
+                                    id: id,
+                                    sort: maxSort + index + 1,
+                                }));
+                                data.areas = [...sortedAreas, ...newItems];
+                            }
+                        } else {
+                            // 濡傛灉娌℃湁鎺掑簭淇℃伅锛屼娇鐢ㄩ粯璁ゆ帓搴�
+                            data.areas = areas.map((id, index) => ({
+                                id: id,
+                                sort: index + 1,
+                            }));
+                        }
+                    }
+                    // 鍒犻櫎涓存椂瀛楁
+                    delete data.areasSort;
+                }
+                return data;
+            }}
         >
             <SimpleForm
                 shouldUnregister
@@ -76,13 +122,39 @@
                         </Stack>
                         <Stack direction='row' gap={2}>
                             <TextInput
+                                label="table.field.basContainer.code"
+                                source="code"
+                                parse={v => v}
+                            />
+                        </Stack>
+                        <Stack direction='row' gap={2}>
+                            <TextInput
                                 label="table.field.basContainer.codeType"
                                 source="codeType"
                                 parse={v => v}
                             />
                         </Stack>
                         <Stack direction='row' gap={2}>
-                            <ReferenceArrayInput source="areas" reference="warehouseAreas">
+                            <ReferenceArrayInput 
+                                source="areas" 
+                                reference="warehouseAreas"
+                                sort={{ field: 'sort', order: 'ASC' }}
+                                format={(value) => {
+                                    // 浠庡悗绔帴鏀舵椂锛氬皢 [{id, sort}] 杞崲涓� [id, id, ...]
+                                    if (!value || !Array.isArray(value)) return [];
+                                    if (value.length === 0) return [];
+                                    // 濡傛灉鏄璞℃暟缁勶紝鎻愬彇id
+                                    if (typeof value[0] === 'object' && value[0] !== null && value[0].id !== undefined) {
+                                        return value.map(item => item.id);
+                                    }
+                                    // 濡傛灉宸茬粡鏄函ID鏁扮粍锛岀洿鎺ヨ繑鍥�
+                                    return value;
+                                }}
+                                parse={(value) => {
+                                    // 淇濆瓨鏃讹細淇濇寔鍘熷�硷紝鐢� AreasSortInput 澶勭悊杞崲
+                                    return value;
+                                }}
+                            >
                                 <SelectArrayInput
                                     label="table.field.basContainer.areas"
                                     optionText="name"
@@ -92,16 +164,20 @@
                                 />
                             </ReferenceArrayInput>
                         </Stack>
+                        {/* 涓嬫柟鏄剧ず宸查�夊簱鍖哄拰鎺掑簭缂栬緫 */}
+                        <AreasSortInput source="areas" />
+                        {/* 闅愯棌瀛楁锛氬瓨鍌ㄦ帓搴忎俊鎭� */}
+                        <TextInput source="areasSort" style={{ display: 'none' }} />
 
                     </Grid>
-                    <Grid item xs={12} md={4}>
+                    {/* <Grid item xs={12} md={4}>
                         <Typography variant="h6" gutterBottom>
                             {translate('common.edit.title.common')}
                         </Typography>
                         <StatusSelectInput />
                         <Box mt="2em" />
                         <MemoInput />
-                    </Grid>
+                    </Grid> */}
                 </Grid>
             </SimpleForm>
         </Edit >

--
Gitblit v1.9.1