import CONFIG from "@/config";

export default function useColumns() {
  const TableColumns = [
    {
      item: { width:100,key: "puOrgName", title: "采购组织" },
      attr: {},
    },
    { item: { width:150,key: "materialName", title: "物料" }, attr: {} },
    { item: { width:150,key: "materialCode", title: "物料编码" }, attr: {} },
    { item: { width:100,key: "materialClassifyName", title: "物料一级分类" }, attr: {} },
    { item: { width:100,key: "manufacturerName", title: "生产厂家名称" }, attr: {} },
    { item: { width:100,key: "model", title: "物料型号" }, attr: {} },
    { item: { width:100,key: "specification", title: "物料规格" }, attr: {} },
    {
      item: { width:100,key: "supplierName", title: "供应商名称" },
      attr: {},
    },
    { item: { width:100,key: "customerName", title: "客户" }, attr: {} },
    {
      item: { width:100,key: "taxPrice", title: "主含税单价" },
      attr: {
        is: "el-computed-input-v2",
        formatter: (prop) => {
          return (prop * 1).toFixed(CONFIG.precision);
        },
      },
    },
    { item: { width:100,key: "unitName", title: "主单位" }, attr: {} },
    { item: { width:100,key: "effectiveDate", title: "价格生效日期" }, attr: {} },
    { item: { width:100,key: "endDate", title: "价格失效日期" }, attr: {} },
    { item: { width:100,key: "buyerName", title: "采购员" }, attr: {} },
    { item: { width:100,key: "applyCode", title: "来源单据" }, attr: {} },
    {
      item: { width:100,key: "convertRate", title: "换算率" },
      attr: {
        is: "el-computed-input-v2",
        formatter: (prop) => {
          return (prop * 1).toFixed(CONFIG.precision);
        },
      },
    },
    {
      item: { width:100,key: "status", title: "有效状态" },
      attr: { is: "el-dict-tag", dictName: "is_effective" },
    },
    {
      item: { width:100,key: "enableStatus", title: "启用状态" },
      attr: { is: "el-dict-tag", dictName: "is_effective" },
    },
    {
      item: { width:100,key: "materialStatus", title: "物料启用状态" },
      attr: { is: "el-dict-tag", dictName: "is_effective" },
    },
    {
      item: { width:100,key: "isDistribution", title: "配送价" },
      attr: { is: "el-dict-tag", dictName: "is_effective" },
    },
    {
      item: { width:100,key: "priceType", title: "价格类型" },
      attr: { is: "el-dict-tag", dictName: "sys_price_type" },
    },
    { item: { width:100,key: "expiryEarly", title: "效期预警" }, attr: {} },
    { item: { width:100,key: "priority", title: "含税/无税优先" }, attr: {} },
    { item: { width:100,key: "createByName", title: "创建人" }, attr: {} },
    { item: { width:100,key: "updateByName", title: "更新人名称" }, attr: {} },
  ].map(({ item, attr }) => ({
    attr,
    item: {
      ...item,
      sortabled: true,
      fixedabled: true,
      filterabled: true,
      hiddenabled: true,
    },
  }));

  const SearchColumns = [
    {
      item: { width:100,key: "puOrgName", title: "采购组织" },
      attr: {
        is: "el-popover-select-v2",
        referName: "ORG_PARAM",
        valuewidth:100,key: "name",
        dataMapping: {
          puOrg: "id",
          puOrgName: "name",
        },
      },
    },
    {
      item: { width:100,key: "manufacturer", title: "生产厂家" },
      attr: { is: "el-input" },
    },
    {
      item: { width:100,key: "supplierName", title: "供应商" },
      attr: {
        is: "el-popover-select-v2",
        referName: "SUPPLIER_PARAM",
        valuewidth:100,key: "name",
        dataMapping: {
          supplier: "id",
          supplierName: "name",
        },
      },
    },
    {
      item: { width:100,key: "applyCode", title: "来源单据" },
      attr: { is: "el-input" },
    },
    {
      item: { width:100,key: "materialCode", title: "物料编码" },
      attr: {
        is: "el-popover-select-v2",
        referName: "MATERIAL_PARAM",
        valuewidth:100,key: "code",
        dataMapping: {
          material: "id",
          materialCode: "code",
        },
      },
    },
    {
      item: { width:100,key: "status", title: "有效状态" },
      attr: { is: "el-select", dictName: "is_effective" },
    },
    {
      item: { width:100,key: "enableStatus", title: "启用状态" },
      attr: { is: "el-select", dictName: "is_effective" },
    },
  ];
  return { TableColumns, SearchColumns };
}
