skyouc
2025-04-08 05951bf4f4eacc72552eb6763c640aa8b2067105
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import React, { useState, useRef, useEffect, useMemo } from "react";
import {
    Edit,
    SimpleForm,
    FormDataConsumer,
    useTranslate,
    TextInput,
    NumberInput,
    BooleanInput,
    DateInput,
    SelectInput,
    ReferenceInput,
    ReferenceArrayInput,
    AutocompleteInput,
    SaveButton,
    Toolbar,
    Labeled,
    NumberField,
    required,
    useRecordContext,
    DeleteButton,
    useNotify,
} from 'react-admin';
import PropTypes from 'prop-types';
import { useWatch, useFormContext, useForm, useFormState } from "react-hook-form";
import { Stack, Grid, Box, Typography, Tabs, Tab, } from '@mui/material';
import * as Common from '@/utils/common';
import { EDIT_MODE, REFERENCE_INPUT_PAGESIZE } from '@/config/setting';
import EditBaseAside from "@/page/components/EditBaseAside";
import CustomerTopToolBar from "@/page/components/EditTopToolBar";
import MemoInput from "@/page/components/MemoInput";
import StatusSelectInput from "@/page/components/StatusSelectInput";
import TreeSelectInput from "@/page/components/TreeSelectInput";
import request from '@/utils/request';
const FormToolbar = () => {
    const { getValues } = useFormState();
    return (
        <Toolbar sx={{ justifyContent: 'space-between' }}>
            <SaveButton />
            <DeleteButton mutationMode="optimistic" />
        </Toolbar>
    )
}
 
function CustomTabPanel(props) {
    const { children, value, index, ...other } = props;
 
    return (
        <div
            role="tabpanel"
            hidden={value !== index}
            id={`simple-tabpanel-${index}`}
            aria-labelledby={`simple-tab-${index}`}
            {...other}
        >
            {value === index && <Box sx={{ p: 3 }}>{children}</Box>}
        </div>
    );
}
 
CustomTabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.number.isRequired,
    value: PropTypes.number.isRequired,
};
 
function a11yProps(index) {
    return {
        id: `simple-tab-${index}`,
        'aria-controls': `simple-tabpanel-${index}`,
    };
}
 
