export default function useColumns() {
  const SearchColumns = [
    {
      item: { key: "rowStatus", title: "行状态", },
      attr: {
        is: "el-select",
        dictName: "sys_row_status",
        multiple: true,
        clearable: true,
        collapseTags: true,
      },
    },
    {
      item: { key: "buyerName", title: "采购员", },
      attr: {
        clearable: true,
        is: "el-popover-select-v2",
        referName: "CONTACTS_PARAM",
        valueKey: "name",
        dataMapping: {
          buyer: "code",
        },
      },
    },
    {
      item: { key: "materialClassifyFour", title: "品类", },
      attr: {
        clearable: true,
        is: "el-popover-multiple-tree-select",
        valueKey: "id",
        referName: "MATERIALCLASSIFY_PARAM",
        defaultProps: {
          label: function (data, node) {
            return data.code + " " + data.name;
          },
          children: "children",
        },
      },
    },
    {
      item: { key: "manufacturer", title: "生产厂家", width: 100, },
      attr: {
        is: "el-input",
        clearable: true,
      },
    },
    {
      item: { key: "puManagerAuditorName", title: "审核人", },
      attr: {
        is: "el-popover-select-v2",
        referName: "CONTACTS_PARAM",
        valueKey: "name",
        dataMapping: {
          puManagerAuditor: "code",
          puManagerAuditorName: "name"
        },
      },
    },
    {
      item: { key: "businessType", title: "业务类型", },
      attr: {
        is: "el-select",
        dictName: "sys_business",
        clearable: true,
      },
    },
    {
      item: { key: "customerName", title: "需求客户", },
      attr: {
        is: "el-popover-select-v2",
        referName: "CUSTOMER_PARAM",
        valueKey: "name",
        dataMapping: {
          customer: "id",
          customerName: "name"
        },
      },
    },
    {
      item: { key: "materialCodeList", title: "物料编码", },
      attr: {
        clearable: true,
        is: "el-input",
        // is: "el-popover-multiple-select-v2",
        // valueKey: "code",
        // referName: "MATERIAL_PARAM",
      },
    },
    {
      item: { key: "purchaseOrgName", title: "默认采购组织", },
      attr: {
        is: "el-popover-select-v2",
        referName: "ORG_PARAM",
        valueKey: "name",
        dataMapping: {
          purchaseOrg: "id",
          purchaseOrgName: "name"
        },
      },
    },
    {
      item: { key: "demandDateArray", title: "需求日期", },
      attr: {
        is: "el-date-picker",
        type: "daterange",
        valueFormat: "yyyy-MM-dd",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",

      },
    },
    {
      item: { key: "code", title: "采购需求单号", },
      attr: {
        is: "el-input",
        clearable: true,
      },
    },
    {
      item: { key: "approverFinishTimeArray", title: "审批结束日期", },
      attr: {
        is: "el-date-picker",
        type: "daterange",
        valueFormat: "yyyy-MM-dd",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",

      },
    },
    {
      item: { key: "isCustomerSpecified", title: "是否客户指定", },
      attr: {
        is: "el-select",
        dictName: "sys_yes_no",
        clearable: true,
      },
    },
    {
      item: { key: "isUrgency", title: "是否紧急需求", },
      attr: {
        is: "el-select",
        dictName: "sys_yes_no",
        clearable: true,
      },
    },
    {
      item: { key: "additionalSupplierName", title: "补单供应商", },
      attr: {
        is: "el-popover-select-v2",
        referName: "SUPPLIER_PARAM",
        valueKey: "name",
        dataMapping: {
          additionalSupplier: "id",
          additionalSupplierName: "name"
        },
      },
    },
    {
      item: { key: "processTimeArray", title: "确认日期", },
      attr: {
        is: "el-date-picker",
        type: "daterange",
        valueFormat: "yyyy-MM-dd",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",

      },
    },
  ];

  const TableColumns = [
    {
      item: { key: "status", title: "行状态", width: 100, },
      attr: {
        is: "el-dict-tag",
        dictName: "sys_row_status",
      },
    },
    {
      item: { key: "finalBuyQty", title: "最终采购量", },
      attr: {
        is: "el-input-number",
        min: 0,
        controlsPosition: "right",
        isSummary: true,
      },
    },
    {
      item: { key: "artificialAdjust", title: "人工调整数", width: 90, },
      attr: {
        isSummary: true,
        formatter: (prop) => {
          return prop.finalBuyQty - prop.suggestionPurchase
        },
      },
    },
    {
      item: { key: "materialClassifyOneName", title: "一级分类名称", width: 120, },
      attr: {},
    },
    {
      item: { key: "materialCode", title: "物料编码", width: 120, },
      attr: {},
    },
    {
      item: { key: "materialName", title: "品名", },
      attr: {},
    },
    {
      item: { key: "specification", title: "规格", },
      attr: {},
    },
    {
      item: { key: "unit", title: "单位", width: 80, },
      attr: {},
    },
    {
      item: { key: "manufacturer", title: "生产厂家/代理人", },
      attr: {},
    },
    {
      item: { key: "demandNum", title: "需求单位量", width: 100, },
      attr: {},
    },
    {
      item: { key: "evensalesforyear", title: "近1月均销量", width: 100, },
      attr: {
        formatter: (prop) => {
          return prop.evensalesforyear ? parseFloat(prop.evensalesforyear).toFixed(2) : "0.00"
        }
      },
    },
    {
      item: { key: "evensalesforthrmonth", title: "近3月均销量", width: 120, },
      attr: {
        formatter: (prop) => {
          return prop.evensalesforthrmonth ? parseFloat(prop.evensalesforthrmonth).toFixed(2) : "0.00"
        }
      },
    },
    // {
    //   item: { key: "", title: "需求客户近1月用量", width: 150, },
    //   attr: {},
    // },
    // {
    //   item: { key: "", title: "需求客户近3月月均用量", width: 150, },
    //   attr: {},
    // },
    {
      item: { key: "netDemandNum", title: "总最终净需求量", width: 120, },
      attr: {
        isSummary: true,
        formatter: (prop) => {
          return prop.netDemandNum ? parseFloat(prop.netDemandNum).toFixed(2) : "0.00";
        }
      },
    },
    {
      item: { key: "totalMonthlySales", title: "总月销量", width: 120, },
      attr: {
        formatter: (prop) => {
          return prop.totalMonthlySales ? parseFloat(prop.totalMonthlySales).toFixed(2) : "0.00";
        }
      },
    },
    {
      item: { key: "demandCycle", title: "需求可用周期", width: 120, },
      attr: {
        formatter: (prop) => {
          return prop.demandCycle ? parseFloat(prop.demandCycle).toFixed(2) : "0.00";
        }
      },
    },
    {
      item: { key: "dullQut", title: "呆滞量", width: 120, },
      attr: {
        formatter: (prop) => {
          // return prop.dullQut ? parseFloat(prop.dullQut).toFixed(2) : "0.00";
          return parseFloat(prop.dullQut).toFixed(2);
        }
      },
    },
    {
      item: { key: "centralPublicStock", title: "中心公共库存", },
      attr: {},
    },
    {
      item: { key: "centralWarehouse", title: "中心仓专属货位", },
      attr: {},
    },
    // {
    //   item: { key: "", title: "客户专属货位库存", },
    //   attr: {},
    // },
    {
      item: { key: "commerceWarehouse", title: "电商仓库", },
      attr: {},
    },
    {
      item: { key: "buyTransit", title: "采购在途", },
      attr: {},
    },
    // {
    //   item: { key: "", title: "近效期库存数量", },
    //   attr: {},
    // },
    {
      item: { key: "lendTransit", title: "借出在途", },
      attr: {},
    },
    {
      item: { key: "transferTransit", title: "调拨在途", },
      attr: {},
    },
    {
      item: { key: "eachWarehouseStock", title: "各项目仓库存", },
      attr: {},
    },
    {
      item: { key: "regionPublicStock", title: "区域分仓公共库存", },
      attr: {},
    },
    {
      item: { key: "stockTotal", title: "库存总计", hidden: false, },
      attr: {},
    },
    {
      item: { key: "buyPeriod", title: "采购周期", width: 120, },
      attr: {},
    },
    {
      item: { key: "minPackage", title: "最小包装量", width: 120, hidden: false, },
      attr: {},
    },
    {
      item: { key: "minOrder", title: "最小订货量", width: 120, },
      attr: {},
    },
    {
      item: { key: "minBatch", title: "最小批量", width: 120, },
      attr: {},
    },
    {
      item: { key: "modifyReason", title: "修改原因", hidden: false, },
      attr: {
        is: "el-input",
      },
    },
    {
      item: { key: "suggestionPurchase", title: "建议净采购量", hidden: false, },
      attr: {},
    },
    {
      item: { key: "closeQty", title: "关闭数量", hidden: false, },
      attr: {},
    },
    {
      item: { key: "materialClassifyTwoName", title: "二级品类", },
      attr: {},
    },
    {
      item: { key: "materialClassifyThreeName", title: "三级品类", },
      attr: {},
    },
    {
      item: { key: "materialClassifyFourName", title: "四级品类", },
      attr: {},
    },
    {
      item: { key: "buyerName", title: "采购员", },
      attr: {
        is: "el-popover-select-v2",
        referName: "CONTACTS_PARAM",
        valueKey: "name",
        dataMapping: {
          buyer: "code",
        },
      },
    },
    {
      item: { key: "purchaseOrgName", title: "默认采购组织名称", },
      attr: {},
    },
    {
      item: { key: "validityPeriod", title: "有效期", hidden: false, width: 120, },
      attr: {},
    },
    {
      item: { key: "validityPeriodUnit", title: "有效期单位", hidden: false, width: 120, },
      attr: {},
    },
    {
      item: { key: "businessType", title: "业务类型", hidden: false, width: 120, },
      attr: {
        is: "el-dict-tag",
        dictName: "sys_business",
      },
    },
    {
      item: { key: "safetyStock", title: "安全库存量", hidden: false, width: 120, },
      attr: {
        formatter: (prop) => {
          return prop.safetyStock ? parseFloat(prop.safetyStock).toFixed(2) : "0.00";
        }
      },
    },
    {
      item: { key: "billSource", title: "单据来源", hidden: false, width: 120, },
      attr: {
        is: "el-dict-tag",
        dictName: "sys_bill_source",
      },
    },
    {
      item: { key: "registrant", title: "注册人", hidden: false, },
      attr: {},
    },
    {
      item: { key: "buyDiscrepancy", title: "总需要与终采差异", },
      attr: {},
    },
    {
      item: { key: "forecastClassification", title: "集团预测分类", hidden: false, },
      attr: {
        is: "el-dict-tag",
        dictName: "predictive_classify",
      },
    },
    {
      item: { key: "centerBinPossession", title: "中心仓占有量", hidden: false, },
      attr: {},
    },
    {
      item: { key: "centralWarehouseAvailable", title: "中心仓可用量", hidden: false, },
      attr: {},
    },
    {
      item: { key: "puManagerAuditor", title: "采购经理审核人", },
      attr: {},
    },
  ].map(({ item, attr }) => ({
    attr,
    item: {
      ...item,
      sortabled: true,
      fixedabled: true,
      filterabled: true,
      hiddenabled: true,
    },
  }));

  return { SearchColumns, TableColumns }
}