import CONFIG from "@/config";

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

  const SearchColumns = [
    {
      item: {
        key: "contractName",
        title: "合同名称",
      },
      attr: {
        is: "el-input",
      },
    },
    {
      item: { key: "status", title: "状态" },
      attr: {
        is: "el-select",
        dictName: "documents_status",
      },
    },
    {
      item: {
        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 };
}