const MatnrEdit = () => {
    const translate = useTranslate();
    const [value, setValue] = React.useState(0);
 
    const notify = useNotify();
    const [dynamicFields, setDynamicFields] = useState([]);
 
    useEffect(() => {
        getDynamicFields();
    }, []);
    const getDynamicFields = async () => {
        const {
            data: { code, data, msg },
        } = await request.get("/fields/enable/list");
        if (code === 200) {
            setDynamicFields(data || [])
 
 
        } else {
            notify(msg);
        }
    };
    const handleChange = (event, newValue) => {
        setValue(newValue);
    };
    return (
        <Edit
            redirect="list"
            mutationMode={EDIT_MODE}
            actions={<CustomerTopToolBar />}
            title={"menu.matnr"}
        >
            <SimpleForm
                shouldUnregister
                warnWhenUnsavedChanges
                toolbar={<FormToolbar />}
                mode="onTouched"
                defaultValues={{}}
            // validate={(values) => { }}
            >
                <Grid container rowSpacing={3} columnSpacing={3}>
 
                    <Grid item xs={12} md={10}>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.main')}
                        </Typography>
                        <Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
                            <Tab label={translate('page.matnr.title.basic')} {...a11yProps(0)} />
                            <Tab label={translate('page.matnr.title.control')} {...a11yProps(1)} />
                            <Tab label={translate('page.matnr.title.batchRole')} {...a11yProps(2)} />
                        </Tabs>
 
                        <CustomTabPanel value={value} index={0}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.name"
                                        source="name"
                                        parse={v => v}
                                        required
                                        autoFocus
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.code"
                                        source="code"
                                        required
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <ReferenceInput source="shipperId" reference="companys" filter={{ type: 'shipper' }}>
                                        <AutocompleteInput
                                            label="table.field.matnr.shipperId"
                                            optionText="name"
                                            filterToQuery={(val) => ({ name: val })}
                                        />
                                    </ReferenceInput>
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    {/* <ReferenceInput
                                        source="groupId"
                                        reference="matnrGroup"
                                        perPage={REFERENCE_INPUT_PAGESIZE}
                                    >
                                        <AutocompleteInput
                                            label="table.field.matnr.groupId"
                                            optionText="label"
                                            validate={[required()]}
                                            filterToQuery={(val) => ({ code: val })}
                                        />
                                    </ReferenceInput> */}
 
                                    <TreeSelectInput
                                        label="table.field.matnr.groupId"
                                        resource={'matnrGroup'}
                                        source="groupId"
                                    />
                                </Grid>
 
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.platCode"
                                        source="platCode"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.spec"
                                        source="spec"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.weight"
                                        source="weight"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.color"
                                        source="color"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.size"
                                        source="size"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.describle"
                                        source="describle"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.nromNum"
                                        source="nromNum"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.unit"
                                        source="unit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.purUnit"
                                        source="purUnit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <TextInput
                                        label="table.field.matnr.stockUnit"
                                        source="stockUnit"
                                        parse={v => v}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.stockLevel"
                                        source="stockLevel"
                                        choices={[
                                            { id: 0, name: ' A' },
                                            { id: 1, name: ' B' },
                                            { id: 2, name: 'C' },
                                        ]}
                                        validate={required()}
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.isLabelMange"
                                        source="flagLabelMange"
                                        choices={[
                                            { id: 0, name: ' 否' },
                                            { id: 1, name: ' 是' },
                                        ]}
                                        validate={required()}
                                    />
                                </Grid>
 
                                {dynamicFields.map((item) => {
                                    return (
                                        <Grid key={item.id} item xs={6} display="flex" gap={1}>
                                            <DynamicFields
                                                label={item.fieldsAlise}
                                                source={item.fields}
                                                validate={item.unique === 1 ? required() : false}
                                            />
                                        </Grid>
                                    )
                                })}
 
                            </Grid>
 
                        </CustomTabPanel>
                        <CustomTabPanel value={value} index={1}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.safeQty"
                                        source="safeQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.minQty"
                                        source="minQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.maxQty"
                                        source="maxQty"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.stagn"
                                        source="stagn"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.validWarn"
                                        source="validWarn"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <NumberInput
                                        label="table.field.matnr.valid"
                                        source="valid"
                                    />
                                </Grid>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <SelectInput
                                        label="table.field.matnr.flagCheck"
                                        source="flagCheck"
                                        choices={[
                                            { id: 0, name: ' 否' },
                                            { id: 1, name: ' 是' },
                                        ]}
                                    />
                                </Grid>
                            </Grid>
                        </CustomTabPanel>
                        <CustomTabPanel value={value} index={2}>
                            <Grid container rowSpacing={2} columnSpacing={2}>
                                <Grid item xs={6} display="flex" gap={1}>
                                    <ReferenceInput
                                        source="rglar_id"
                                        reference="serialRule"
                                        perPage={REFERENCE_INPUT_PAGESIZE}
                                    >
                                        <AutocompleteInput
                                            label="table.field.matnr.rglarId"
                                            optionText="name"
                                            filterToQuery={(val) => ({ name: val })}
                                        />
                                    </ReferenceInput>
                                </Grid>
                            </Grid>
                        </CustomTabPanel>
                    </Grid>
 
 
                    <Grid item xs={12} md={2}>
                        <Typography variant="h6" gutterBottom>
                            {translate('common.edit.title.common')}
                        </Typography>
                        <StatusSelectInput />
                        <Box mt="2em" />
                        <MemoInput />
                    </Grid>
                </Grid>
            </SimpleForm>
        </Edit >
    )
}
 
export default MatnrEdit;
 
const DynamicFields = (props) => {
    const { ...parmas } = props;
    const form = useFormContext();
    const field = `extendFields.${parmas.source}`;
    const value = form.getValues(field);
    value && form.setValue(parmas.source, value);
    return (
        <TextInput
            {...parmas}
        />
    )
}