export default function useColumns() {
  const TableColumns = [
    { item: { key: "code", title: "订单生成单号",width :160 }, attr: {} },
    {
      item: { key: "status", title: "状态" ,width :100},
      attr: {
        is: "el-dict-tag",
        dictName: "purchase_task_status",
      },
    },

    {
      item: { key: "existPrice", title: "是否有价格",width :100 },
      attr: { is: "el-dict-tag", dictName: "sys_true_false" },
    },
    { item: { key: "demandCode", title: "需求单号",width :150 }, attr: {} },
    { item: { key: "materialName", title: "物料",width :150 }, attr: {} },
    {
      item: { key: "materialCode", title: "物料编码",width :150 },
      attr: {},
    },
    {
      item: { key: "materialDesc", title: "物料描述",width :100 },
      attr: {},
    },
    {
      item: { key: "manufacturerName", title: "生产厂家" ,width :100},
      attr: {},
    },
    { item: { key: "puQty", title: "采购数量",width :100 }, attr: {} },
    {
      item: { key: "executeQty", title: "已执行数量" ,width :100},
      attr: {},
    },
    {
      item: { key: "residueQty", title: "未执行数量",width :100 },
      attr: {},
    },
    {
      item: { key: "priceType", title: "价格类型" ,width :100},
      attr: { is: "el-dict-tag", dictName: "sys_price_type" },
    },
    { item: { key: "puUnitName", title: "采购单位",width :100 }, attr: {} },
    { item: { key: "buyerName", title: "采购员",width :100 }, attr: {} },
    {
      item: { key: "supplierName", title: "建议供应商",width :100 },
      attr: {},
    },
    { item: { key: "puOrgName", title: "采购组织",width :100 }, attr: {} },
    { item: { key: "currencyName", title: "币种",width :100 }, attr: {} },
    { item: { key: "source", title: "需求单号" ,width :100}, attr: {} },
    {
      item: { key: "customerName", title: "收货客户",width :100 },
      attr: {},
    },
    {
      item: { key: "assignSupplierName", title: "指定供应商" ,width :100},
      attr: {},
    },
    { item: { key: "demandDate", title: "需求时间",width :100 }, attr: {} },
    { item: { key: "projectName", title: "项目名称",width :100 }, attr: {} },
    {
      item: { key: "demandPersonalName", title: "需求人",width :100 },
      attr: {},
    },
    {
      item: { key: "demandOrgName", title: "需求组织" ,width :100},
      attr: {},
    },
    {
      item: { key: "demandDeptName", title: "需求部门",width :100 },
      attr: {},
    },
    {
      item: { key: "isBack", title: "是否退回",width :100 },
      attr: { is: "el-dict-tag", dictName: "sys_yes_no" ,width :100},
    },
    { item: { key: "baskCause", title: "退回原因" ,width :100}, attr: {} },
    { item: { key: "backDate", title: "退回日期",width :100 }, attr: {} },
    { item: { key: "unitName", title: "单位" ,width :100}, attr: {} },
  ].map(({ item, attr }) => ({
    attr,
    item: {
      ...item,
      sortabled: true,
      fixedabled: true,
      filterabled: true,
      hiddenabled: true,
    },
  }));

  const SearchColumns = [
    {
      item: {
        key: "classIds",
        title: "物料分类",
      },
      attr: {
        is: "el-popover-multiple-tree-select",
        referName: "MATERIALCLASSIFY_PARAM",
        valueKey: "id",
      },
    },
    {
      item: {
        key: "materialCodes",
        title: "物料编码",
      },
      attr: {
        is: "el-popover-multiple-select-v2",
        valueKey: "code",
        referName: "MATERIAL_PARAM",
      },
    },
    {
      item: {
        key: "materialDesc",
        title: "物料描述",
      },
      attr: {
        is: "el-input",
      },
    },
    {
      item: {
        key: "code",
        title: "单据号",
      },
      attr: {
        is: "el-input",
      },
    },
    {
      item: {
        key: "puOrgIds",
        title: "采购组织",
      },
      attr: {
        is: "el-popover-multiple-select-v2",
        referName: "ORG_PARAM",
        valueKey: "id",
      },
    },
    {
      item: {
        key: "status",
        title: "状态",
      },
      attr: {
        is: "el-select",
        dictName: "purchase_task_status",
        clearable: true,
      },
    },
    {
      item: {
        key: "date",
        title: "创建时间",
      },
      attr: {
        is: "el-date-picker",
        type: "daterange",
        unlinkPanels: true,
        rangeSeparator: "至",
        valueFormat: "yyyy-MM-dd",
        endPlaceholder: "结束日期",
        startPlaceholder: "开始日期",
        pickerOptions: pickerOptions,
        value: [],
      },
    },
    {
      item: {
        key: "buyers",
        title: "采购员",
      },
      attr: {
        is: "el-popover-multiple-select-v2",
        referName: "CONTACTS_PARAM",
        valueKey: "code",
      },
    },
    {
      item: {
        key: "manufacturerName",
        title: "生产厂家",
      },
      attr: {
        is: "el-input",
      },
    },
    {
      item: {
        key: "customerName",
        title: "收货客户",
      },
      attr: {
        is: "el-popover-select-v2",
        referName: "CUSTOMERDEPT_PARAM",
        valueKey: "name",
      },
    },
    {
      item: {
        key: "documentsCodes",
        title: "采购需求单号",
        span: 12,
      },
      attr: {
        is: "el-input",
        placeholder: "请输入来源单据号，多个用,分隔",
      },
    },
    {
      item: {
        key: "materialCodes",
        title: "物料编码",
        span: 12,
      },
      attr: {
        is: "el-input",
        placeholder: "请输入物料编码，多个用,分隔",
      },
    },
  ].map(({ item, attr }) => ({
    attr,
    item: { ...item, hidden: true, span: item.span || 6 },
  }));

  const pickerOptions = {
    shortcuts: [
      {
        text: "昨天",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近三天",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近一周",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近一个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近三个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近半年",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
          picker.$emit("pick", [start, end]);
        },
      },
    ],
  };

  return { TableColumns, SearchColumns };
}
