import {
  initPage,
  initParams,
  initColumns,
  initDicts,
} from "@/utils/init";

export const TableColumns = [
  // { key: "id", title: "主键" },
  // { key: "puOrg", title: "采购组织" },
  { key: "puOrgName", title: "采购组织", inputType: "Input" },
  {
    key: "billType",
    title: "订单类型",
    inputType: "Select",
    referName: "sys_order_type",
  },
  { key: "code", title: "订单编号",  inputType: "Input" },
  {
    key: "status",
    title: "单据状态",
    inputType: "Select",
    width:80,
    referName: "documents_status", // 字典名
  },
  { key: "billDate", title: "订单日期" },
  // { key: "supplier", title: "供应商" },
  { key: "supplierName", title: "供应商", inputType: "Input" },
  { key: "paymentAgreementName", title: "付款协议" },
  {
    key: "source",
    title: "订单来源",  
    inputType: "Select",
    referName: "order_source", // 字典名
    width:80,
  },
  // { key: "paymentAgreement", title: "付款协议" },
  
  // { key: "buyer", title: "采购员" },ut
  { key: "buyerName", title: "采购员" },
  // { key: "puDept", title: "采购部门" },
  { key: "puDeptName", title: "采购部门" },
  // { key: "customer", title: "收货客户" },
  { key: "customerName", title: "收货客户" },
  { 
    key: "isDeliver", 
    title: "是否发货",
    inputType: 'Checkbox',
   },
  {
    key: "isArrival",
    title: "到货超期",
    inputType: 'Checkbox',
    width:80,
  },
  {
    key: "isBack",
    title: "退货",
    inputType: 'Checkbox',
    width:80,
  },
  // { key: "freezeCause", title: "冻结原因" },
  { key: "qty", title: "总数量" },
  { key: "money", title: "总数量" },
  {
    key: "isMarketing",
    title: "已协同生成销售订单",
    inputType: 'Checkbox',
  },
  {
    key: "isMarketingSource",
    title: "由销售订单协同生成",
    inputType: 'Checkbox',
  },
  // { key: "personal", title: "人员" },
  { key: "personalName", title: "人员" },
  // { key: "isSendSrm", title: "是否同步SRM" },
  {
    key: "isInvoice",
    title: "发票标识",
    inputType: 'Checkbox',
    width:80,
  },
  { key: "rebateMoney", title: "订单使用返利金额" },
  { key: "deductionMoney", title: "订单抵扣余款金额" },
  // { key: "warehouse", title: "WMS入库仓库" },
  { key: "warehouseName", title: "收货仓库" }, //WMS入库仓库名称
  // { key: "goodsAllocation", title: "货位" },
  { key: "goodsAllocationName", title: "货位" },
  // { key: "customerDept", title: "客户部门" },
  { key: "customerDeptName", title: "客户部门" },
  // { key: "supplierContacts", title: "供应商业务联系人" },
  { key: "supplierContactsName", title: "供应商业务联系人" },
  {
    key: "isUrgency",
    title: "紧急程度",
    inputType: 'Checkbox',
    width:80,
  },
  // { key: "agent", title: "代理人" }, // 建议删除
  { key: "agentName", title: "代理人" },
  {
    key: "isClose",
    title: "最终关闭",
    inputType: 'Checkbox',
    width:80,
  },
  { key: "applyPaymentMoney", title: "累计付款申请金额" },
  { key: "paymentMoney", title: "累计付款金额" },
  { key: "invoiceMoney", title: "发票金额" },
  // { key: "supplierPersonal", title: "供应商业务员" },
  { key: "supplierPersonalName", title: "供应商业务员" },
  { key: "marketingCode", title: "销售订单号" },
  // { key: "tenantId", title: "租户号" },
  // { key: "revision", title: "乐观锁" },
  { key: "createByName", title: "创建人" },
  { key: "updateByName", title: "更新人" },
  // { key: "delFlag", title: "删除标记" },
  { key: "flowId", title: "OA流程ID" },
  { key: "approver", title: "审批人" },
  { key: "approverFinishTime", title: "审批时间" },
  { key: "approveTime", title: "提交时间" },
  { key: "createTime", title: "制单日期/创建时间" },
  { key: "remark", title: "备注" },
  { key: "updateTime", title: "最后修改时间" },

  { key: "oaDemandNo", title: "OA需求单号" },
  { key: "address", title: "收货地址" },
  { key: "contacts", title: "收获联系人" },
  {
    key: "isSendWms",
    title: "已同步WMS",
    inputType: 'Checkbox',
    width:120,
  },
  { key: "retReasonName", title: "退换原因" },
  { key: "closeTime", title: "最终关闭日期" },
  { key: "processTypeName", title: "处理方式" },
  { key: "isEnd", title: "整单关闭标识" },
  { key: "projectNowName", title: "在建工程项目" },
  { key: "operatingItemsName", title: "经营性项目" },
  { key: "isArrivalReson", title: "到货超期原因" },
  { key: "midOrderNo", title: "中台采购订单号" },
];

