skyouc
8 天以前 f2b48ce0cfdf9b68ecc7c9d84937d69500590f81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as React from 'react';
import { Stack, Chip, Dialog, DialogTitle, DialogContent, IconButton, CircularProgress } from '@mui/material';
import { useTranslate, useRecordContext } from 'react-admin';
import CloseIcon from '@mui/icons-material/Close';
import request from '@/utils/request';
 
const CrossZoneAreaField = () => {
    const translate = useTranslate();
    const record = useRecordContext();
    const [open, setOpen] = React.useState(false);
    const [areaNames, setAreaNames] = React.useState([]);
    const [loading, setLoading] = React.useState(false);
 
    const handleOpen = () => {
        setOpen(true);
    };
 
    const handleClose = () => {
        setOpen(false);
    };
 
    const fetchAreaNames = async () => {
        if (!record?.areaIds || record.areaIds.length === 0) return;
        
        setLoading(true);
        try {            
            const res = await request.post(`/warehouseAreas/many/${record.areaIds.join(',')}`);
            if (res?.data?.code === 200) {
                setAreaNames(res.data.data || []);
            }
        } catch (error) {
            console.error('获取区域名称失败:', error);
        } finally {
            setLoading(false);
        }
    };
 
    React.useEffect(() => {
        if (record?.areaIds && record.areaIds.length > 0) {
            fetchAreaNames();
        }
    }, [record]);
 
    if (loading) {
        return <CircularProgress size={20} />;
    }
 
    return (
        <>
            <Stack 
                direction="row" 
                gap={1} 
                flexWrap="wrap" 
                onClick={handleOpen}
                sx={{ cursor: 'pointer' }}
            >
                {areaNames.slice(0, 1).map((item, idx) => (
                    <Chip
                        size="small"
                        key={item.id}
                        label={item.name || item.id}
                    />
                ))}
                {areaNames.length > 1 && (
                    <Chip
                        size="small"
                        label={`+${areaNames.length - 1}`}
                    />
                )}
                {areaNames.length === 0 && record.areaIds && record.areaIds.length > 0 && (
                    <Chip
                        size="small"
                        label={`${record.areaIds.length} 个区域`}
                    />
                )}
            </Stack>
 
            <Dialog 
                open={open} 
                onClose={handleClose}
                maxWidth="md"
                fullWidth
            >
                <DialogTitle>
                    {translate('table.field.basStation.crossZoneArea')}
                    <IconButton
                        aria-label="close"
                        onClick={handleClose}
                        sx={{
                            position: 'absolute',
                            right: 8,
                            top: 8,
                        }}
                    >
                        <CloseIcon />
                    </IconButton>
                </DialogTitle>
                <DialogContent>
                    {loading ? (
                        <CircularProgress />
                    ) : (
                        <Stack direction="row" gap={1} flexWrap="wrap" sx={{ mt: 1 }}>
                            {areaNames.map((item) => (
                                <Chip
                                    size="small"
                                    key={item.id}
                                    label={item.name || item.id}
                                />
                            ))}
                        </Stack>
                    )}
                </DialogContent>
            </Dialog>
        </>
    );
};
 
export default CrossZoneAreaField;