import React, { useState, useEffect } from "react";
import DrawInitForm from "@/components/DrawInitForm";
import { doFetch } from "@/utils/doFetch";
function Otherinstore() {
  const [open, setopen] = useState(false);

  return (
    <>
      <div
        style={{ height: "20px", width: "20px", backgroundColor: "red" }}
        onClick={() => {
          setopen(!open);
        }}
      ></div>
      <DrawInitForm
        width="1200px"
        fields={
          open
            ? {
                materialList: {
                  value: [],
                  title: "物料信息",
                  type: "table",
                  col: { span: 24 },
                  name: ["materialList"],
                  required: true,
                  linkconfig: {
                    urlchangeval: {
                      //根据url接口 改变某个value
                      database: (params) =>
                        doFetch({
                          url: "/ngic-workmanship/wmsMaterieLabel/queryByLabelId",
                          params,
                        }),
                      params: { labelId: "linked" },
                      effectresult: {
                        productionUnitName: "productionUnitName",
                        materieCode: "materieCode",
                        supplierId: "supplierId",
                        supplierName: "supplierName",
                        width: "width",
                        ironLoss: "ironLoss",
                        sheetThickness: "sheetThickness",
                        shopSign: "shopSign",
                        weight: "weight",
                        specificationModel: "specificationModel",
                      },
                    },
                  },
                  columns: [
                    {
                      title: (
                        <span>
                          批次号 <b style={{ color: "red" }}>*</b>
                        </span>
                      ),
                      dataIndex: "labelId",
                      key: "labelId",
                      valueType: "select",
                      width: 180,
                      params: {},
                      request: async () => {
                        alert("Please")
                        let res = await doFetch({
                          url: "/ngic-workmanship/wmsMaterieLabel/selectionByStatus",
                          params: { status: 1 },
                        });
                        console.log(res);
                        return res?.data?.dataList;
                      },
                      formItemProps: () => {
                        return {
                          rules: [{ required: true, message: "此项为必填项" }],
                        };
                      },
                    },

                    {
                      title: (
                        <span>
                          物料编码-名称 <b style={{ color: "red" }}>*</b>
                        </span>
                      ),
                      dataIndex: "materieCode",
                      key: "materieCode",
                      width: 160,
                      valueType: "select",
                      readonly: true,
                      renderFormItem: ({ entry }) => {
                        return (
                          <span>
                            {entry?.materieCode}-{entry?.materieName}
                          </span>
                        );
                      },
                    },
                    {
                      title: "规格型号",
                      dataIndex: "specificationModel",
                      key: "specificationModel",
                      readonly: true,
                      width: 140,
                    },

                    {
                      title: "供应商",
                      dataIndex: "supplierName",
                      key: "supplierName",
                      readonly: "supplierName",
                    },
                    {
                      title: "宽度",
                      dataIndex: "width",
                      key: "width",
                      readonly: "width",
                    },
                    {
                      title: "铁损",
                      dataIndex: "ironLoss",
                      key: "ironLoss",
                      readonly: "ironLoss",
                    },
                    {
                      title: "片厚",
                      dataIndex: "sheetThickness",
                      key: "sheetThickness",
                      readonly: "sheetThickness",
                    },
                    {
                      title: "牌号",
                      dataIndex: "shopSign",
                      key: "shopSign",
                      readonly: "shopSign",
                    },
                    {
                      title: "入库数量",
                      dataIndex: "weight",
                      key: "weight",
                      readonly: "weight",
                    },
                    {
                      title: "库存单位",
                      dataIndex: "productionUnitName",
                      key: "productionUnitName",
                      readonly: "productionUnitName",
                    },
                    {
                      title: "操作",
                      valueType: "option",
                      width: 70,
                      render: (text, record, _, action) => [
                        <a key="delete" onClick={() => {}}>
                          删除
                        </a>,
                      ],
                    },
                  ],
                  rowKey: "id",
                },
              }
            : {}
        }
        visible={open}
        onClose={() => {
          setopen(false);
        }}
      ></DrawInitForm>
    </>
  );
}

export default Otherinstore;
