/**
 * Created by 芋道源码
 *
 * 数据字典工具类
 */
import store from "@/store";

export const DICT_TYPE = {
  USER_TYPE: "user_type",
  COMMON_STATUS: "common_status",

  // ========== SYSTEM 模块 ==========
  SYSTEM_USER_SEX: "system_user_sex",
  SYSTEM_MENU_TYPE: "system_menu_type",
  SYSTEM_ROLE_TYPE: "system_role_type",
  SYSTEM_DATA_SCOPE: "system_data_scope",
  SYSTEM_NOTICE_TYPE: "system_notice_type",
  SYSTEM_OPERATE_TYPE: "system_operate_type",
  SYSTEM_LOGIN_TYPE: "system_login_type",
  SYSTEM_LOGIN_RESULT: "system_login_result",
  SYSTEM_SMS_CHANNEL_CODE: "system_sms_channel_code",
  SYSTEM_SMS_TEMPLATE_TYPE: "system_sms_template_type",
  SYSTEM_SMS_SEND_STATUS: "system_sms_send_status",
  SYSTEM_SMS_RECEIVE_STATUS: "system_sms_receive_status",
  SYSTEM_ERROR_CODE_TYPE: "system_error_code_type",
  SYSTEM_OAUTH2_GRANT_TYPE: "system_oauth2_grant_type",
  SYSTEM_NOTIFY_TEMPLATE_TYPE: "system_notify_template_type",
  EIM_BUSINESS_OBJECT_TYPE: "eim_business_object_type",
  EIM_BUSINESS_OBJECT_DATE: "eim_business_object_date",

  // ========== INFRA 模块 ==========
  INFRA_BOOLEAN_STRING: "infra_boolean_string",
  INFRA_REDIS_TIMEOUT_TYPE: "infra_redis_timeout_type",
  INFRA_JOB_STATUS: "infra_job_status",
  INFRA_JOB_LOG_STATUS: "infra_job_log_status",
  INFRA_API_ERROR_LOG_PROCESS_STATUS: "infra_api_error_log_process_status",
  INFRA_CONFIG_TYPE: "infra_config_type",
  INFRA_CODEGEN_TEMPLATE_TYPE: "infra_codegen_template_type",
  INFRA_CODEGEN_SCENE: "infra_codegen_scene",
  INFRA_FILE_STORAGE: "infra_file_storage",
  INFRA_CODEGEN_FRONT_TYPE: "infra_codegen_front_type", //生成代码前端类型
  AUDIT_TYPE: "audit_type", //审核类型

  // ========== BPM 模块 ==========
  BPM_MODEL_CATEGORY: "bpm_model_category",
  BPM_MODEL_FORM_TYPE: "bpm_model_form_type",
  BPM_TASK_ASSIGN_RULE_TYPE: "bpm_task_assign_rule_type",
  BPM_PROCESS_INSTANCE_STATUS: "bpm_process_instance_status",
  BPM_PROCESS_INSTANCE_RESULT: "bpm_process_instance_result",
  BPM_TASK_ASSIGN_SCRIPT: "bpm_task_assign_script",
  BPM_OA_LEAVE_TYPE: "bpm_oa_leave_type",

  // ========== PAY 模块 ==========
  PAY_CHANNEL_WECHAT_VERSION: "pay_channel_wechat_version", // 微信渠道版本
  PAY_CHANNEL_ALIPAY_SIGN_TYPE: "pay_channel_alipay_sign_type", // 支付渠道支付宝算法类型
  PAY_CHANNEL_ALIPAY_MODE: "pay_channel_alipay_mode", // 支付宝公钥类型
  PAY_CHANNEL_ALIPAY_SERVER_TYPE: "pay_channel_alipay_server_type", // 支付宝网关地址
  PAY_CHANNEL_CODE_TYPE: "pay_channel_code_type", // 支付渠道编码类型
  PAY_ORDER_NOTIFY_STATUS: "pay_order_notify_status", // 商户支付订单回调状态
  PAY_ORDER_STATUS: "pay_order_status", // 商户支付订单状态
  PAY_ORDER_REFUND_STATUS: "pay_order_refund_status", // 商户支付订单退款状态
  PAY_REFUND_ORDER_STATUS: "pay_refund_order_status", // 退款订单状态
  PAY_REFUND_ORDER_TYPE: "pay_refund_order_type", // 退款订单类别

  // ========== 生产管理 模块 ==========
  MES_PRODUCTION_ORDER_STATUS: "mes_production_order_status", // 生产状态
  MES_PRODUCTION_ORDER_TYPE: "mes_production_order_type", //
  MES_UNIT: "mes_unit", // 单位
  MES_PROCESS_SECTION: "mes_process_section",
  MES_ERP: "mes_erp", //ERP标识
  WMS_STOCK_CATEGORIES: "wms_stock_categories", //仓库类别
  WMS_STOCK_MODES: "wms_stock_modes", //仓库模式
  WMS_SUPPLIER_TYPES: "wms_supplier_types", //供应商类型
  MES_MATERIAL_CATEGORIES: "mes_material_categories", //物料类别
  MES_RECEIVE_MATERIALS_ORDER_STATUS: "mes_receive_materials_order_status", //单据状态
  WMS_DOCUMENTS_TYPE: "wms_documents_type", //单据类型
  WMS_TEST_STATUS: "wms_test_status", //检验状态
  MES_SEND_MATERIAL_STATUS: "mes_send_material_status", //领料状态
  MES_ISSUE_MATERIALS_STATUS: "mes_issue_materials_status", //发料状态
  WMS_DELIVERY_TYPE: "wms_delivery_type", //交货方式
  WMS_SEND_ISSUE_PROGRESS: "wms_send_issue_progress", //发料进度
  WMS_SALES_STATUS: "wms_sales_status", //销售状态
  WMS_ISSUE_STATUS: "wms_issue_status", //出库状态
  // 检验
  WMS_TEST_RESULT: "wms_test_result", //检验结果
  WMS_INSPECTION_CATEGORY: "wms_Inspection_category", //检验类别
  WMS_INSPECTION_TYPE: "wms_inspection_type", //检验类型
  WMS_DELIVERY_STATUS: "wms_delivery_status", //发料状态
  WMS_JUDGE_CHECKING: "wms_judge_checking", //wms判断是否免检
  WMS_RECEIVE_MATERIALS_STATUS: "wms_receive_materials_status", //wms领料状态
  WMS_MATERIAL_RETURN_STATUS: "wms_material_return_status", //退料状态
  MES_QC_BAD_TYPE: "mes_qc_bad_type", //不良类型
  MES_QC_BAD_LEVEL: "mes_qc_bad_level", //不良等级
  MES_QUALITY_IPQC_SINGLE_RESULT: "mes_quality_ipqc_single_result", // 实测值是否合格
  WMS_INSPECT_DEAL_RESULTS: "wms_inspect_deal_results", //处理结果
  WMS_MATERIAL_PREPARATION_STATUS: "wms_material_preparation_status", //备料状态
  WMS_UNPACKING_STATUS: "wms_unpacking_status", //装箱状态
  WMS_MATERIAL_SPLIT: "wms_material_split", //物料是否拆合批
  WMS_APPROVAL_RESULTS: "wms_approval_results", //审批结果
  WMS_WAREHOUSING_STATUS: "wms_warehousing_status", //入库状态
  WMS_SALE_ORDER_DOCUMENT_TYPE: "wms_sale_order_document_type", //销售订单单据类型
  WMS_ISSUE_TYPE: "wms_issue_type", //发料类型
  WMS_MATERIALS_STATUS: "wms_materials_status", //物料状态
  WMS_SALE_ORDER_DELIVER_STATUS: "wms_sale_order_deliver_status", //销售发料状态
  WMS_PURCHASE_ORDERS_DOCUMENT_STATUS: "wms_purchase_orders_document_status", //采购订单单据状态
  WMS_DOCUMENT_STATUS: "wms_document_status", //wms业务单据 单据状态
  WMS_SCRAP_TYPE: "wms_scrap_type", //报废类型
  WMS_PURCHASE_RETURN_STATUS: "wms_purchase_return_status", //来料退货退料状态
  WMS_IS_MAIN_MATERIALS: "wms_is_main_materials", //是否主料
  WMS_PALLET_USE: "wms_pallet_use", //栈板是否使用
  WMS_OTHER_ISSUE_TYPE: "wms_other_issue_type", //交易类型
  WMS_INSPECTION_ITEMS: "wms_inspection_items", //检查类别（大类）
  MES_COMMON_STATUS: "mes_common_status", //通用启/禁用状态
  WMS_INSPECTION_TOOLS: "wms_inspection_tools", //wms检查工具
  WMS_CHECK_QUANTITY: "wms_check_quantity", //wms检查数量
  WMS_ENABLE_FLAG: "wms_enable_flag", //启用标志
  WMS_AUDIT_STATUS: "wms_audit_status", //检验标准审核状态
  WMS_NO_PASS_TYPE: "wms_no_pass_type", //wms不合格处理
  WMS_MATERIAL_RETURN_TYPE: "wms_material_return_type", //wms退料类型
  WMS_RETURN_MATERIALS_APPROVAL_STATUS: "wms_return_materials_approval_status", //wms退料审核状态
  WMS_RETURN_STATUS: "wms_return_status", //退料管理退料状态
  WMS_IQC_APPROVAL_STATUS: "wms_iqc_approval_status", //iqc审核状态
  WMS_OTHER_ISSUE_TYPE_ERP: "wms_other_issue_type_erp", //wms其他出库类型erp
  MES_RESUPPLY_ORDER_APPROVAL_STATUS: "mes_resupply_order_approval_status", //补料审批状态
  WMS_INCOMING_TYPE: "wms_incoming_type", //入库类型
  // 受托物料
  WMS_MATERIAL_RECEIVING_CATEGORY: "wms_material_receiving_category",
  // 拆箱状态
  WMS_QUERY_UNPACKING_STATUS: "wms_query_unpacking_status",

  // dfs
  WMS_SLITTING_STATUS: "wms_slitting_status", //分切状态
  WMS_SLITTING_OR_NOT: "wms_slitting_or_not", //是否分切
  WMS_SLITTING_MATERIAL_STATUS: "wms_slitting_material_status", //分切物料状态
  WMS_LOAD_STATUS: "wms_load_status", //分切上料状态,
  WMS_OQC_AUDIT_STATUS: "wms_oqc_audit_status", //oqc审核状态
  YES_NO: "yes_no", //是否字典
  WMS_SIGN_STATUS: "wms_sign_status", //签收状态
  WMS_INSPECTION_UNIT: "wms_inspection_unit", //WMS检验项计量单位
  WMS_RECEIVE_STATUS: "wms_receive_status", //收货状态
  WMS_OUT_SOURCE_STATUS: "wms_out_source_status", //委外领料状态
  CLASS_FLAG: "class_flag", //oqc班别
  WMS_IPQC_QUERY_TYPE: "wms_ipqc_query_type", //ipqc查看方式
  WMS_IPQC_FIRST_INSPECTION_CONTROL: "wms_ipqc_first_inspection_control", //ipqc首件是否管控
  WMS_DELIVERY_BACKSIGN_STATUS: "wms_delivery_backsign_status", //送货单回签状态
  WMS_IS_OVER_DATE_SORT: "wms_is_over_date_sort", //WMS有效期排序
  OTHER_IN_STOCK_TYPE: "other_in_stock_type", // 其他收料类别
  WMS_SALES_RETURN_STATUS: "wms_sales_return_status", //销售退货状态
  SALE_RETURN_TYPE: "sale_return_type", //销售退货类型
  SYS_ZONE: "sys_zone", //区域字典
  NOTIFY_ASSIGN_SCRIPT: "notify_assign_script", //站内信自定义脚本
  LODOP_REPORT_TYPE: "lodop_report_type", //LODOP打印模板
  PULL_FORCE_TITLE: "pull_force_title", //测试条信息标题
  ORIGINAL_GLUE_PULL_FORCE: "original_glue_pull_force", //测试条信息原胶拉力
  RELATIVE_STRIPPING_FORCE: "relative_stripping_force", //测试条信息相对剥离力
  WORKFLOW_ENABLE_FLAG: "workflow_enable_flag", //工作流启用标识
  WMS_SPLITTING_TYPE: "wms_splitting_type", //分切类型
  WMS_SHELVES_CODE: "wms_shelves_code", //WMS货架号
  WMS_LEVEL_CODE: "wms_level_code", // WMS层号
  WMS_LOCATION_CODE: "wms_location_code", //WMS位置号
  WMS_REGULAR_CHECK_DOCUMENT_TYPE: "wms_regular_check_document_type", //定期盘点单据类型
  ERP_WRITE_FLAG: "erp_write_flag", //ERP回写是否成功
  WMS_INSPECT_RESULTS: "wms_inspect_results", //IQC检验结果
  WMS_SPLIT_TYPE: "wms_split_type", //分拆类型
  BOX_TYPE: "box_type", //箱型
  SPLIT_LOSS_TYPE: "split_loss_type", //损耗类型
  WMS_ALLOT_MODE: "wms_allot_mode", //倒冲发料字典
  RETURN_WAY: "return_way", // 受托加工退料方式
  RETURN_TYPE: "return_type", // 退料类型

  //=============数据管理器(查询管理)==================
  YM_DATA_TYPE: "ym_data_type", // 字段类型
  YM_STRING_QUERY_TYPE: "ym_string_query_type",
  YM_INT_QUERY_TYPE: "ym_int_query_type",
  YM_DATE_QUERY_TYPE: "ym_date_query_type",
  YM_UNIQUE_DATA_QUERY: "ym_unique_data_query",
  HTTP_METHOD_TYPE: "http_method_type", // HTTP方法类型
  REQUEST_PARAM_TYPE: "request_param_type", // 请求参数类型
};