export const TabColumns = [
  {
    title: '物料信息',
    key: 'puOrderItemList',
    tableColumns: [
      { key: "rowNo", title: "行号" },
      // { key: "orderId", title: "采购订单ID" },
      { key: "material", title: "物料" },
      { key: "materialName", title: "物料名称", width: 180 },
      { key: "materialCode", title: "物料编码", width: 180 },
      { key: "materialClassify", title: "物料分类", width: 180 },
      { key: "materialManufacturersCode", title: "厂家物料编码", width: 180 },
      { key: "specification", title: "规格", width: 180 },
      { key: "model", title: "型号", width: 180 },
      {
        key: "isMedcine",
        title: "医药物料",
        inputType: 'Checkbox',
        width:80,
      },
      { key: "manufacturerName", title: "生产厂家代理人", width: 180 },
      { 
        key: "isDrug", 
        title: "物料药品属性",
        inputType: 'Checkbox',
        width:80, 
      },
      { key: "unitName", title: "单位", width: 180 },
      { key: "qty", title: "数量" },
      // { key: "currency", title: "币种" },
      // { key: "currencyName", title: "币种" },
      { key: "taxPrice", title: "含税单价" },
      { key: "money", title: "价税合计" },
      { key: "tax", title: "税率" },
      { key: "taxDeductMoneya", title: "折扣金额" },
      { key: "arrivalQty", title: "已到货数量" },
      { key: "unarrivedQty", title: "未到货数量" },
      { key: "notaxMoney", title: "无税金额" },
      { key: "priceSource", title: "价格目录ID" },
      {
        key: "isStorage",
        title: "入库关闭",
        inputType: 'Checkbox',
        width:80,
      },
      {
        key: "isInvoice",
        title: "开票关闭",
        inputType: 'Checkbox',
        width:80,
      },
      {
        key: "isArrival",
        title: "到货关闭",
        inputType: 'Checkbox',
        width:80,
      },
      {
        key: "isPayment",
        title: "付款关闭",
        inputType: 'Checkbox',
        width:80,
      },
      {
        key: "isGift",
        title: "赠品",
        inputType: 'Checkbox',
        width:80,
      },
      { key: "warehouse", title: "收货仓库", width: 180 },
      { key: "place", title: "收货地点", width: 180 },
      { key: "address", title: "收货地址", width: 180 },
      { key: "productBatch", title: "产品批号", width: 180 },
      { key: "manufactureDate", title: "生产日期", width: 180 },
      { key: "efficacyLoseDate", title: "有效期至/失效日期", width: 180 },
      { key: "approvalNumber", title: "批准文号", width: 180 },
      { key: "registration", title: "注册证号", width: 180 },
      {
        key: "storageCondition",
        title: "存储条件",
        inputType: "Select",
        referName: "sys_storage_condition", // 字典名
      },
      {
        key: "carriageCondition",
        title: "运输条件",
        inputType: "Select",
        referName: "sys_conditions_carriage", // 字典名
      },
      {
        key: "isBatchLock",
        title: "批号锁定标识",
        inputType: 'Checkbox',
        width:80,
      },
      {
        key: "isReplenishment",
        title: "补单标识",
        inputType: 'Checkbox',
        width:80,
      },
      { key: "isUrgency", title: "紧急标识" },
      { key: "originalQty", title: "原始数量" },
      { key: "originalMoney", title: "原始金额" },
      { key: "directProductBatch", title: "直运产品批号", width: 180 },
      { key: "discountRule", title: "折扣规则编码", width: 180 },
      { key: "reservedQty", title: "预留数量" },
      { key: "reservedPeriod", title: "预留周期", width: 180 },
      { key: "taxDeductClassify", title: "扣税类别" },
      { key: "exchangeRate", title: "折本汇率" },
      { key: "source", title: "上游单据号", width: 180 },
      { key: "sourceId", title: "上游单据ID", width: 180 },
      { key: "demandCode", title: "采购需求单号", width: 180 },
      { key: "arrivalDatePlan", title: "计划到货日期", width: 180 },
      {
        key: "priceType",
        title: "价格类型",
        inputType: "Select",
        referName: "sys_price_type", // 字典名
      },
      { 
        key: "isDistributionPrice", 
        title: "配送价",
        inputType: 'Checkbox',
        width:80,
       },
      // { key: "tenantId", title: "租户号" },
      // { key: "revision", title: "乐观锁" },
      { key: "createByName", title: "创建人" },
      { key: "updateByName", title: "更新人" },
      // { key: "delFlag", title: "删除标记" },
      // { key: "materialClassifyOne", title: "物料一级分类" },
      { key: "materialClassifyOneName", title: "物料一级分类", width: 180 },
      // { key: "materialClassifyTwo", title: "物料二级分类" },
      { key: "materialClassifyTwoName", title: "物料二级分类", width: 180 },
      // { key: "materialClassifyThree", title: "物料三级分类" },
      { key: "materialClassifyThreeName", title: "物料三级分类", width: 180 },
      // { key: "materialClassifyFour", title: "物料四级分类" },
      { key: "materialClassifyFourName", title: "物料四级分类", width: 180 },
      { key: "price", title: "无税单价" }
    ]
  },
  {
    title: '执行结果',
    key: 'puOrderExecuteList',
    tableColumns: [
      // { key: "id", title: "主键" },
      // { key: "orderId", title: "采购订单ID", width: 180 },
      { key: "rowno", title: "行号" },
      { key: "material", title: "物料", width: 180 },
      { key: "materialName", title: "物料名称", width: 180 },
      { key: "specification", title: "规格" },
      { key: "qty", title: "数量" },
      { key: "stroageQty", title: "累计到货主数量" },
      { key: "stockQty", title: "累计入库主数量" },
      { key: "invoiceQty", title: "累计开票主数量" },
      { key: "rollbackQty", title: "累计退货主数量" },
      { key: "backStockQty", title: "累计退库主数量" },
      { key: "floatQty", title: "未到货数量" },
      // { key: "tenantId", title: "租户号" },
      // { key: "revision", title: "乐观锁" },
      { key: "createByName", title: "创建人名称", width: 180 },
      { key: "updateByName", title: "更新人名称", width: 180 },
      // { key: "delFlag", title: "删除标记" }
    ]
  },
];

