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, 
 | 
    useRefresh, 
 | 
    SelectInput, 
 | 
    NumberInput, 
 | 
    ReferenceInput, 
 | 
    ReferenceArrayInput, 
 | 
    AutocompleteInput, 
 | 
    DeleteButton, 
 | 
} from 'react-admin'; 
 | 
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; 
 | 
import MyCreateButton from "@/page/components/MyCreateButton"; 
 | 
import MyExportButton from '@/page/components/MyExportButton'; 
 | 
import PageEditDrawer from "@/page/components/PageEditDrawer"; 
 | 
import { Box, Typography, Card, Stack, Switch } from '@mui/material'; 
 | 
import ConfirmButton from '../../components/ConfirmButton'; 
 | 
import LocReviseCreate from "./LocReviseCreate"; 
 | 
import TaskIcon from '@mui/icons-material/Task'; 
 | 
import { styled } from '@mui/material/styles'; 
 | 
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 />, 
 | 
    <DateInput label='common.time.after' source="timeStart" alwaysOn />, 
 | 
    <DateInput label='common.time.before' source="timeEnd" alwaysOn />, 
 | 
    <TextInput source="code" label="table.field.locRevise.code" />, 
 | 
    <SelectInput source="type" label="table.field.locRevise.type" 
 | 
        choices={[ 
 | 
            { id: 0, name: ' 库存调整' }, 
 | 
            { id: 1, name: ' 盘点调整' }, 
 | 
            { id: 2, name: ' 其它调整' }, 
 | 
        ]} 
 | 
    />, 
 | 
    <NumberInput source="anfme" label="table.field.locRevise.anfme" />, 
 | 
    <NumberInput source="reviseQty" label="table.field.locRevise.reviseQty" />, 
 | 
    <SelectInput source="exceStatus" label="table.field.locRevise.exceStatus" 
 | 
        choices={[ 
 | 
            { id: 0, name: '未执行' }, 
 | 
            { id: 1, name: '执行中' }, 
 | 
            { id: 2, name: '执行完成' }, 
 | 
        ]} 
 | 
    />, 
 | 
    <NumberInput source="orgAreaId" label="table.field.locRevise.orgAreaId" />, 
 | 
    <TextInput source="orgAreaName" label="table.field.locRevise.orgAreaName" />, 
 | 
    <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 LocReviseList = () => { 
 | 
    const [createDialog, setCreateDialog] = useState(false); 
 | 
    const [drawerVal, setDrawerVal] = useState(false); 
 | 
    const translate = useTranslate(); 
 | 
  
 | 
    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.locRevise"} 
 | 
                empty={false} 
 | 
                filters={filters} 
 | 
                sort={{ field: "create_time", order: "desc" }} 
 | 
                actions={( 
 | 
                    <TopToolbar> 
 | 
                        <FilterButton /> 
 | 
                        <MyCreateButton onClick={() => { setCreateDialog(true) }} /> 
 | 
                        <SelectColumnsButton preferenceKey='locRevise' /> 
 | 
                        <MyExportButton /> 
 | 
                    </TopToolbar> 
 | 
                )} 
 | 
                perPage={DEFAULT_PAGE_SIZE} 
 | 
            > 
 | 
                <StyledDatagrid 
 | 
                    preferenceKey='locRevise' 
 | 
                    bulkActionButtons={false} 
 | 
                    rowClick={(id, resource, record) => false} 
 | 
                    expand={false} 
 | 
                    expandSingle={true} 
 | 
                    omit={['id', 'createTime', 'createBy', 'areaId', 'memo']} 
 | 
                > 
 | 
                    <NumberField source="id" /> 
 | 
                    <TextField source="code" label="table.field.locRevise.code" /> 
 | 
                    <TextField source="type$" label="table.field.locRevise.type" sortable={false} /> 
 | 
                    {/* <NumberField source="anfme" label="table.field.locRevise.anfme" /> 
 | 
                    <NumberField source="reviseQty" label="table.field.locRevise.reviseQty" /> */} 
 | 
                    <NumberField source="areaId" label="table.field.locRevise.areaId" /> 
 | 
                    <TextField source="areaName" label="table.field.locRevise.areaName" /> 
 | 
                    <TextField source="exceStatus$" label="table.field.locRevise.exceStatus" sortable={false} /> 
 | 
                    <TextField source="updateBy$" label="common.field.updateBy" /> 
 | 
                    <DateField source="updateTime" label="common.field.updateTime" showTime /> 
 | 
                    <TextField source="createBy$" label="common.field.createBy" /> 
 | 
                    <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' }} /> 
 | 
                        <DelButton /> 
 | 
                        <CompleteButton /> 
 | 
                    </WrapperField> 
 | 
                </StyledDatagrid> 
 | 
            </List> 
 | 
            <PageEditDrawer 
 | 
                title={"toolbar.createLocRevise"} 
 | 
                drawerVal={createDialog} 
 | 
                setDrawerVal={setCreateDialog} 
 | 
            > 
 | 
                <LocReviseCreate 
 | 
                    open={createDialog} 
 | 
                    setOpen={setCreateDialog} 
 | 
                /> 
 | 
            </PageEditDrawer> 
 | 
        </Box> 
 | 
    ) 
 | 
} 
 | 
  
 | 
const DelButton = () => { 
 | 
    const record = useRecordContext(); 
 | 
    return ( 
 | 
        record?.exceStatus == 0 ? <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} /> : <></> 
 | 
    ) 
 | 
} 
 | 
  
 | 
//完成单据 
 | 
const CompleteButton = () => { 
 | 
    const record = useRecordContext(); 
 | 
    const notify = useNotify(); 
 | 
    const refresh = useRefresh(); 
 | 
    const requestComplete = async () => { 
 | 
        const { data: { code, data, msg } } = await request.post(`/reviseLog/complete/${record.id}`); 
 | 
        if (code === 200) { 
 | 
            notify(msg); 
 | 
            refresh() 
 | 
        } else { 
 | 
            notify(msg); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    return ( 
 | 
        record.exceStatus == 1 ? <ConfirmButton label={"toolbar.confirmTransfer"} color="secondary" startIcon={<TaskIcon />} onConfirm={requestComplete} size="small" /> : <></> 
 | 
    ) 
 | 
  
 | 
} 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
export default LocReviseList; 
 |