/**
 * 获取 dictType 对应的数据字典数组
 *
 * @param dictType 数据类型
 * @returns {*|Array} 数据字典数组
 */
export function getDictDatas(dictType) {
  return store.getters.dict_datas[dictType] || [];
}

/**
 * 获取 dictType 对应的数据字典数组
 *
 * @param dictType 数据类型
 * @param values 数组、单个元素
 * @returns {*|Array} 数据字典数组
 */
export function getDictDatas2(dictType, values) {
  if (values === undefined) {
    return [];
  }
  // 如果是单个元素，则转换成数组
  if (!Array.isArray(values)) {
    values = [this.value];
  }
  // 获得字典数据
  const results = [];
  for (const value of values) {
    const dict = getDictData(dictType, value);
    if (dict) {
      results.push(dict);
    }
  }
  return results;
}

export function getDictData(dictType, value) {
  // 获取 dictType 对应的数据字典数组
  const dictDatas = getDictDatas(dictType);
  if (!dictDatas || dictDatas.length === 0) {
    return "";
  }
  // 获取 value 对应的展示名
  value = value + ""; // 强制转换成字符串，因为 DictData 小类数值，是字符串
  for (const dictData of dictDatas) {
    if (dictData.value === value) {
      return dictData;
    }
  }
  return undefined;
}

export function getDictDataLabel(dictType, value) {
  const dict = getDictData(dictType, value);
  return dict ? dict.label : "";
}

export class getDictDataL {}
