import { doFetch } from "@/utils/doFetch";

export function getColumns(setDrawer, formRef) {
  return [
    {
      title: "物料（名称+编码）",
      key: "materieId",
      dataIndex: "materieId",
      valueType: "select",
      formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      options: {
        path: "/ngic-workmanship/pmMaterie/query/selectbox",
      },
      fieldProps: {
        onChange: (value, options) => {
          if (value) {
            doFetch({
              url: "/ngic-workmanship/pmMaterie/queryById",
              params: { materieId: value },
            }).then((res) => {
              console.log(res);
              const data = res?.data?.data;
              formRef.current.setFieldValue(
                "specificationModel",
                data?.specificationModel ?? ""
              );
              formRef.current.setFieldValue("shopSign", data?.shopSign ?? "");
              formRef.current.setFieldValue("ironLoss", data?.ironLoss ?? "");
              formRef.current.setFieldValue(
                "sheetThickness",
                data?.sheetThickness ?? ""
              );
            });
          } else {
            formRef?.current?.resetFields();
          }
        },
      },
    },
    {
      title: "规格型号",
      key: "specificationModel",
      dataIndex: "specificationModel",
      fieldProps: {
        disabled: true,
        placeholder: "",
      },
    },
    {
      title: "牌号",
      key: "shopSign",
      dataIndex: "shopSign",
      fieldProps: {
        disabled: true,
        placeholder: "",
      },
    },
    {
      title: "铁损",
      key: "ironLoss",
      dataIndex: "ironLoss",
      fieldProps: {
        disabled: true,
        placeholder: "",
      },
    },
    {
      title: "片厚",
      key: "sheetThickness",
      dataIndex: "sheetThickness",
      fieldProps: {
        disabled: true,
        placeholder: "",
      },
    },
    {
      title: "手动录入",
      key: "split",
      dataIndex: "split",
      valueType: "split",
    },
    {
      title: "供应商",
      key: "supplierId",
      dataIndex: "supplierId",
      valueType: "select",
      options: {
        path: "/ngic-auth/sysSupplier/query/selection",
        params: {},
      },
    },
    {
      title: "单边厚度",
      key: "unilateralThickness",
      dataIndex: "unilateralThickness",
      valueType: "digit",
      fieldProps: {
        precision: 3,
        max: 999999,
      },
    },
    {
      title: "备注",
      key: "remark",
      dataIndex: "remark",
      valueType: "textarea",
    },
    {
      title: (
        <span>
          <b style={{ color: "red" }}>*</b> 列表
        </span>
      ),
      valueType: "formList",
      dataIndex: "list",
      formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      initialValue: [
        {
          state: "all",
          title: "标题",
        },
      ],
      colProps: {
        xs: 24,
        sm: 24,
      },
      columns: [
        {
          title: "数量",
          dataIndex: "weight",
          key: "weight",
          valueType: "digit",
          colProps: {
            sm: 6,
          },
          fieldProps: {
            precision: 3,
            max: 999999,
          },
          formItemProps: {
            rules: [
              {
                required: true,
                message: "此项为必填项",
              },
            ],
          },
        },
        {
          title: "宽度",
          dataIndex: "width",
          key: "width",
          valueType: "digit",
          formItemProps: {
            rules: [
              {
                required: true,
                message: "此项为必填项",
              },
            ],
          },
          fieldProps: {
            mode: "multiple",
            precision: 3,
            max: 999999,
          },

          colProps: {
            sm: 6,
          },
        },
        {
          title: "米数",
          dataIndex: "length",
          key: "length",
          valueType: "digit",
          formItemProps: {
            rules: [
              {
                required: true,
                message: "此项为必填项",
              },
            ],
          },
          fieldProps: {
            precision: 3,
            max: 999999,
          },
          colProps: {
            sm: 6,
          },
        },
        {
          title: "批次号",
          dataIndex: "materieControlNo",
          key: "materieControlNo",
          valueType: "input",
          formItemProps: {
            rules: [
              {
                required: false,
                message: "此项为必填项",
              },
            ],
          },
          fieldProps: {
            placeholder:'不填写则默认生成'
          },
          colProps: {
            sm: 6,
          },
        },
      ],
      search: false,
    },
  ];
}
