import { CUSTOMER_TYPE, FLOW_STATUS } from '@/config/constants';
import { dictToOptionList } from '@/utils/tool';

const fieldCodes = [
  'NUMBER',
  'DATE',
  'TEXT',
  'SINGLE_SELECT',
  'MULTIPLE_SELECT',
  'CHECKBOX',
  'TEXTAREA',
  'TABLE',
  'RADIO',
  'FILE',
  'DEVICE_IN_TABLE',
];

export const operatorConfig = [
  {
    label: '等于',
    value: 'EQ',
    range: [
      'NUMBER',
      'TEXT',
      'SINGLE_SELECT',
      'MULTIPLE_SELECT',
      'CHECKBOX',
      'RADIO',
    ],
  },
  {
    label: '不等于',
    value: 'NE',
    range: [
      'NUMBER',
      'TEXT',
      'SINGLE_SELECT',
      'MULTIPLE_SELECT',
      'CHECKBOX',
      'RADIO',
    ],
  },
  {
    label: '大于',
    value: 'GT',
    range: ['NUMBER', 'DATE'],
  },
  {
    label: '小于',
    value: 'LT',
    range: ['NUMBER', 'DATE'],
  },
  {
    label: '大于等于',
    value: 'GE',
    range: ['NUMBER', 'DATE'],
  },
  {
    label: '小于等于',
    value: 'LE',
    range: ['NUMBER', 'DATE'],
  },
  {
    label: '选择范围',
    value: 'RANGE',
    range: ['DATE'],
  },
  {
    label: '模糊查询',
    value: 'LIKE',
    range: ['TEXT', 'TEXTAREA'],
  },
];

export const staticMetadata = [
  {
    code: 'TEXT',
    fieldId: 'serviceName',
    fieldTitle: '服务单元',
  },
  {
    code: 'TEXT',
    fieldId: 'sopNo',
    fieldTitle: 'SOP流水号',
  },
  {
    code: 'TEXT',
    fieldId: 'crmNo',
    fieldTitle: '项目单号',
  },
  {
    code: 'DATE',
    fieldId: 'beginTime',
    fieldTitle: '派单时间',
  },
  {
    code: 'TEXT',
    fieldId: 'customManagerName',
    fieldTitle: '客户经理',
  },
  {
    code: 'SINGLE_SELECT',
    fieldId: 'customManagerType',
    fieldTitle: '客户类型',
    options: dictToOptionList(CUSTOMER_TYPE),
  },
  {
    code: 'TEXT',
    fieldId: 'customName',
    fieldTitle: '客户名称',
  },
  {
    code: 'TEXT',
    fieldId: 'crmName',
    fieldTitle: '项目名称',
  },
  {
    code: 'TEXT',
    fieldId: 'productName',
    fieldTitle: '实施产品',
  },
  {
    code: 'TEXT',
    fieldId: 'serviceName',
    fieldTitle: '服务单元',
  },
  {
    code: 'DATE',
    fieldId: 'examStartTime',
    fieldTitle: '考试开始时间',
  },
  {
    code: 'DATE',
    fieldId: 'examEndTime',
    fieldTitle: '考试结束时间',
  },
  {
    code: 'TEXT',
    fieldId: 'flowCreateName',
    fieldTitle: '提交人',
  },
  {
    code: 'DATE',
    fieldId: 'flowCreateTime',
    fieldTitle: '提交时间',
  },
  {
    code: 'DATE',
    fieldId: 'flowUpdateTime',
    fieldTitle: '更新时间',
  },
  {
    code: 'SINGLE_SELECT',
    fieldId: 'status',
    fieldTitle: '流程状态',
    // options: dictToOptionList(FLOW_STATUS).filter(
    //   (item) => item.value !== 'END'
    // ),
    options: [
      { value: 'AUDITING', label: '进行中' },
      { value: 'FINISH', label: '已完结' },
    ],
  },
  {
    code: 'TEXT',
    fieldId: 'taskName',
    fieldTitle: '流程节点',
  },
  {
    code: 'TEXT',
    fieldId: 'pendApproveName',
    fieldTitle: '当前节点负责人',
  },
];

export const specialUserMeta = [
  'region_user_id_1',
  'engineer_user_id_1',
  'assistant_engineer_user_id_1',
  'pendApproveName',
];

export function getOperatorByCode(code) {
  return operatorConfig
    .filter((item) => item.range.includes(code))
    .map((item) => {
      return {
        label: item.label,
        value: item.value,
      };
    });
}
