import React, { useEffect, useMemo, useRef, useState } from "react";
import { Dropdown, Menu, Button, Tooltip } from "antd";
import { ProTable } from "@ant-design/pro-table";
import { doFetch } from "@/utils/doFetch";
import Details from "@/components/Details";
import AutoTable from "@/components/AutoTable";
import getPrem from "@/utils/getPrem";
function Instore(props) {
  const [drawer, setdrawer] = useState({
    visible: false,
    dataSource: null,
    totalCard: null,
  });

  const extraAction = function (text, record, _, action) {
    return [
      getPrem("details", action, "查看", () => {
        doFetch({
          url: "/ngic-workmanship/wmsMaterieInventory/queryById",
          params: { id: record.id },
        }).then((res) => {
          if (res.code === "0000") {
            console.log(res);
            setdrawer((v) => ({
              ...v,
              dataSource: res?.data?.data,
              totalCard: [
                {
                  cardTitle: "库存信息",
                  itemData: [
                    {
                      title: "仓库编号",
                      key: "storeCode",
                    },
                    {
                      title: "仓库名称",
                      key: "storeName",
                    },
                    {
                      title: "库位名称",
                      key: "storePositionName",
                    },
                    {
                      title: "批次号",
                      key: "materieControlNo",
                    },
                    {
                      title: "供应商名称",
                      key: "supplierName",
                    },
                    {
                      title: "库存数量",
                      key: "stockNum",
                    },
                    {
                      title: "上架时间",
                      key: "upload_time",
                    },
                  ],
                },
              ],
              visible: true,
            }));
          }
        });
      }),
    ];
  };

  const columns = [
    {
      title: "仓库名称",
      dataIndex: "storeName",
      key: "storeName",
      search: false,
    },
    {
      title: "库位名称",
      dataIndex: "stockNum",
      key: "stockNum",
      search: false,
    },
    {
      title: "物料编码",
      dataIndex: "materieId",
      key: "materieId",
      search: false,
    },
    {
      title: "物料名称",
      dataIndex: "materieName",
      key: "materieName",
    },
    {
      title: "规格型号",
      dataIndex: "specificationModel",
      key: "specificationModel",
      search: false,
    },
    {
      title: "批次号",
      dataIndex: "materieControlNo",
      key: "materieControlNo",
      search: false,
    },
    {
      title: "库存数量",
      dataIndex: "stockNum",
      key: "stockNum",
      search: false,
    },
    {
      title: "可用数量",
      dataIndex: "usableNum",
      key: "usableNum",
      search: false,
    },
    {
      title: "库存单位",
      dataIndex: "productionUnit",
      key: "productionUnit",
      search: false,
    },
    {
      title: "片厚",
      dataIndex: "SheetThickness",
      key: "SheetThickness",
      search: false,
    },
    {
      title: "铁损",
      dataIndex: "ironLoss",
      search: false,
      key: "ironLoss",
    },
    {
      title: "宽度",
      dataIndex: "width",
      key: "width",
      search: false,
    },
    {
      title: "米数",
      dataIndex: "length",
      key: "length",
      search: false,
    },
    // {
    //   title: "库存信息",
    //   dataIndex: "option",
    //   key: "option",
    //   valueType: "option",
    //   width: 100,
    //   render: (text, row, _, action) => extraAction(text, row, _, action),
    // },
  ];

  return (
    <div>
      <AutoTable
        {...props}
        pageextra="none"
        path="/ngic-workmanship/wmsMaterieInventory/queryList"
        columns={columns}
      ></AutoTable>

      <Details
        title="库存信息"
        onClose={() => {
          setdrawer((v) => ({
            ...v,
            visible: false,
          }));
        }}
        footer={false}
        destroyOnClose={true}
        width={"100%"}
        {...drawer}
      ></Details>
    </div>
  );
}

export default Instore;
