verou
2025-03-18 a7e9d0a982fc4e2d8e88d397d259dd3ebcfc2cff
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
import React, { useState, useRef, useEffect, useMemo, useCallback } from "react";
import { useNavigate } from 'react-router-dom';
import {
    List,
    DatagridConfigurable,
    SearchInput,
    TopToolbar,
    SelectColumnsButton,
    EditButton,
    FilterButton,
    CreateButton,
    ExportButton,
    BulkDeleteButton,
    WrapperField,
    useRecordContext,
    useTranslate,
    useNotify,
    useListContext,
    FunctionField,
    TextField,
    NumberField,
    DateField,
    BooleanField,
    ReferenceField,
    TextInput,
    DateTimeInput,
    DateInput,
    SelectInput,
    NumberInput,
    ReferenceInput,
    ReferenceArrayInput,
    AutocompleteInput,
    DeleteButton,
    useRefresh,
    Button
} from 'react-admin';
import { Box, Typography, Card, Stack } from '@mui/material';
import { styled } from '@mui/material/styles';
import LocCreate from "./LocCreate";
import LocPanel from "./LocPanel";
import EmptyData from "../../components/EmptyData";
import MyCreateButton from "../../components/MyCreateButton";
import MyExportButton from '../../components/MyExportButton';
import InitButton from './InitButton';
import BatchModal from './BatchModal';
import PageDrawer from "../../components/PageDrawer";
import MyField from "../../components/MyField";
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting';
import * as Common from '@/utils/common';
import DashboardIcon from '@mui/icons-material/Dashboard';
import EditIcon from '@mui/icons-material/Edit';
import request from '@/utils/request';
 
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
    '& .css-1vooibu-MuiSvgIcon-root': {
        height: '.9em'
    },
    '& .RaDatagrid-row': {
        cursor: 'auto'
    },
    '& .column-name': {
    },
    '& .opt': {
        width: 200
    },
}));
 
const filters = [
    <SearchInput source="condition" alwaysOn />,
 
    <NumberField source="warehouseId$" label="table.field.loc.warehouseId" />,
    <NumberField source="areaId$" label="table.field.loc.areaId" />,
    <TextInput source="code" label="table.field.loc.code" />,
    <TextInput source="type" label="table.field.loc.type" />,
    <TextInput source="name" label="table.field.loc.name" />,
    <NumberInput source="flagLogic" label="table.field.loc.flagLogic" />,
    <TextInput source="fucAtrrs" label="table.field.loc.fucAtrrs" />,
    <TextInput source="barcode" label="table.field.loc.barcode" />,
    <TextInput source="unit" label="table.field.loc.unit" />,
    <TextInput source="size" label="table.field.loc.size" />,
    <NumberInput source="row" label="table.field.loc.row" />,
    <NumberInput source="col" label="table.field.loc.col" />,
    <NumberInput source="lev" label="table.field.loc.lev" />,
    <NumberInput source="channel" label="table.field.loc.channel" />,
    <NumberInput source="maxParts" label="table.field.loc.maxParts" />,
    <NumberInput source="maxPack" label="table.field.loc.maxPack" />,
    <NumberInput source="flagLabelMange" label="table.field.loc.flagLabelMange" />,
    <TextInput source="locAttrs" label="table.field.loc.locAttrs" />,
 
    <TextInput label="common.field.memo" source="memo" />,
    <SelectInput
        label="common.field.status"
        source="status"
        choices={[
            { id: '1', name: 'common.enums.statusTrue' },
            { id: '0', name: 'common.enums.statusFalse' },
        ]}
        resettable
    />,
]
 
