import { connect } from "umi";
import type { CurrentUser } from "umi";
import type { ConnectState } from "@/models/connect";
import React, { useRef, useState } from "react";
import ProCard from "@ant-design/pro-card";
import { MenuFoldOutlined } from "@ant-design/icons";
import type { FormInstance } from "antd";
import { Button, Descriptions, message, Space, Spin, Table, Tree, Typography } from "antd";
import useRequest from "@ahooksjs/use-request";
import { getServerpartTree } from "@/services/options";
import type { ActionType } from "@ant-design/pro-table";
import ProTable from "@ant-design/pro-table";
import ReactHTMLTableToExcel from "react-html-table-to-excel";
import LeftSelectTree from "@/pages/reports/settlementAccount/component/leftSelectTree";
import PageTitleBox from "@/components/PageTitleBox";
import moment from "moment";
import { handleGetNestingCOMMODITYTYPETree } from "@/pages/reports/productControl/commodityInfo/service";
import { handleGetInventoryList } from "../service";
import { keyBy } from "lodash";
import InventoryDetail from "./components/inventoryDetail";
import { highlightText } from "@/utils/highlightText";
import { exportXlsxFromProColumnsExcelJS } from "@/utils/exportExcelFun";
import { formatTreeData, sortTreeData } from "@/utils/format";

const { Text } = Typography;

