// 年度销售目标填报
export default function useColumns() {
  const SearchColumns = [
    {
      item: { key: "code", title: "编码" },
      attr: {
        is: "el-input",
        placeholder: "请输入编码",
        clearable: true,
      }
    },
    {
      item: { key: "goalName", title: "目标名称" },
      attr: {
        is: "el-input",
        placeholder: "请输入年度销售目标名称",
        clearable: true,
      }
    },
    {
      item: { key: "documentDateRange", title: "单据日期" },
      attr: {
        is: "el-date-picker",
        type: "daterange",
        valueFormat: "yyyy-MM-dd",
        align: "right",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",
        placeholder: "请选择单据日期",
        pickerOptions: pickerOptions,
      }
    },
    {
      item: { key: "annual", title: "年度" },
      attr: {
        is: "el-date-picker",
        type: "year",
        valueFormat: "yyyy",
        placeholder: "选择年度",
        clearable: true,
      }
    },
    {
      item: { key: "custom", title: "客户" },
      attr: {
        is: "el-popover-select-v2",
        valueKey: "name",
        referName: "CUSTOMER_PARAM",
        dataMapping: {
          customCode: 'code',
        },
        placeholder: "请输入客户",
      }
    },
    {
      item: { key: "saleZone", title: "销售区域" },
      attr: {
        is: "el-popover-select-v2",
        valueKey: "name",
        referName: "MK_SALESAREA_PARAM",
        dataMapping: {
          saleZoneCode: 'code',
        },
        placeholder: "请输入销售区域",
      }
    },
    {
      item: { key: "creator", title: "制单人" },
      attr: {
        is: "el-popover-select-v2",
        valueKey: "name",
        referName: "CONTACTS_PARAM",
        dataMapping: {
          creatorCode: 'code',
        },
        placeholder: "请输入制单人",
      }
    },
    {
      item: { key: "dept", title: "部门" },
      attr: {
        is: "el-popover-select-v2",
        valueKey: "name",
        referName: "DEPT_PARAM",
        dataMapping: {
          deptId: 'id',
        },
        placeholder: "请输入部门",
      }
    },
    {
      item: { key: "status", title: "单据状态" },
      attr: {
        is: "el-select",
        dictName: "sys_status",
        clearable: true,
      }
    },
  ];

  const TableColumns = [
    {
      item: { key: "status", title: "状态", width: 100, },
      attr: {
        is: "el-dict-tag",
        dictName: "sys_status",
      }
    },
    {
      item: { key: "code", title: "编码", },
      attr: {}
    },
    {
      item: { key: "goalName", title: "目标名称", },
      attr: {}
    },
    {
      item: { key: "documentDate", title: "单据日期", width: 100, },
      attr: {}
    },
    {
      item: { key: "annual", title: "年度", width: 100, },
      attr: {}
    },
    {
      item: { key: "custom", title: "客户", },
      attr: {}
    },
    {
      item: { key: "saleZone", title: "销售区域", },
      attr: {}
    },
    {
      item: { key: "creator", title: "制单人", width: 100, },
      attr: {}
    },
    {
      item: { key: "dept", title: "部门", },
      attr: {}
    },
    {
      item: { key: "goalTotal", title: "目标合计（元）", },
      attr: {
        formatter: (prop) => {
          return prop.goalTotal ? (prop.goalTotal * 1).toFixed(2) : prop.goalTotal;
        },
      }
    },
    {
      item: { key: "notes", title: "备注", },
      attr: {}
    },

  ].map(({ item, attr }) => ({
    attr,
    item: {
      ...item,
      sortabled: true,
      fixedabled: true,
      filterabled: true,
      hiddenabled: true,
    },
  }));

  const pickerOptions = {
    shortcuts: [
      {
        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]);
        },
      },
    ],
  }
  return { SearchColumns, TableColumns }
}