New file |
| | |
| | | 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, |
| | | useNotify, |
| | | useRefresh, |
| | | required, |
| | | useRecordContext, |
| | | DeleteButton, |
| | | } from 'react-admin'; |
| | | import { Stack, Grid, Box, Typography, Dialog, DialogTitle, DialogContent, TextField, Button, DialogActions } from '@mui/material'; |
| | | import { EDIT_MODE, DEFAULT_START_PAGE, DEFAULT_PAGE_SIZE, REFERENCE_INPUT_PAGESIZE } from '@/config/setting'; |
| | | import DialogCloseButton from "../../components/DialogCloseButton.jsx"; |
| | | import StatusSelectInput from "../../components/StatusSelectInput"; |
| | | import CustomerTopToolBar from "../../components/EditTopToolBar"; |
| | | import TreeSelectInput from "@/page/components/TreeSelectInput"; |
| | | import EditBaseAside from "../../components/EditBaseAside"; |
| | | import MemoInput from "../../components/MemoInput"; |
| | | import SaveIcon from '@mui/icons-material/Save'; |
| | | import { DataGrid } from '@mui/x-data-grid'; |
| | | import * as Common from '@/utils/common'; |
| | | import request from '@/utils/request'; |
| | | |
| | | |
| | | const CreateBySelectMats = (props) => { |
| | | const { open, setOpen, data, setData, queryForm } = props; |
| | | const [page, setPage] = useState({ page: DEFAULT_START_PAGE, pageSize: DEFAULT_PAGE_SIZE }); |
| | | const [rowCount, setRowCount] = useState(0); |
| | | const [isLoading, setIsLoading] = useState(false); |
| | | const [formData, setFormData] = useState({}); |
| | | const [tableData, setTableData] = useState([]); |
| | | const [dyFields, setDyFields] = useState([]); |
| | | const [pageSize, setPageSize] = useState(25); |
| | | const [selectedRows, setSelectedRows] = useState([]); |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const refresh = useRefresh(); |
| | | |
| | | const handleClose = (event, reason) => { |
| | | if (reason !== "backdropClick") { |
| | | setOpen(false); |
| | | } |
| | | }; |
| | | |
| | | const handleChange = (e) => { |
| | | const { name, value } = e.target; |
| | | setFormData(() => ({ |
| | | [name]: value |
| | | })); |
| | | }; |
| | | |
| | | const reset = () => { |
| | | setFormData({ |
| | | maktx: '', |
| | | matnrCode: '', |
| | | }) |
| | | } |
| | | |
| | | const handleSubmit = () => { |
| | | const hasarr = data.map(el => +el.matnrId) |
| | | const selectedData = selectedRows.filter(item => !hasarr.includes(item)).map(id => (tableData.find(row => row.id === id))); |
| | | const value = selectedData.map((el => { |
| | | const dynamicFields = dyFields.reduce((acc, item) => { |
| | | acc[item.fields] = el['extendFields']?.[item.fields] || ''; |
| | | return acc; |
| | | }, {}); |
| | | return { |
| | | id: el.id, |
| | | matnrId: el.matnrId, |
| | | maktx: el.maktx, |
| | | matnrCode: el.matnrCode, |
| | | anfme: el.anfme, |
| | | batch: el.batch, |
| | | spec: el.spec, |
| | | model: el.model, |
| | | fieldsIndex: el.fieldsIndex, |
| | | stockUnit: el.unit || '', |
| | | ...dynamicFields |
| | | } |
| | | })); |
| | | setData([...data, ...value]); |
| | | setOpen(false); |
| | | reset(); |
| | | }; |
| | | |
| | | const getData = async () => { |
| | | let params = { |
| | | ...formData, |
| | | orgAreaId: queryForm?.orgAreaId, |
| | | current: page?.page, |
| | | pageSize: page?.pageSize, |
| | | orderBy: "create_time desc" |
| | | }; |
| | | setIsLoading(true) |
| | | const res = await request.post(`/transfer/locs/items`, params); |
| | | if (res?.data?.code === 200) { |
| | | const { data } = res.data; |
| | | setTableData(data?.records); |
| | | setRowCount(data?.total); |
| | | } else { |
| | | notify(res.data.msg); |
| | | } |
| | | setIsLoading(false) |
| | | }; |
| | | |
| | | useEffect(() => { |
| | | getData(); |
| | | }, [open, page]); |
| | | |
| | | const handleSearch = () => { |
| | | getData() |
| | | }; |
| | | |
| | | return ( |
| | | <Dialog |
| | | open={open} |
| | | onClose={handleClose} |
| | | aria-labelledby="form-dialog-title" |
| | | fullWidth |
| | | disableRestoreFocus |
| | | maxWidth="xl" |
| | | > |
| | | <DialogTitle id="form-dialog-title" sx={{ |
| | | position: 'sticky', |
| | | top: 0, |
| | | backgroundColor: 'background.paper', |
| | | zIndex: 1000 |
| | | }}> |
| | | {translate("common.action.newAddMats")} |
| | | <Box sx={{ position: 'absolute', top: 8, right: 8, zIndex: 1001 }}> |
| | | <DialogCloseButton onClose={handleClose} /> |
| | | </Box> |
| | | </DialogTitle> |
| | | <DialogContent sx={{ mt: 2 }}> |
| | | <Box component="form" onSubmit={handleSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}> |
| | | <Grid container spacing={2}> |
| | | <Grid item md={3}> |
| | | <TextField |
| | | label={translate('table.field.matnr.name')} |
| | | name="maktx" |
| | | value={formData.maktx} |
| | | onChange={handleChange} |
| | | size="small" |
| | | /> |
| | | </Grid> |
| | | <Grid item md={3}> |
| | | <TextField |
| | | label={translate('table.field.matnr.code')} |
| | | name="matnrCode" |
| | | value={formData.matnrCode} |
| | | onChange={handleChange} |
| | | size="small" |
| | | /> |
| | | </Grid> |
| | | <Grid item md={2} sx={{ margin: 'auto' }}> |
| | | <Button variant="contained" onClick={handleSearch}>{translate('toolbar.query')}</Button> |
| | | </Grid> |
| | | </Grid> |
| | | </Box> |
| | | |
| | | <Box sx={{ mt: 2, height: 600, width: '100%' }}> |
| | | <SelectMatsTableView |
| | | tableData={tableData} |
| | | setTableData={setTableData} |
| | | page={page} |
| | | rowCount={rowCount} |
| | | pageSize={pageSize} |
| | | setPage={setPage} |
| | | isLoading={isLoading} |
| | | setPageSize={setPageSize} |
| | | dyFields={dyFields} |
| | | setDyFields={setDyFields} |
| | | selectedRows={selectedRows} |
| | | setSelectedRows={setSelectedRows} |
| | | /> |
| | | </Box> |
| | | </DialogContent> |
| | | <DialogActions sx={{ position: 'sticky', bottom: 0, backgroundColor: 'background.paper', zIndex: 1000 }}> |
| | | <Box sx={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}> |
| | | <Button onClick={handleSubmit} variant="contained" startIcon={<SaveIcon />}> |
| | | {translate('toolbar.confirm')} |
| | | </Button> |
| | | </Box> |
| | | </DialogActions> |
| | | </Dialog> |
| | | ); |
| | | } |
| | | |
| | | export default CreateBySelectMats; |
| | | |
| | | |
| | | const SelectMatsTableView = ({ tableData, page, isLoading, pageSize, setPage, setPageSize, rowCount, setTableData, selectedRows, setSelectedRows, dyFields, setDyFields }) => { |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const [extendColumns, setExtendColumns] = useState([]); |
| | | |
| | | const [columns, setColumns] = useState([ |
| | | { field: 'maktx', headerName: translate('table.field.matnr.name'), width: 300 }, |
| | | { field: 'matnrCode', headerName: translate('table.field.matnr.code'), width: 200 }, |
| | | { field: 'locCode', headerName: translate('table.field.locItem.locCode'), width: 100 }, |
| | | { field: 'spec', headerName: translate('table.field.matnr.spec'), width: 100 }, |
| | | { field: 'batch', headerName: translate('table.field.locItem.batch'), width: 100 }, |
| | | { field: 'model', headerName: translate('table.field.matnr.model'), width: 100 }, |
| | | { field: 'anfme', headerName: translate('table.field.locItem.anfme'), width: 100 }, |
| | | { field: 'unit', headerName: translate('table.field.matnr.unit'), width: 100 }, |
| | | { field: 'wareArea', headerName: translate('table.field.locItem.wareArea'), width: 100, sortable: false }, |
| | | ]) |
| | | |
| | | const handleSelectionChange = (ids) => { |
| | | setSelectedRows(ids) |
| | | }; |
| | | |
| | | useEffect(() => { |
| | | if (extendColumns == undefined || extendColumns.length < 1) { |
| | | getDynamicFields(); |
| | | } |
| | | }, []); |
| | | |
| | | const getDynamicFields = async () => { |
| | | const { |
| | | data: { code, data, msg }, |
| | | } = await request.get("/fields/enable/list"); |
| | | if (code === 200) { |
| | | const cols = data.map(el => ({ |
| | | field: el.fields, |
| | | headerName: el.fieldsAlise, |
| | | minWidth: 100, |
| | | flex: 1, |
| | | editable: el.unique, |
| | | valueGetter: (value, row) => { |
| | | return row.extendFields?.[el.fields] || ''; |
| | | }, |
| | | })) |
| | | setExtendColumns(cols); |
| | | setDyFields(data) |
| | | setColumns([...columns, ...cols]) |
| | | } else { |
| | | notify(msg); |
| | | } |
| | | } |
| | | |
| | | return ( |
| | | <div style={{ height: 590, width: '100%' }}> |
| | | <DataGrid |
| | | rows={tableData} |
| | | rowCount={rowCount} |
| | | columns={columns} |
| | | paginationMode="server" |
| | | paginationModel={page} |
| | | checkboxSelection |
| | | onPaginationModelChange={setPage} |
| | | onRowSelectionModelChange={handleSelectionChange} |
| | | selectionModel={selectedRows} |
| | | disableColumnMenu={true} |
| | | disableColumnSorting |
| | | disableMultipleColumnsSorting |
| | | loading={isLoading} |
| | | slotProps={{ |
| | | loadingOverlay: { |
| | | variant: 'linear-progress', |
| | | noRowsVariant: 'linear-progress', |
| | | }, |
| | | }} |
| | | /> |
| | | </div> |
| | | ); |
| | | }; |