import CONFIG from "@/config";

export default function useColumns() {
  const TableColumns = [
    { item: { width: 100, key: "puOrgName", title: "采购组织" }, attr: {} },
    { item: { width: 100, key: "code", title: "合同编码" }, attr: {} },
    {
      item: { width: 100, key: "status", title: "状态" },
      attr: { is: "el-dict-tag", dictName: "documents_status" },
    },
    {
      item: { width: 100, key: "lastPuMoney", title: "年度采购额" },
      attr: {
        formatter: (prop) => {
          const { lastPuMoney = 0 } = prop;
          return (lastPuMoney * 1);
        },
      },
    },
    { item: { width: 100, key: "buyerName", title: "采购员" }, attr: {} },
    { item: { width: 100, key: "supplierName", title: "供应商" }, attr: {} },
    {
      item: { width: 100, key: "contractType", title: "合同类型" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_contract_type",
      },
    },
    {
      item: { width: 100, key: "puMoneyYear", title: "合同总金额" },
      attr: {
        formatter: (prop) => {
          const { puMoneyYear = 0 } = prop;
          return (puMoneyYear * 1);
        },
      },
    },
    { item: { width: 100, key: "puDeptName", title: "采购部门" }, attr: {} },
    {
      item: { width: 100, key: "supplierTier", title: "供应商层级" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_supplier_tier",
      },
    },
    {
      item: { width: 100, key: "contractName", title: "合同名称" },
      attr: {},
    },
    {
      item: { width: 100, key: "grossRateAverage", title: "平均毛利率 (%)" },
      attr: {
        is: "el-computed-input-v2",
        formatter: (prop) => {
          const { grossRateAverage = 0 } = prop;
          return (grossRateAverage * 1).toFixed(2);
        },
      },
    },
    {
      item: { width: 100, key: "approveFlow", title: "审批流程" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_approve_flow",
      },
    },
    {
      item: { width: 100, key: "consumableClass", title: "耗材类别" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_consumable_class",
      },
    },
    {
      item: { width: 100, key: "effectiveDate", title: "合同生效日期" },
      attr: {},
    },
    {
      item: {
        width: 100,
        key: "brandGrossRate",
        title: "同类品牌及毛利率 (%)",
      },
      attr: {
        formatter: (prop) => {
          const { brandGrossRate = 2 } = prop;
          return (brandGrossRate * 1).toFixed(2);
        },
      },
    },
    {
      item: { width: 100, key: "contractFormat", title: "合同格式" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_contract_format",
      },
    },
    {
      item: { width: 100, key: "productName", title: "产品类别&名称" },
      attr: {},
    },
    { item: { width: 100, key: "endDate", title: "合同终止日期" }, attr: {} },
    {
      item: { width: 100, key: "invoiceTax", title: "发票税率 (%)" },
      attr: {
        formatter: (prop) => {
          const { invoiceTax } = prop;
          return (invoiceTax * 1).toFixed(2);
        },
      },
    },
    {
      item: { width: 100, key: "emergencyDegree", title: "紧急程度" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_emergency_degree",
      },
    },
    { item: { width: 100, key: "project", title: "项目医院" }, attr: {} },
    {
      item: { width: 100, key: "deliveryType", title: "交货方式" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_delivery_type",
      },
    },
    { item: { width: 100, key: "source", title: "合同来源" }, attr: {} },
    {
      item: { width: 100, key: "contractPartycName", title: "合同丙方" },
      attr: {},
    },
    {
      item: { width: 100, key: "guaranteePeriodEnd", title: "质保期限" },
      attr: {},
    },
    {
      item: { width: 100, key: "freightMethods", title: "运费承担方式" },
      attr: {
        is: "el-dict-tag",
        dictName: "puarchase_contract_freight_methods",
      },
    },
    {
      item: { width: 100, key: "createTime", title: "合同创建时间" },
      attr: {},
    },
    {
      item: { width: 100, key: "isTarget", title: "是否有指标" },
      attr: { is: "el-dict-tag", dictName: "sys_yes_no" },
    },
    {
      item: { width: 100, key: "contractTarget", title: "合同指标" },
      attr: {},
    },
    {
      item: { width: 100, key: "exemptionPostageCondtion", title: "包邮条件" },
      attr: {},
    },
    {
      item: { width: 100, key: "isRebate", title: "是否有返利" },
      attr: { is: "el-dict-tag", dictName: "sys_yes_no" },
    },
    {
      item: { width: 100, key: "rebatePolicy", title: "返利政策" },
      attr: {},
    },
    {
      item: { width: 100, key: "externalContract", title: "外部合同号" },
      attr: {},
    },
    {
      item: { width: 100, key: "rollbackPolicy", title: "退换货政策" },
      attr: {},
    },
    { item: { width: 100, key: "enquiryCode", title: "询价单号" }, attr: {} },
    {
      item: { width: 100, key: "contractContent", title: "合同主要内容" },
      attr: {},
    },
    {
      item: { width: 100, key: "refusalReasons", title: "拒绝理由" },
      attr: {},
    },
    {
      item: { width: 100, key: "pigeonhole", title: "是否归档" },
      attr: { is: "el-dict-tag", dictName: "sys_yes_no" },
    },
    {
      item: {
        width: 100,
        key: "pigeonholeFile",
        title: "归档附件",
        filterabled: false,
      },
      attr: { is: "el-file-preview" },
    },
    {
      item: {
        width: 100,
        key: "externalFile",
        title: "对外附件",
        filterabled: false,
      },
      attr: { is: "el-file-preview" },
    },
    {
      item: {
        width: 100,
        key: "puFile",
        title: "盖章合同附件",
        filterabled: false,
      },
      attr: { is: "el-file-preview" },
    },
    {
      item: {
        width: 100,
        key: "supplierFile",
        title: "供应商盖章合同附件",
        filterabled: false,
      },
      attr: { is: "el-file-preview" },
    },
    { item: { width: 100, key: "projectCode", title: "项目编号" }, attr: {} },
    { item: { width: 100, key: "projectName", title: "项目名称" }, attr: {} },
    { item: { width: 100, key: "area", title: "区域" }, attr: {} },
    {
      item: { width: 100, key: "consigneePhone", title: "收货人联系方式" },
      attr: {},
    },
    {
      item: { width: 100, key: "paymentAgreement", title: "付款协议" },
      attr: {},
    },
    {
      item: { width: 100, key: "taxPrice", title: "价税合计" },
      attr: {
        formatter: (prop) => {
          const { taxPrice = 0 } = prop;
          return (taxPrice * 1);
        },
      },
    },
    { item: { width: 100, key: "currencyName", title: "币种" }, attr: {} },
    {
      item: { width: 100, key: "guaranteePeriod", title: "质保期" },
      attr: {},
    },
  ].map(({ item, attr }) => ({
    attr,
    item: {
      sortabled: true,
      fixedabled: true,
      filterabled: true,
      hiddenabled: true,
      ...item,
    },
  }));

  const SearchColumns = [
    {
      item: {
        width: 100,
        key: "contractName",
        title: "合同名称",
      },
      attr: {
        is: "el-input",
        clearable: true,
      },
    },
   
    {
      item: { key: "buyerName", title: "采购员", width: 100 },
      attr: {
        is: "el-popover-select-v2",
        clearable: true,
        valueKey: "name",
        referName: "CONTACTS_PARAM",
        dataMapping: {
          buyer: "code",
          buyerName: "name",
        },
      },
    },
    {
      item: { 
        key: "puOrgName", 
        title: "采购组织", 
      },
      attr: {
        is: "el-popover-select-v2",
        clearable: true,
        valueKey: "name",
        referName: "ORG_PARAM",
        dataMapping: {
          puOrg: "code",
          puOrgName: "name",
        },
      },
    },
    {
      item:{
        key: "materialName",
        title: "物料名称",  
      },
      attr:{
        clearable:true,
        is: "el-popover-select-v2",
        valueKey: "name",
        referName: "MATERIAL_PARAM",
        // dataMapping: {
        //   material: "code",
        // }
      },
    },
    
    {
      item: { width: 100, key: "contractType", title: "合同类型" },
      attr: {
        is: "el-select",
        dictName: "puarchase_contract_contract_type",
        clearable: true,
      },
    },
    {
      item: { width: 100, key: "approveFlow", title: "审批流程" },
      attr: {
        is: "el-select",
        dictName: "puarchase_contract_approve_flow",
        clearable: true,
      },
    },
    {
      item: { width: 100, key: "code", title: "合同编码" },
      attr: {
        is: "el-input",
        clearable: true,
      },
    },
    {
      item: {
        key: "supplierName",
        title: "供应商",
      },
      attr: {
        is: "el-popover-select-v2",
        clearable: true,
        valueKey: "name",
        referName: "SUPPLIER_PARAM",
        dataMapping: {
          supplier: "code",
          supplierName: "name",
        },
      },
    },
    {
      item:{
        key: "beginAndEndTimeList",
        title: "合同创建日期",
        span:12,
      },
      attr: {
        clearable:true,
        is: "el-date-wrapper",
      },
    },






    {
      item: { width: 100, key: "status", title: "状态" },
      attr: {
        is: "el-select",
        dictName: "documents_status",
        clearable: true,
      },
    },
    {
      item: {
        width: 100,
        key: "pigeonhole",
        title: "是否归档",
      },
      attr: {
        is: "el-select",
        dictName: "sys_yes_no",
      },
    },
  ].map(({ item, attr }) => ({
    attr,
    item: { ...item, hidden: true, span: item.span || 6 },
  }));

  return { TableColumns, SearchColumns };
}
