skyouc
7 天以前 06d7fb698ce6d0efc7ff4224c6b68d2f50feb716
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
    CreateBase,
    useTranslate,
    TextInput,
    NumberInput,
    BooleanInput,
    DateInput,
    SaveButton,
    SelectInput,
    ReferenceInput,
    ReferenceArrayInput,
    DatagridConfigurable,
    AutocompleteInput,
    Toolbar,
    required,
    useDataProvider,
    TextField,
    NumberField,
    ReferenceField,
    BooleanField,
    useNotify,
    useSelectAll,
    Form,
    useCreateController,
    useListContext,
    SearchInput,
    useRefresh,
    List,
    SelectArrayInput,
    useListController
} from 'react-admin';
import {
    Dialog,
    DialogActions,
    DialogContent,
    DialogTitle,
    Grid,
    Box,
    Button,
    Paper,
    TableContainer,
    Table,
    TableHead,
    TableBody,
    TableRow,
    TableCell,
    Tooltip,
    IconButton,
    styled,
 
} 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';
import { Add, Edit, Delete } from '@mui/icons-material';
import _ from 'lodash';
import { DataGrid } from '@mui/x-data-grid';
import StatusSelectInput from "../../components/StatusSelectInput";
import TreeSelectInput from "@/page/components/TreeSelectInput";
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting';
import ConfirmationNumber from '@mui/icons-material/ConfirmationNumber';
 
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
    '& .css-1vooibu-MuiSvgIcon-root': {
        height: '.9em'
    },
    '& .RaDatagrid-row': {
        cursor: 'auto'
    },
    '& .column-name': {
    },
}));
 
const filters = [
    <SearchInput source="condition" alwaysOn />,
]
 
