import regValue from "@/utils/regValue";
import {
  unitSelect,
  serialNumberRuleSelect,
  processLineSelect,
  bmTableSelect,
} from "@/services/craft";
export default {
  materieCode: {
    value: null,
    type: "input",
    title: "物料编号",
    name: ["materieCode"],
    required: true,
  },
  materieName: {
    value: null,
    type: "input",
    title: "物料名称",
    name: ["materieName"],
    required: true,
  },
  materieType: {
    value: null,
    type: "select",
    title: "物料类别",
    name: ["materieType"],
    required: true,
    options: [
      {
        label: "自制件",
        value: 0,
      },
      {
        label: "采购件",
        value: 1,
      },
      {
        label: "虚拟件",
        value: 2,
      },
    ],
  },
  unitList: {
    value: [],
    title: "生产单位",
    type: "table",
    col: { span: 24 },
    name: ["unitList"],
    required: true,
    columns: [
      {
        title: "主次",
        dataIndex: "index",
        key: "index",
        search: false,
        render: (_, row, index) => {
          return <span>{index == 0 ? "主单位" : `第${index + 1}单位`}</span>;
        },
        editable: false,
        width: 120,
      },
      {
        title: "单位类型",
        dataIndex: "productionUnit",
        key: "productionUnit",
        search: false,
        valueType: "select",
        request: async () => [
          {
            value: 0,
            label: "数量（PCS）",
          },
          {
            value: 1,
            label: "重量",
          },
          {
            value: 2,
            label: "面积",
          },
          {
            value: 3,
            label: "容积",
          },
        ],
      },
      {
        title: "单位",
        dataIndex: "productionUnitType",
        key: "productionUnitType",
        search: false,
        valueType: "select",
        request: async () => {
          let res = await unitSelect({ dicKey: "material_unit" });
          return res?.data?.dataList ?? [];
        },
      },
      {
        title: "操作",
        valueType: "option",
        width: 70,
        render: (text, record, _, action) => [
          <a key="delete" onClick={() => {}}>
            删除
          </a>,
        ],
      },
    ],
    maxLength: 3,
    rowKey: "id",
  },
  enableDualUnits: {
    value: null,
    type: "radio",
    title: "启用双单位",
    name: ["enableDualUnits"],
    required: false,
    options: [
      {
        label: "否",
        value: 0,
      },
      {
        label: "是",
        value: 1,
      },
    ],
    linked: true,
  },
  inventoryUnit: {
    value: null,
    type: "select",
    title: "库存单位",
    name: ["inventoryUnit"],
    required: false,
    belinked: {
      options: {
        database: unitSelect,
        params: { dicKey: "material_unit" },
      },
      hides: [
        {
          name: "enableDualUnits",
          equalvalue: [0, null],
          required: true,
        },
      ],
    },
  },
  unitConversion: {
    value: null,
    title: "单位转换（生产单位=库存单位*系数）",
    type: "inputnumber",
    name: ["unitConversion"],
    required: false,
    ...regValue(null, 6, 3),
    belinked: {
      hides: [
        {
          name: "enableDualUnits",
          equalvalue: [0, null],
          required: true,
        },
      ],
    },
  },
  processLineId: {
    value: null,
    type: "select",
    title: "工艺路线",
    name: ["processLineId"],
    required: false,
    options: {
      database: processLineSelect,
      params: {},
    },
  },
  materialControl: {
    value: null,
    type: "select",
    title: "物料管控",
    name: ["materialControl"],
    required: false,
    options: [
      {
        label: "单品管控",
        value: 0,
      },
      {
        label: "批次管控",
        value: 1,
      },
    ],
    linked: true,
  },
  serialNumberRuleId: {
    value: null,
    type: "select",
    title: "序列号规则",
    name: ["serialNumberRuleId"],
    required: false,
    options: {
      database: serialNumberRuleSelect,
      params: { noTypeCode: "materials_no" },
    },
  },
  labelTemplateId: {
    value: null,
    type: "select",
    title: "标签模板",
    name: ["labelTemplateId"],
    required: false,
    options: {
      database: bmTableSelect,
      params: { tableType: 0 },
    },
  },
  remark: {
    value: null,
    type: "textarea",
    title: "描述",
    name: ["remark"],
    required: false,
    col: { span: 24 },
  },
};