// export const SearchColumns = TableColumns.filter((element) => element.search);
export const SearchColumns = [
  {
    key: "source",
    title: "订单来源",  
    inputType: "Select",
    referName: "order_source", // 字典名
    clearable:true,
  },
  {
    key: "code",
    title: "订单编号",  
    inputType: "Input",
    clearable:true,
  },
  {
    key: "date",
    title: "订单日期",  
    type: "daterange",
    inputType: "DatePicker",
    unlinkPanels: true,
    rangeSeparator: "至",
    valueFormat: "yyyy-MM-dd",
    endPlaceholder: "结束日期",
    startPlaceholder: "开始日期",
    clearable:true,
  },
  {
    key: "status",
    title: "单据状态",
    inputType: "Select",
    referName: "documents_status", // 字典名
    clearable:true,
  },
  { 
    key: "supplierName", 
    title: "供应商", 
    inputType: "PopoverSelect",
    valueKey: "id",
    referName: "SUPPLIER_PARAM",
    dataMapping: {
      // supplier: "id",
      supplierName: "name",
    },
    queryParams: () => ({}),
    clearable:true,
  },
  {
    key: "puOrgIds",
    title: "采购组织",
    inputType: "PopoverSelect",
    multiple:true,
    valueKey: "id",
    referName: "ORG_PARAM",
    dataMapping: {},
    queryParams: () => ({}),
    clearable:true,
  },
  {
    key: "materialCode",
    title: "物料编码",
    inputType: "PopoverSelect",
    valueKey: "code",
    referName: "MATERIAL_PARAM",
    dataMapping: {},
    queryParams: () => ({}),
    clearable:true,
  },
  {
    key: "materialName",
    title: "物料名称",
    inputType: "PopoverSelect",
    valueKey: "name",
    referName: "MATERIAL_PARAM",
    dataMapping: {},
    queryParams: () => ({}),
    clearable:true,
  },
  { 
    key: "deliveryStatus",
    title: "erp发送状态", 
    inputType: "Select",
    referName: "order_delivery_status", // 字典名
    clearable:true,
  },
  { 
    key: "contractNo",
    title: "合同号", 
    inputType: "Input",
    clearable:true,
  },
  {
    key: "projectNowName",
    title: "在建工程项目",
    inputType: "PopoverSelect",
    require: true,
    valueKey: "name",
    referName: "PROJECT_PARAM",
    dataMapping: {},
    queryParams: () => ({}),
    clearable:true,
  },
  {
    key: "buyers",
    title: "采购员",
    inputType: "PopoverSelect",
    multiple:true,
    valueKey: "code",
    referName: "CONTACTS_PARAM",
    dataMapping: {},
    queryParams: () => ({}),
    clearable:true,
  },
  {
    key: "billTypes",
    title: "订单类型",
    inputType: "Select",
    referName: "sys_order_type", // 字典名
    multiple:true,
    tags:true,
    clearable:true,
  },
  { 
    key: "demandCode",
    title: "采购需求单号", 
    inputType: "Input",
    clearable:true,
  },
  { 
    key: "isDrug",
    title: "物料药品属性", 
    inputType: "SelectCheck",
    clearable:true,
  },
];

const NewColumns = initColumns(TableColumns);
const NewSearchColumns = initColumns(SearchColumns);
const NewTabColumns = TabColumns.map((element) => ({
  ...element,
  tableColumns: initColumns(element.tableColumns),
}));
// 
export const SelectColumns = NewColumns.filter(column => column.inputType === 'Select')

NewTabColumns.forEach(column => {
  SelectColumns.push(...column.tableColumns.filter(cColumn => cColumn.inputType === 'Select'))
});

SelectColumns.push(...NewSearchColumns.filter(column => column.inputType === 'Select'))