const MatnrModal = ({ open, setOpen }) => {
    const refresh = useRefresh();
    const translate = useTranslate();
    const notify = useNotify();
 
    const [formData, setFormData] = useState({
        areaMatId: null,
        groupId: null,
        matnrId: null,
    });
 
    const { selectedIds, onUnselectItems, onSelectAll } = useListContext();
    const handleClose = (event, reason) => {
        if (reason !== "backdropClick") {
            setOpen(false);
            reset()
            refresh();
            onUnselectItems()
        }
    };
 
    const reset = () => {
        setFormData({
            areaMatId: null,
            groupId: null,
            matnrId: null,
        })
    }
 
    const handleReset = (e) => {
        e.preventDefault();
    };
 
    const handleChange = (value, name) => {
        setFormData((prevData) => ({
            ...prevData,
            [name]: value
        }));
        refresh();
    };
 
    const removeEmptyKeys = (obj) => {
        return _.pickBy(obj, (value) => {
            if (_.isObject(value)) {
                const newObj = removeEmptyKeys(value);
                return !_.isEmpty(newObj);
            }
            return !_.isNil(value) && (_.isNumber(value) ? value !== 0 : !_.isEmpty(value));
        });
    }
 
    const handleSubmit = async () => {
        const parmas = {
            locId: selectedIds,
            areaMatId: formData.areaMatId,
            groupId: formData.groupId,
            matnrId: formData.matnrId,
        }
        const res = await request.post(`/locAreaMatRela/matnr/bind`, parmas);
        if (res?.data?.code === 200) {
            handleClose()
        } else {
            notify(res.data.msg);
        }
    }
 
    const [groupId, setGroupId] = useState();
    const warehouseChange = (e) => {
        setGroupId(e.target.value)
    }
 
    return (
        <Dialog open={open} maxWidth="md" fullWidth>
            <Form onSubmit={handleSubmit}>
                <DialogCloseButton onClose={handleClose} />
                <DialogTitle>{translate('toolbar.bindmatnr')}</DialogTitle>
                <DialogContent sx={{ mt: 2 }}>
                    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3, height: 200 }}>
                        <Grid container spacing={3}>
                            <Grid item xs={3}>
                                <ReferenceInput
                                    source="areaMatId"
                                    reference="locAreaMat"
                                >
                                    <AutocompleteInput
                                        label="table.field.loc.locAreaId"
                                        optionText="code"
                                        onChange={(value) => handleChange(value, 'areaMatId')}
                                        value={formData.areaMatId}
                                        validate={required()}
                                        filterToQuery={(val) => ({ code: val })}
                                    />
                                </ReferenceInput>
                            </Grid>
                            <Grid item xs={3}>
                                <TreeSelectInput
                                    label="table.field.locAreaMatRela.groupId"
                                    resource={'matnrGroup'}
                                    source="groupId"
                                    value={formData.groupId}
                                    onChange={(e) => handleChange(e.target.value, 'groupId')}
                                />
                            </Grid>
                            <Grid  item xs={3}>
                                {/* </Grid> */}
                                {/* <Grid item xs={4}> */}
                                {/* <List
                                resource="matnr"
                                filter={{ groupId: formData.groupId }}
                                storeKey="matnrSelectList"
                                filters={filters}
                                empty={false}
                                actions={<></>}
                            >
                                <StyledDatagrid
                                    preferenceKey='matnr'
                                    bulkActionButtons={<> <SelectMatnrs></SelectMatnrs> </>}
                                    rowClick={false}
                                    omit={['id', 'createTime', 'createBy', 'memo', 'poDetlId', 'matnrId', 'asnId']}
                                >
                                    <NumberField key="id" source="id" />,
                                    <TextField key="name" source="name" label="table.field.matnr.name" />,
                                    <TextField key="code" source="code" label="table.field.matnr.code" />,
                                    <ReferenceField key="groupId" source="groupId" label="table.field.matnr.groupId" reference="matnrGroup" link={false} sortable={false}>
                                        <TextField source="name" />
                                    </ReferenceField>,
                                    <TextField key="spec" source="spec" label="table.field.matnr.spec" />,
                                    <TextField key="model" source="model" label="table.field.matnr.model" />,
                                    <NumberField key="nromNum" source="nromNum" label="table.field.matnr.nromNum" />,
                                    <TextField key="stockLeval$" source="stockLeval$" label="table.field.matnr.stockLevel" sortable={false} />,
                                    <TextField key="flagLabelMange$" source="flagLabelMange$" label="table.field.matnr.isLabelMange" sortable={false} />,
                                    <NumberField key="safeQty" source="safeQty" label="table.field.matnr.safeQty" />,
                                    <NumberField key="minQty" source="minQty" label="table.field.matnr.minQty" />,
                                    <NumberField key="maxQty" source="maxQty" label="table.field.matnr.maxQty" />,
                                    <NumberField key="validWarn" source="validWarn" label="table.field.matnr.validWarn" />,
                                    <BooleanField key="flagCheck" source="flagCheck" label="table.field.matnr.flagCheck" sortable={false} />,
                                    <BooleanField key="statusBool" source="statusBool" label="common.field.status" sortable={false} />,
                                    <TextField key="memo" source="memo" label="common.field.memo" sortable={false} />,
                                </StyledDatagrid>
                            </List> */}
                                <ReferenceArrayInput source="matnrId" reference="matnr" filter={{ groupId: formData.groupId }}>
                                    <SelectArrayInput
                                        label="table.field.locAreaMatRela.matnrId"
                                        value={formData.matnrId}
                                        onChange={(e) => handleChange(e.target.value, 'matnrId')}
                                    />
                                </ReferenceArrayInput>
                            </Grid>
                        </Grid>
                    </Box>
                </DialogContent>
                <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}>
                    <Box sx={{ width: '100%', display: 'flex', justifyContent: 'end' }}>
                        <Button type="submit" variant="contained" startIcon={<SaveIcon />}>
                            {translate('toolbar.confirm')}
                        </Button>
                    </Box>
                </DialogActions>
            </Form>
        </Dialog>
    );
}
 
export default MatnrModal;
 
const SelectMatnrs = () => {
    const { selectedIds, data, isPending, onUnselectItems } = useListContext();
    const clickMatnrs = () => {
        console.log(selectedIds);
        onUnselectItems()
    }
 
    return (
        <Button label={"toolbar.confirmSelect"} onClick={clickMatnrs}>
            <ConfirmationNumber />
        </Button>
    )
}