const LocList = () => {
    const translate = useTranslate();
 
    const [createDialog, setCreateDialog] = useState(false);
    const [drawerVal, setDrawerVal] = useState(false);
 
 
    return (
        <Box display="flex">
            <List
                sx={{
                    flexGrow: 1,
                    transition: (theme) =>
                        theme.transitions.create(['all'], {
                            duration: theme.transitions.duration.enteringScreen,
                        }),
                    marginRight: drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0,
                }}
                title={"menu.loc"}
                empty={<EmptyData onClick={() => { setCreateDialog(true) }} />}
                filters={filters}
                sort={{ field: "create_time", order: "desc" }}
                actions={(
                    <TopToolbar>
                        <FilterButton />
                        <InitButton />
                        <MyCreateButton onClick={() => { setCreateDialog(true) }} />
                        <SelectColumnsButton preferenceKey='loc' />
                        <MyExportButton />
                    </TopToolbar>
                )}
                perPage={DEFAULT_PAGE_SIZE}
            >
                <StyledDatagrid
                    preferenceKey='loc'
                    bulkActionButtons={
                        <>
                            <BatchButton />
                            <BulkDeleteButton />
                        </>
                    }
                    rowClick={() => false}
                    expand={() => <LocPanel />}
                    omit={['id', 'createTime', 'createBy', 'memo']}
                >
                    <NumberField source="id" />
                    <NumberField source="warehouseId$" label="table.field.loc.warehouseId" />
                    <NumberField source="areaId$" label="table.field.loc.areaId" />
                    <TextField source="code" label="table.field.loc.code" />
                    <TextField source="type" label="table.field.loc.type" />
                    <TextField source="name" label="table.field.loc.name" />
                    <NumberField source="flagLogic" label="table.field.loc.flagLogic" />
                    <TextField source="fucAtrrs" label="table.field.loc.fucAtrrs" />
                    <TextField source="barcode" label="table.field.loc.barcode" />
                    <TextField source="unit" label="table.field.loc.unit" />
                    <TextField source="size" label="table.field.loc.length" />
                    <TextField source="size" label="table.field.loc.width" />
                    <TextField source="size" label="table.field.loc.height" />
                    <NumberField source="lrow" label="table.field.loc.row" />
                    <NumberField source="col" label="table.field.loc.col" />
                    <NumberField source="lev" label="table.field.loc.lev" />
                    <NumberField source="channel" label="table.field.loc.channel" />
                    <NumberField source="maxParts" label="table.field.loc.maxParts" />
                    <NumberField source="maxPack" label="table.field.loc.maxPack" />
                    <NumberField source="flagLabelMange" label="table.field.loc.flagLabelMange" />
                    <TextField source="locAttrs" label="table.field.loc.locAttrs" />
                    <ReferenceField source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}>
                        <TextField source="nickname" />
                    </ReferenceField>
                    <DateField source="updateTime" label="common.field.updateTime" showTime />
                    <ReferenceField source="createBy" label="common.field.createBy" reference="user" link={false} sortable={false}>
                        <TextField source="nickname" />
                    </ReferenceField>
                    <DateField source="createTime" label="common.field.createTime" showTime />
                    <BooleanField source="statusBool" label="common.field.status" sortable={false} />
                    <TextField source="memo" label="common.field.memo" sortable={false} />
                    <WrapperField cellClassName="opt" label="common.field.opt">
                        <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} />
                        {/* <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} /> */}
                        <EnableButton />
                    </WrapperField>
                </StyledDatagrid>
            </List>
            <LocCreate
                open={createDialog}
                setOpen={setCreateDialog}
            />
            <PageDrawer
                title='Loc Detail'
                drawerVal={drawerVal}
                setDrawerVal={setDrawerVal}
            >
            </PageDrawer>
        </Box>
    )
}
 
export default LocList;
 
const EnableButton = () => {
    const record = useRecordContext();
    const notify = useNotify();
    const refresh = useRefresh();
    const enable = async () => {
        const res = await request.post('/loc/update', {
            ...record,
            status: +!record.status
        });
        if (res?.data?.code === 200) {
            refresh()
        } else {
            notify(res.data.msg);
        }
    }
    return (
        record.status === 1 ?
            (<Button onClick={enable} label={"toolbar.unenable"}>
                <DashboardIcon />
            </Button>) : (<Button onClick={enable} label={"toolbar.enable"}>
                <DashboardIcon />
            </Button>)
 
    )
}
 
const BatchButton = () => {
    const record = useRecordContext();
    const notify = useNotify();
    const refresh = useRefresh();
    const { selectedIds } = useListContext();
    console.log(selectedIds)
 
    const [createDialog, setCreateDialog] = useState(false);
 
    return (
        <>
            <Button onClick={() => setCreateDialog(true)} label={"toolbar.batch"}>
                <EditIcon />
            </Button>
 
            <BatchModal
                open={createDialog}
                setOpen={setCreateDialog}
            />
        </>
 
    )
}
const CustomBulkActionButton = () => {
    const { selectedIds } = useListContext();
    const notify = useNotify();
    const refresh = useRefresh();
 
    const handleCustomBulkAction = async () => {
        if (selectedIds.length === 0) {
            notify('请选择要操作的记录');
            return;
        }
        // 这里写具体的批量操作逻辑,例如向服务器发送请求
        try {
            const res = await request.post('/loc/bulk-action', { ids: selectedIds });
            if (res?.data?.code === 200) {
                refresh();
                notify('批量操作成功');
            } else {
                notify(res.data.msg);
            }
        } catch (error) {
            notify('批量操作失败,请稍后重试');
        }
    };
 
    return (
        <Button onClick={handleCustomBulkAction} label="自定义批量操作">
            {/* 可以添加自定义图标 */}
            <EditIcon />
        </Button>
    );
};