const inventoryInformation: React.FC<{ currentUser: CurrentUser }> = (props) => {
    const { currentUser } = props
    const downloadBtnRef = useRef<any>()
    const actionRef = useRef<ActionType>();
    const formRef = useRef<FormInstance>();
    const [reqDetailList, setReqDetailList] = useState<any>(); // 合计项数据源
    const [reqDefaultDetailList, setReqDefaultDetailList] = useState<any>(); // 合计项数据源
    const [printOut, setPrintOut] = useState<any>(); // 打印数据的内容
    const [collapsible, setCollapsible] = useState<boolean>(false)
    const [treeView, setTreeView] = useState<any>()
    const [printIndex, setPrintIndex] = useState<number>(new Date().getTime())


    // 树相关的属性和方法
    const [selectedId, setSelectedId] = useState<string>()
    // 如果出现门店 勾选门店之后 还需要服务区的数据话 就要传这个进去了
    const [selectedParentId, setSelectedParentId] = useState<string>()
    // 导出的加载效果
    const [showLoading, setShowLoading] = useState<boolean>(false)
    // 是否显示打印的表格
    const [showExportTable, setShowExportTable] = useState<boolean>(false)
    // 查询的条件
    const [searchParams, setSearchParams] = useState<any>()
    // 拿到服务区下的所有门店id集合
    const [handleAllShopId, sethandleAllShopId] = useState<any>()
    // 表格的合计数据
    const [tableSumObj, setTableSumObj] = useState<any>()
    // 当前行数据
    const [currentRow, setCurrentRow] = useState<any>()
    // 显示详情抽屉
    const [showDetail, setShowDetail] = useState<boolean>(false)
    // 当前选中的服务区id
    const [currentSelectServerpartId, setCurrentSelectServerpartId] = useState<any>()
    // 判断是不是点击了 排序、分页等
    const isNoTableReload = useRef<boolean>(false)
    // 表格数据
    const [tableData, setTableData] = useState<any>()


    const buildLeafMaps = (nodes: any[]) => {
        const dfs = (node: any): any => {
            if (!node.children || node.children.length === 0) {
                return { ...node, value: node.value.toString() }; // 叶子：value → string
            }
            const newChildren = node.children.map(dfs);
            const allLeafValues = newChildren.flatMap((c) => c.value.split(","));
            return {
                ...node,
                children: newChildren,
                value: allLeafValues.join(","), // 父级：value → "1904,1905,1906"
            };
        };
        return nodes.map(dfs);
    }

    const columns: any = [
        {
            dataIndex: "calcType",
            title: "统计类型",
            hideInTable: true,
            valueType: 'select',
            fieldProps: {
                options: [
                    { label: "一品一码", value: 1 },
                    { label: "一品多码", value: 2 },
                ]
            },
            initialValue: 1,
        },
        {
            title: "商品类别",
            dataIndex: "COMMODITY_TYPE",
            valueType: 'treeSelect',
            hideInTable: true,
            fieldProps: {
                treeCheckable: true,  // 开启复选框
                multiple: true,
                treeDefaultExpandAll: true,
                showCheckedStrategy: 'SHOW_PARENT',
                maxTagCount: "responsive",
            },
            request: async () => {
                const req = {
                    PROVINCE_CODE: currentUser?.ProvinceCode,
                    COMMODITYTYPE_VALID: 1,
                    ShowCode: false
                }
                const data = await handleGetNestingCOMMODITYTYPETree(req)

                if (data && data.length > 0) {
                    let list: any = []
                    data.forEach((item: any) => {
                        if (item.value === 1901) {
                            list.push(item)
                        }
                    })
                    return buildLeafMaps(list)
                }
                return []
            }
        },
        {
            dataIndex: 'searchText',
            title: '查询内容',
            hideInTable: true,
            fieldProps: {
                placeholder: "请输入商品名称/商品条码/商品编码"
            }
        },

        {
            title: "序号",
            dataIndex: "index",
            valueType: 'index',
            align: 'center',
            width: 80,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>商品名称</div>,
            dataIndex: "COMMODITY_NAME",
            align: 'left',
            width: 250,
            ellipsis: true,
            hideInSearch: true,
            render: (_, record) => {
                return record?.COMMODITY_NAME ? <a onClick={() => {
                    setCurrentRow(record)
                    setShowDetail(true)
                }}>
                    {highlightText(record?.COMMODITY_NAME, searchParams?.searchText)}
                </a> : "-"
            }
        },
        {
            title: <div style={{ textAlign: 'center' }}>商品条码</div>,
            dataIndex: "COMMODITY_BARCODE",
            align: 'left',
            width: 120,
            ellipsis: true,
            hideInSearch: true,
            render: (_, record) => {
                return record?.COMMODITY_BARCODE ? highlightText(record?.COMMODITY_BARCODE, searchParams?.searchText) : "-"
            }
        },
        {
            title: <div style={{ textAlign: 'center' }}>商品编码</div>,
            dataIndex: "COMMODITY_BRAND",
            align: 'left',
            width: 120,
            ellipsis: true,
            hideInSearch: true,
            render: (_, record) => {
                return record?.COMMODITY_BRAND ? highlightText(record?.COMMODITY_BRAND, searchParams?.searchText) : "-"
            }
        },
        {
            title: <div style={{ textAlign: 'center' }}>商品规格</div>,
            dataIndex: "COMMODITY_RULE",
            align: 'left',
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>剩余数量</div>,
            dataIndex: "OVERPLUSCOUNT",
            align: 'right',
            valueType: 'digit',
            // 这里如果要加默认的排序的话 需要单独在导出表格里面 单领出来
            sorter: (a, b) => a.OVERPLUSCOUNT - b.OVERPLUSCOUNT,
            // defaultSortOrder: "descend",
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>含税成本金额</div>,
            dataIndex: "OVERPLUS_AMOUNT",
            align: 'right',
            valueType: 'digit',
            sorter: (a, b) => a.OVERPLUS_AMOUNT - b.OVERPLUS_AMOUNT,
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>除税成本金额</div>,
            dataIndex: "OVERPLUS_PRICE",
            align: 'right',
            valueType: 'digit',
            sorter: (a, b) => a.OVERPLUS_PRICE - b.OVERPLUS_PRICE,
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>含税销售金额</div>,
            dataIndex: "OVERPLUS_XS_AMOUNT",
            align: 'right',
            sorter: (a, b) => a.OVERPLUS_XS_AMOUNT - b.OVERPLUS_XS_AMOUNT,
            valueType: 'digit',
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        },
        {
            title: <div style={{ textAlign: 'center' }}>除税销售金额</div>,
            dataIndex: "OVERPLUS_XS_PRICE",
            align: 'right',
            valueType: 'digit',
            sorter: (a, b) => a.OVERPLUS_XS_PRICE - b.OVERPLUS_XS_PRICE,
            width: 120,
            ellipsis: true,
            hideInSearch: true,
        }
    ]

    const exportTable = (e) => {
        e.stopPropagation();                                            // 防止Collapse组件收起
        const main = document.getElementsByClassName(`saleReportHideBox${printIndex}`)[0]
        const thead = main.querySelector('thead').cloneNode(true);  // 深克隆DOM节点
        const tbody = main.querySelector('tbody').cloneNode(true);  // 深克隆DOM节点
        const container = document.querySelector('#hiddenBox');

        const tempTable = document.createElement('table');
        tempTable.appendChild(thead);
        tempTable.appendChild(tbody);

        tempTable.setAttribute('id', 'table-to-xls-inventoryInformation');                    // 给table添加id，值与按钮上的table字段对应

        container.appendChild(tempTable);                                // 把创建的节点添加到页面容器中

        setShowLoading(false)

        downloadBtnRef.current.handleDownload();
        setShowExportTable(false)
        tempTable.remove() // 防止重复打印一个内容
    }

    const handleClose = () => {
        setCurrentRow(null)
        setShowDetail(false)
    }

    const sortListByState = (
        list: any[],
        state?: { field?: string; order?: 'ascend' | 'descend' }
    ) => {
        const arr = Array.isArray(list) ? list.slice() : [];
        if (!state?.field || !state?.order) return arr; // ★ 返回副本，避免共享引用

        const { field, order } = state;
        const factor = order === 'ascend' ? 1 : -1;

        const getVal = (v: any) => {
            if (v == null) return { type: 3, v: Number.POSITIVE_INFINITY }; // 统一丢到最后
            if (typeof v === 'number') return { type: 0, v };
            if (v instanceof Date) return { type: 1, v: v.getTime() };

            if (typeof v === 'string') {
                const t = Date.parse(v);
                if (!Number.isNaN(t)) return { type: 1, v: t };
                const n = Number(v);
                // 纯数字字符串才按数字比较（去掉前后空格，避免把 '0012' 和 '12 '误判为不同）
                if (!Number.isNaN(n) && v.trim() !== '' && String(n) === v.trim())
                    return { type: 0, v: n };
                return { type: 2, v: v }; // 普通字符串
            }
            // 其它类型转字符串
            return { type: 2, v: String(v) };
        };

        return arr
            .map((item, idx) => {
                const val = getVal(item?.[field]);
                return { item, idx, val };
            })
            .sort((a, b) => {
                // 先按类型分组，再按值比
                if (a.val.type !== b.val.type) return (a.val.type - b.val.type) * factor;
                if (a.val.v < b.val.v) return -1 * factor;
                if (a.val.v > b.val.v) return 1 * factor;
                // 值相等，用原始下标保证稳定
                return a.idx - b.idx;
            })
            .map(d => d.item);
    };


    return (
        <div ref={(el) => {
            // 打印报表
            if (!reqDetailList || reqDetailList.length === 0) return;
            setPrintOut(el);
        }} >

            {
                showLoading ?
                    <div
                        style={{
                            width: '100%',
                            height: '100%',
                            background: 'rgba(0,0,0,0.1)',
                            position: 'fixed',
                            zIndex: 5,
                            display: 'flex',
                            alignItems: 'center',
                            justifyContent: 'center'
                        }}
                    >
                        <div style={{
                            display: 'flex',
                            alignItems: 'center',
                            justifyContent: 'center',
                            padding: '15px 20px 10px',
                            background: '#fff',
                            borderRadius: '8px',
                            width: '200px'
                        }}>
                            <Spin />
                            <span style={{ marginLeft: '5px' }}>数据导出中...</span>
                        </div>
                    </div> : ''
            }

            <div className={`saleReportHideBox${printIndex}`} style={{ position: 'fixed', zIndex: -1, top: 0, left: 0 }}>
                {
                    showExportTable && reqDetailList && reqDetailList.length > 0 ?
                        <ProTable
                            columns={columns}
                            dataSource={reqDetailList}
                            pagination={false}
                            expandable={{
                                defaultExpandAllRows: true
                            }}
                            summary={(pageData) => {
                                return (
                                    <Table.Summary fixed="top">
                                        <Table.Summary.Row>
                                            <Table.Summary.Cell index={0} colSpan={4}>
                                                <div style={{ textAlign: 'center', fontWeight: 600 }}>本页合计</div>
                                            </Table.Summary.Cell>
                                            <Table.Summary.Cell index={4}>
                                                <div style={{ textAlign: 'right' }}>
                                                    {tableSumObj.OVERPLUSCOUNT ? Number(tableSumObj.OVERPLUSCOUNT.toFixed(2)).toLocaleString('zh-CN') : ''}
                                                </div>
                                            </Table.Summary.Cell>
                                            <Table.Summary.Cell index={5}>
                                                <div style={{ textAlign: 'right' }}>
                                                    {tableSumObj.OVERPLUS_AMOUNT ? Number(tableSumObj.OVERPLUS_AMOUNT.toFixed(2)).toLocaleString('zh-CN') : ''}
                                                </div>
                                            </Table.Summary.Cell>
                                            <Table.Summary.Cell index={6}>
                                                <div style={{ textAlign: 'right' }}>
                                                    {tableSumObj.OVERPLUS_PRICE ? Number(tableSumObj.OVERPLUS_PRICE.toFixed(2)).toLocaleString('zh-CN') : ''}
                                                </div>
                                            </Table.Summary.Cell>
                                            <Table.Summary.Cell index={7}>
                                                <div style={{ textAlign: 'right' }}>
                                                    {tableSumObj.OVERPLUS_XS_AMOUNT ? Number(tableSumObj.OVERPLUS_XS_AMOUNT.toFixed(2)).toLocaleString('zh-CN') : ''}
                                                </div>
                                            </Table.Summary.Cell>
                                            <Table.Summary.Cell index={8}>
                                                <div style={{ textAlign: 'right' }}>
                                                    {tableSumObj.OVERPLUS_XS_PRICE ? Number(tableSumObj.OVERPLUS_XS_PRICE.toFixed(2)).toLocaleString('zh-CN') : ''}
                                                </div>
                                            </Table.Summary.Cell>
                                        </Table.Summary.Row>
                                    </Table.Summary>
                                )
                            }}
                        /> : ''
                }
            </div>
            <div id='hiddenBox' style={{ position: 'fixed', zIndex: -1, top: 0, left: 0 }} />

            <div style={{ backgroundColor: '#fff', display: 'flex' }}>
                <LeftSelectTree setSelectedId={setSelectedId} setCollapsible={setCollapsible} setAllServiceShop={sethandleAllShopId} collapsible={collapsible} pageType={'ahjg'} collapsibleTitle={'请选择门店'} />
                <div style={{
                    width: !collapsible ? 'calc(100% - 300px)' : 'calc(100% - 60px)',
                    paddingTop: 0,
                    paddingBottom: 0,
                    paddingRight: 0
                }}>
                    <ProTable
                        actionRef={actionRef}
                        formRef={formRef}
                        columns={columns}
                        bordered
                        expandable={{
                            expandRowByClick: true
                        }}
                        scroll={{ x: "100%", y: "calc(100vh - 520px)" }}
                        headerTitle={<PageTitleBox props={props} />} // 列表表头
                        search={{ span: 6 }}
                        request={async (params, sorter) => {
                            console.log('paramsparamsparamsparamsparamsparams', params);
                            if (!selectedId || isNoTableReload.current) {
                                isNoTableReload.current = false
                                return
                            }
                            // 根据门店去判断 是哪个服务区里面的 再把服务区的id 记录下来 而且要去重
                            let serverpartId: any = []

                            if (selectedId) {
                                let list: any = selectedId.split(',')
                                if (list && list.length > 0) {
                                    list.forEach((item: any) => {
                                        for (let key in handleAllShopId) {
                                            if (handleAllShopId[key] && handleAllShopId[key].length > 0) {
                                                if (handleAllShopId[key].indexOf(Number(item)) !== -1) {
                                                    if (serverpartId && serverpartId.length > 0) {
                                                        if (serverpartId.indexOf(key) === -1) {
                                                            serverpartId.push(key)
                                                        }
                                                    } else {
                                                        serverpartId.push(key)
                                                    }
                                                }
                                            }
                                        }
                                    })
                                }
                            }

                            const sortstr = Object.keys(sorter).map(n => {
                                const value = sorter[n]
                                return value ? `${n} ${value.replace('end', '')}` : ''
                            })

                            const req: any = {
                                calcType: params?.calcType || "",
                                ProvinceCode: currentUser?.ProvinceCode,
                                ServerpartId: serverpartId && serverpartId.length > 0 ? serverpartId.toString() : "",
                                ServerpartShopId: selectedId,
                                CommodityTypeId: params?.COMMODITY_TYPE ? params?.COMMODITY_TYPE.toString() : "",
                                SearchKeyName: "COMMODITY_NAME,COMMODITY_BRAND,COMMODITY_BARCODE",
                                SearchKeyValue: params?.searchText || "",
                                PageIndex: "1",
                                PageSize: "999999",
                                SortStr: sortstr.toString()
                            }
                            setSearchParams(params)
                            const data = await handleGetInventoryList(req)
                            setCurrentSelectServerpartId(serverpartId)

                            console.log('datadata', data);
                            setTableSumObj(data.OtherData)


                            let sorterList: any = sortTreeData(JSON.parse(JSON.stringify(data.List)), sortstr.toString())

                            let fieldData: any = [
                                "OVERPLUSCOUNT",
                                "OVERPLUS_AMOUNT",
                                "OVERPLUS_PRICE",
                                "OVERPLUS_XS_AMOUNT",
                                "OVERPLUS_XS_PRICE",
                            ]

                            let enumList: any = []
                            let newPrintData: any = formatTreeData(JSON.parse(JSON.stringify(sorterList)), fieldData, enumList, [], [])
                            console.log('newPrintDatanewPrintData', newPrintData);

                            setReqDetailList(newPrintData)
                            setReqDefaultDetailList(data.List)
                            setTableData(data.List)
                            // if (data.List && data.List.length > 0) {
                            // return { data: data.List, success: true }
                            // }
                            // return { data: [], success: true }
                        }}
                        dataSource={tableData}
                        toolbar={{
                            actions: [
                                // <span style={{ visibility: 'hidden' }}>
                                //     <ReactHTMLTableToExcel
                                //         buttonText={'导出excel'}
                                //         ref={downloadBtnRef}
                                //         table="table-to-xls-inventoryInformation"
                                //         filename={`库存信息统计表`}
                                //         sheet="sheet1"
                                //     />
                                // </span>,
                                <Button
                                    key="new"
                                    type="primary"
                                    onClick={(e) => {
                                        if (reqDetailList && reqDetailList.length > 0) {
                                            // 尝试一下 导出新方法 
                                            exportXlsxFromProColumnsExcelJS(columns,
                                                reqDetailList,
                                                `库存信息统计表`,
                                                {
                                                    topTitle: `库存信息统计表`, // 顶部大标题
                                                    footerMaker: currentUser?.Name,
                                                    footerMakerTime: moment().format('YYYY-MM-DD HH:mm:ss'),
                                                    footerStatsTime: ""
                                                }
                                            )
                                        } else {
                                            message.error('暂无数据可导出！')
                                        }


                                        // if (reqDetailList && reqDetailList.length > 0) {
                                        //     setShowLoading(true)
                                        //     setTimeout(() => {
                                        //         setShowExportTable(true)
                                        //         setTimeout(() => {
                                        //             exportTable(e)
                                        //         }, 100)
                                        //     }, 100)
                                        // } else {
                                        //     message.error('暂无数据可导出！')
                                        // }
                                    }}
                                >
                                    导出excel
                                </Button>
                            ]
                        }}
                        tableExtraRender={
                            (_, data) => {
                                return <div style={{ paddingLeft: 24 }}>
                                    <Descriptions
                                        size="small" column={5}
                                        className="commity-sale-description"
                                        contentStyle={{ fontWeight: "bolder" }} labelStyle={{ color: "#00000073" }}
                                    >
                                        <Descriptions.Item label="剩余库存">{tableSumObj?.OVERPLUSCOUNT ? tableSumObj?.OVERPLUSCOUNT.toLocaleString('zh-CN') : ''}<Text
                                            type="secondary"> </Text></Descriptions.Item>
                                        <Descriptions.Item label="含税成本">{tableSumObj?.OVERPLUS_AMOUNT ? tableSumObj?.OVERPLUS_AMOUNT.toLocaleString('zh-CN') : ''}<Text
                                            type="secondary"> </Text></Descriptions.Item>
                                        <Descriptions.Item label="除税成本">{tableSumObj?.OVERPLUS_PRICE ? tableSumObj?.OVERPLUS_PRICE.toLocaleString('zh-CN') : ''}<Text
                                            type="secondary"> </Text></Descriptions.Item>
                                        <Descriptions.Item label="含税销售金额">{tableSumObj?.OVERPLUS_XS_AMOUNT ? tableSumObj?.OVERPLUS_XS_AMOUNT.toLocaleString('zh-CN') : ''}<Text
                                            type="secondary"> </Text></Descriptions.Item>
                                        <Descriptions.Item label="除税销售金额">{tableSumObj?.OVERPLUS_XS_PRICE ? tableSumObj?.OVERPLUS_XS_PRICE.toLocaleString('zh-CN') : ''}<Text
                                            type="secondary"> </Text></Descriptions.Item>
                                    </Descriptions>
                                </div>
                            }
                        }
                        summary={(pageData) => {
                            let OVERPLUSCOUNTSUM: number = 0
                            let OVERPLUS_AMOUNTSUM: number = 0
                            let OVERPLUS_PRICESUM: number = 0
                            let OVERPLUS_XS_AMOUNTSUM: number = 0
                            let OVERPLUS_XS_PRICESUM: number = 0

                            if (pageData && pageData.length > 0) {
                                pageData.forEach((item: any) => {
                                    OVERPLUSCOUNTSUM += item.OVERPLUSCOUNT
                                    OVERPLUS_AMOUNTSUM += item.OVERPLUS_AMOUNT
                                    OVERPLUS_PRICESUM += item.OVERPLUS_PRICE
                                    OVERPLUS_XS_AMOUNTSUM += item.OVERPLUS_XS_AMOUNT
                                    OVERPLUS_XS_PRICESUM += item.OVERPLUS_XS_PRICE
                                })
                            }
                            return (
                                <Table.Summary fixed="bottom">
                                    <Table.Summary.Row>
                                        <Table.Summary.Cell index={0} colSpan={5}>
                                            <div style={{ textAlign: 'center', fontWeight: 600 }}>本页合计</div>
                                        </Table.Summary.Cell>
                                        <Table.Summary.Cell index={4}>
                                            <div style={{ textAlign: 'right' }}>
                                                {OVERPLUSCOUNTSUM ? Number(OVERPLUSCOUNTSUM.toFixed(2)).toLocaleString('zh-CN') : ''}
                                            </div>
                                        </Table.Summary.Cell>
                                        <Table.Summary.Cell index={5}>
                                            <div style={{ textAlign: 'right' }}>
                                                {OVERPLUS_AMOUNTSUM ? Number(OVERPLUS_AMOUNTSUM.toFixed(2)).toLocaleString('zh-CN') : ''}
                                            </div>
                                        </Table.Summary.Cell>
                                        <Table.Summary.Cell index={6}>
                                            <div style={{ textAlign: 'right' }}>
                                                {OVERPLUS_PRICESUM ? Number(OVERPLUS_PRICESUM.toFixed(2)).toLocaleString('zh-CN') : ''}
                                            </div>
                                        </Table.Summary.Cell>
                                        <Table.Summary.Cell index={7}>
                                            <div style={{ textAlign: 'right' }}>
                                                {OVERPLUS_XS_AMOUNTSUM ? Number(OVERPLUS_XS_AMOUNTSUM.toFixed(2)).toLocaleString('zh-CN') : ''}
                                            </div>
                                        </Table.Summary.Cell>
                                        <Table.Summary.Cell index={8}>
                                            <div style={{ textAlign: 'right' }}>
                                                {OVERPLUS_XS_PRICESUM ? Number(OVERPLUS_XS_PRICESUM.toFixed(2)).toLocaleString('zh-CN') : ''}
                                            </div>
                                        </Table.Summary.Cell>
                                    </Table.Summary.Row>
                                </Table.Summary>
                            )
                        }}
                        onChange={(_pagination: any, _filters: any, sorter: any, extra: any) => {
                            console.log('onChange');
                            isNoTableReload.current = true
                            if (extra?.action === 'sort') {
                                const field = Array.isArray(sorter) ? sorter[0]?.field : sorter?.field;
                                const order = Array.isArray(sorter) ? sorter[0]?.order : sorter?.order;
                                const newList: any = sortListByState(reqDefaultDetailList, { field, order })
                                console.log('newListnewList', newList);

                                let fieldData: any = [
                                    "OVERPLUSCOUNT",
                                    "OVERPLUS_AMOUNT",
                                    "OVERPLUS_PRICE",
                                    "OVERPLUS_XS_AMOUNT",
                                    "OVERPLUS_XS_PRICE",
                                ]

                                let enumList: any = []
                                let newPrintData: any = formatTreeData(JSON.parse(JSON.stringify(newList)), fieldData, enumList, [], [])
                                setReqDetailList(newPrintData)
                            }
                        }}
                    />
                </div>
            </div>


            {/* 库存的详情信息 */}
            <InventoryDetail onShow={showDetail} onCancel={handleClose} parentRow={currentRow} currentUser={currentUser} ServerpartId={currentSelectServerpartId} shopId={selectedId} searchParams={searchParams} />

        </div>
    )
}

export default connect(({ user }: ConnectState) => ({
    currentUser: user.currentUser
}))(inventoryInformation);
