zhou zhou
2026-03-19 eb49fb9a98d6dd4e4361daf4eac4f9313236b8e8
rsf-admin/src/page/work/stockTransfer/stockTransferList.jsx
@@ -1,4 +1,4 @@
import React, { useState, useRef, useEffect, useMemo } from "react";
import React, { useState, useRef, useEffect, useMemo, useCallback } from "react";
import { useWatch, useFormContext } from "react-hook-form";
import {
    CreateBase,
@@ -75,33 +75,104 @@
    tableRef.current = useGridApiRef();
    const translate = useTranslate();
    const [orgLoc, setOrgLoc] = useState([]);
    const [tarLoc, setTarLoc] = useState([]);
    const [orgLoc, setOrgLoc] = useState("");
    const [tarLoc, setTarLoc] = useState("");
    const [tarLocList, setTarLocList] = useState([]);
    const [tarLocTotal, setTarLocTotal] = useState(0);
    const [tarLocLoading, setTarLocLoading] = useState(false);
    const tarLocPageRef = useRef(1);
    const tarLocQueryRef = useRef("");
    const debounceRef = useRef(null);
    const PAGE_SIZE = 50;
    useEffect(() => {
        selectAreaNoUse();
    },[orgLoc])
        if (orgLoc === "" || orgLoc.length < 7) {
            return;
        }
        selectLocItem().then((is) => {
            if (is) {
                setTarLocList([]);
                setTarLocTotal(0);
                setTarLoc(null);
            }
        });
    }, [orgLoc]);
    const selectAreaNoUse = async() =>{
    const selectLocItem = async () => {
        const {
            data: { code, data, msg },
        } = await request.post("/loc/areaNoUse/list",{
        } = await request.post("/locItem/useO/page", {
            locCode: orgLoc,
            current: 1,
            pageSize: 100,
            orderBy: "create_time desc"
        });
        if (code === 200) {
            const newData = data.map((item) => {
                return {
                    label: item,
                    id: item
                }
            })
            console.log(newData);
            setTarLocList(newData);
            if (data.total !== 0) {
                setTableData(data.records);
                return true;
            }
        }
        return false;
    };
    }
    const loadAreaNoUsePage = useCallback(async (current = 1, q = "", append = false) => {
        if (!orgLoc || orgLoc.length < 7) return;
        setTarLocLoading(true);
        try {
            const { data: { code, data: pageData } } = await request.post("/loc/areaNoUse/page", {
                locCode: orgLoc,
                current,
                pageSize: PAGE_SIZE,
                q: q || undefined
            });
            if (code === 200 && pageData) {
                const { records = [], total = 0 } = pageData;
                const options = (records || []).map((item) => ({ label: item, id: item }));
                if (append) {
                    setTarLocList((prev) => [...prev, ...options]);
                } else {
                    setTarLocList(options);
                }
                setTarLocTotal(total);
                tarLocPageRef.current = current;
                tarLocQueryRef.current = q;
            }
        } finally {
            setTarLocLoading(false);
        }
    }, [orgLoc]);
    const handleTarLocOpen = useCallback(() => {
        if (orgLoc && orgLoc.length >= 7) {
            tarLocPageRef.current = 1;
            tarLocQueryRef.current = "";
            loadAreaNoUsePage(1, "", false);
        }
    }, [orgLoc, loadAreaNoUsePage]);
    const handleTarLocInputChange = useCallback((e, value) => {
        if (debounceRef.current) clearTimeout(debounceRef.current);
        if (!orgLoc || orgLoc.length < 7) return;
        debounceRef.current = setTimeout(() => {
            loadAreaNoUsePage(1, value ?? "", false);
            debounceRef.current = null;
        }, 300);
    }, [orgLoc, loadAreaNoUsePage]);
    const handleTarLocListboxScroll = useCallback((e) => {
        const el = e.target;
        if (!el || tarLocLoading) return;
        const { scrollTop, scrollHeight, clientHeight } = el;
        if (scrollTop + clientHeight >= scrollHeight - 10) {
            const loaded = tarLocList.length;
            if (loaded < tarLocTotal) {
                const nextPage = Math.floor(loaded / PAGE_SIZE) + 1;
                loadAreaNoUsePage(nextPage, tarLocQueryRef.current, true);
            }
        }
    }, [tarLocLoading, tarLocList.length, tarLocTotal, loadAreaNoUsePage]);
    const handleDeleteItem = () => {
@@ -143,10 +214,17 @@
                                        <Autocomplete
                                            disablePortal
                                            options={tarLocList}
                                            loading={tarLocLoading}
                                            filterOptions={(opts) => opts}
                                            onOpen={handleTarLocOpen}
                                            onInputChange={handleTarLocInputChange}
                                            renderInput={(params) => (
                                                <TextField {...params} label={translate("table.field.stockTransfer.tarLoc")} />
                                            )}
                                            onChange={(event, value) => setTarLoc(value)}
                                            ListboxProps={{
                                                onScroll: handleTarLocListboxScroll
                                            }}
                                        />
                                    </Stack>
                                </Box>
@@ -154,7 +232,8 @@
                                <Stack direction='row' spacing={2} minWidth={200}>
                                    <SubmitButton
                                        orgLoc={orgLoc}
                                        tarLoc={tarLoc}
                                        tarLoc={tarLoc}
                                        tabelData={tabelData}
                                    />
                                </Stack>
                            </Box>
@@ -185,32 +264,27 @@
    const notify = useNotify();
    const redirect = useRedirect();
    const refresh = useRefresh();
    const { orgLoc, tarLoc } = props;
    const check = () => {
        console.log(orgLoc, tarLoc);
    const { orgLoc, tarLoc, tabelData } = props;
    const move = () => {
        if (orgLoc === "" || orgLoc === undefined || orgLoc === null) {
            notify("请选择站点");
            notify("请输入源库位");
            return;
        }
        if (tarLoc === "" || tarLoc === undefined || tarLoc === null) {
            notify("请选择站点");
            notify("请输入目标库位");
            return;
        }
    }
    const http = async (sta, items) => {
        console.log(items);
        const filter = items.filter(item => (item.outQty + item.workQty) > item.anfme);
        if (filter.length > 0) {
            notify(translate('toolbar.request.error.out_stock_qty'))
            return
        }
        const { data: { code, data, msg } } = await request.post(`/locItem/generate/task`, { siteNo: sta, items: items });
        if (tabelData.length === 0) {
            notify("源库位明细无,请检查库位状态");
            return;
        }
        http(orgLoc, tarLoc?.id)
    }
    const http = async (orgLoc, tarLoc) => {
        const { data: { code, data, msg } } = await request.post(`/locItem/move/task`, { orgLoc, tarLoc });
        if (code === 200) {
            notify(msg);
            refresh()
            setTableData([])
            redirect("/task")
        } else {
            notify(msg);
@@ -220,7 +294,7 @@
        <ConfirmButton
            variant="contained"
            color="primary"
            onConfirm={check}
            onConfirm={move}
            label={"table.field.outBound.createTask"}
        >
        </ConfirmButton>
@@ -246,19 +320,19 @@
            width: 100,
            editable: false,
        },
        {
            field: 'workQty',
            headerName: translate('table.field.locItem.workQty'),
            width: 100,
            type: 'number',
            editable: false,
        },
        {
            field: 'locCode',
            headerName: translate('table.field.locItem.locCode'),
            width: 100,
            editable: false,
        },
        // {
        //     field: 'workQty',
        //     headerName: translate('table.field.locItem.workQty'),
        //     width: 100,
        //     type: 'number',
        //     editable: false,
        // },
        // {
        //     field: 'tarLoc',
        //     headerName: translate('table.field.stockTransfer.tarLoc'),
        //     width: 100,
        //     editable: false,
        // },
        {
            field: 'matnrCode',
            headerName: translate('table.field.locItem.matnrCode'),
@@ -316,7 +390,7 @@
                flex: 1,
                editable: false
            }))
            setColumns([...columns, ...cols, action])
            setColumns([...columns, ...cols])
        } else {
            notify(msg);
        }
@@ -348,7 +422,8 @@
            <DataGrid
                apiRef={tableRef}
                rows={tabelData}
                columns={columns}
                columns={columns}
                checkboxSelection = {false}
                disableRowSelectionOnClick
                getRowId={(row) => row.matnrId ? row.matnrId : row.id}
                disableColumnFilter
@@ -363,9 +438,8 @@
                        },
                    },
                }}
                pageSizeOptions={[10, 25, 50, 100]}
                editMode="row"
                checkboxSelection
                pageSizeOptions={[10, 20, 50, 100]}
                editMode="row"
                onRowSelectionModelChange={handleSelectionChange}
                selectionModel={selectedRows}
                sx={{