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: {
        formatter: (prop) => {
          const { taxPrice = 0 } = prop;
          return taxPrice * 1;
        },
      },
    },
    { 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: {},
    },
    {
      item: { width: 100, key: "status", title: "有效状态" },
      attr: { is: "el-dict-tag", dictName: "price_invalid" },
    },
    {
      item: { width: 100, key: "enableStatus", title: "启用状态" },
      attr: { is: "el-dict-tag", dictName: "price_enable" },
    },
    {
      item: { width: 100, key: "materialStatus", title: "物料启用状态" },
      attr: { is: "el-dict-tag", dictName: "material_enable" },
    },
    {
      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: "createTime", title: "创建时间" }, attr: {} },
    {
      item: { width: 100, key: "updateByName", title: "更新人名称" },
      attr: {},
    },
    {
      item: { width: 100, key: "updateTime", 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",
        clearable: true,
        referName: "ORG_PARAM",
        valueKey: "name",
        dataMapping: {
          puOrg: "id",
          puOrgName: "name",
        },
      },
    },
    {
      item: { width: 100, key: "manufacturerName", title: "生产厂家" },
      attr: {
        is: "el-popover-select-v2",
        clearable: true,
        referName: "MANUFACTURER_PARAM",
        valueKey: "name",
        dataMapping: {
          manufacturer: "id",
          manufacturerName: "name",
        },
      },
    },
    {
      item: { width: 100, key: "supplierName", title: "供应商" },
      attr: {
        is: "el-popover-select-v2",
        clearable: true,
        referName: "SUPPLIER_PARAM",
        valueKey: "name",
        dataMapping: {
          supplier: "id",
          supplierCode: "code",
          supplierName: "name",
        },
      },
    },
    {
      item: { width: 100, key: "applyCode", title: "来源单据" },
      attr: { clearable: true, is: "el-input" },
    },
    {
      item: { key: "materialCodeList", title: "物料编码" },
      attr: {
        clearable: true,
        is: "el-popover-multiple-select-v2",
        valueKey: "code",
        referName: "MATERIAL_PARAM",
      },
    },
    {
      item: { key: "materialCodes", title: "物料编码" },
      attr: {
        clearable: true,
        is: "el-input",
        placeholder: '多物料编码使用 , 隔开',
      },
    },
    // {
    //   item: { width: 100, key: "materialCodeList", title: "物料编码" },
    //   attr: {
    //     is: "el-popover-multiple-select-v2",
    //     referName: "MATERIAL_PARAM",
    //     valueKey: "code",
    //   },
    // },
    {
      item: { key: "materialClassifyList", title: "物料一级分类" },
      attr: {
        clearable: true,
        is: "el-popover-multiple-tree-select",
        referName: "MATERIALCLASSIFY_PARAM",
        valueKey: "code",
      },
    },
    {
      item: { width: 100, key: "source", title: "价格来源" },
      attr: { clearable: true, is: "el-select", dictName: "price_source" },
    },
    {
      item: { width: 100, key: "status", title: "有效状态" },
      attr: { clearable: true, is: "el-select", dictName: "price_invalid" },
    },
    {
      item: { width: 100, key: "enableStatus", title: "启用状态", span: 4 },
      attr: { clearable: true, is: "el-select", dictName: "price_enable" },
    },
    {
      item: { width: 100, key: "createTime", title: "价格日期", span: 8 },
      attr: {
        clearable: true,
        is: "el-date-picker",
        type: "datetimerange",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",
        valueFormat: "yyyy-MM-dd hh:mm:ss",
      },
    },
    {
      item: { width: 100, key: "customerName", title: "客户" },
      attr: {
        is: "el-popover-select-v2",
        referName: "CUSTOMER_PARAM",
        valueKey: "name",
        clearable: true,
        dataMapping: {
          customer: "id",
          customerName: "name",
        },
      }
    },
    {
      item: { width: 100, key: "invalid", title: "价格失效日期", span: 8 },
      attr: {
        clearable: true,
        is: "el-date-picker",
        type: "datetimerange",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",
        valueFormat: "yyyy-MM-dd hh:mm:ss",
      },
    },
  ];
  return { TableColumns, SearchColumns };
}
