|  |  |  | 
|---|
|  |  |  | import { Dialog, DialogTitle, Box, DialogActions, DialogContent } from "@mui/material"; | 
|---|
|  |  |  | import React, { useState, useRef, useEffect, useMemo, useCallback, Form } from "react"; | 
|---|
|  |  |  | import { styled } from '@mui/material/styles'; | 
|---|
|  |  |  | import { FilterButton, TopToolbar, Toolbar, useTranslate, SaveButton, List, SelectInput, NumberField, WrapperField, EditButton, DeleteButton, TextField, DateField, TextInput, BooleanField, NumberInput, ReferenceField, SearchInput, SelectColumnsButton, DatagridConfigurable, Button, useRefresh } from "react-admin"; | 
|---|
|  |  |  | import { FilterButton, TopToolbar, Toolbar, useTranslate, SaveButton, List, useRecordSelection, SelectInput, NumberField, WrapperField, EditButton, DeleteButton, TextField, DateField, TextInput, BooleanField, NumberInput, ReferenceField, SearchInput, SelectColumnsButton, DatagridConfigurable, Button, useRefresh, useRecordContext, useNotify } from "react-admin"; | 
|---|
|  |  |  | import DialogCloseButton from "../components/DialogCloseButton"; | 
|---|
|  |  |  | import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_ITEM_PAGE_SIZE } from '@/config/setting'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import request from '@/utils/request'; | 
|---|
|  |  |  | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ | 
|---|
|  |  |  | '& .css-1vooibu-MuiSvgIcon-root': { | 
|---|
|  |  |  | height: '.9em' | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | })); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const SelectSiteButton = (props) => { | 
|---|
|  |  |  | const { source, setOpen, refresh, notify } = props; | 
|---|
|  |  |  | const record = useRecordContext(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const handleClick = async () => { | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | const id = record.id; | 
|---|
|  |  |  | const res = await request.post(`/waitPakin/merge`, {waitPakins: source, siteId: id}); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Button label="toolbar.selectSite" onClick={handleClick} /> | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const SelectSiteModel = (props) => { | 
|---|
|  |  |  | const { open, setOpen, record } = props; | 
|---|
|  |  |  | const { open, setOpen, source } = props; | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const [drawerVal, setDrawerVal] = useState(false); | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const handleClose = (event, reason) => { | 
|---|
|  |  |  | if (reason !== "backdropClick") { | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ( | 
|---|
|  |  |  | <Box> | 
|---|
|  |  |  | <Dialog | 
|---|
|  |  |  | sx={{width: '100%'}} | 
|---|
|  |  |  | open={open} | 
|---|
|  |  |  | onClose={handleClose} | 
|---|
|  |  |  | fullWidth | 
|---|
|  |  |  | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <DialogTitle> | 
|---|
|  |  |  | {translate('toolbar.selectSite')} | 
|---|
|  |  |  | <DialogCloseButton onClose={() => setOpen(false)} /> | 
|---|
|  |  |  | </DialogTitle> | 
|---|
|  |  |  | <DialogContent> | 
|---|
|  |  |  | <List | 
|---|
|  |  |  | resource='deviceSite' | 
|---|
|  |  |  | filter={{type : 1}} | 
|---|
|  |  |  | sx={{ | 
|---|
|  |  |  | flexGrow: 1, | 
|---|
|  |  |  | transition: (theme) => | 
|---|
|  |  |  | 
|---|
|  |  |  | <StyledDatagrid | 
|---|
|  |  |  | preferenceKey='deviceSite' | 
|---|
|  |  |  | bulkActionButtons={false} | 
|---|
|  |  |  | rowClick='toggleSelection' | 
|---|
|  |  |  | onToggleItem={(id, resource, record)=>{ | 
|---|
|  |  |  | console.log(id); | 
|---|
|  |  |  | setOpen(false); | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | omit={['id', 'createTime', 'createBy', 'memo', 'updateBy$', 'createBy$', 'createTime', 'updateTime']} | 
|---|
|  |  |  | rowClick={false} | 
|---|
|  |  |  | omit={['id','name', 'createTime','label', 'createBy', 'memo', 'updateBy$', 'createBy$', 'createTime', 'updateTime']} | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <NumberField source="id" /> | 
|---|
|  |  |  | <TextField source="name" label="table.field.deviceSite.name" /> | 
|---|
|  |  |  | 
|---|
|  |  |  | <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> | 
|---|
|  |  |  | <Button label="toolbar.selectSite" onClick={(id, resource, record)=>{ | 
|---|
|  |  |  | console.log(id); | 
|---|
|  |  |  | setOpen(false) | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | }}/> | 
|---|
|  |  |  | <WrapperField cellClassName="opt" label="common.field.opt"> | 
|---|
|  |  |  | <SelectSiteButton source={source} setOpen={setOpen} refresh={refresh} notify={notify} /> | 
|---|
|  |  |  | </WrapperField> | 
|---|
|  |  |  | </StyledDatagrid> | 
|---|
|  |  |  | </List> | 
|---|
|  |  |  | </DialogContent> | 
|---|
|  |  |  | </DialogContent> | 
|---|
|  |  |  | </Dialog> | 
|---|
|  |  |  | </Box> | 
|---|
|  |  |  | ) | 
|---|