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

export const DICT_TYPE = {
  USER_TYPE: "user_type",
  COMMON_STATUS: "common_status",
  AUDIT_STATUS: "audit_status",
  ADVANCE_STATUS: "advance_status",
  BOX_SHIPMENT_STATUS: "box_shipment_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_MAIL_SEND_STATUS: "mail_send_status",
  SYSTEM_ERROR_CODE_TYPE: "system_error_code_type",
  INTERNAL_MESSAGE_TYPE: "internal_message_type",
  INTERNAL_MESSAGE_READ_STATUS: "internal_message_read_status",

  HELP_DOC_STATUS: "help_doc_status",

  // ========== 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",

  // ========== 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", // 退款订单类别
  ECW_BANK_TYPE: "bank_type", // 银行账号类型
  // ECW_DATA_SOURCE: 'data_source', // 数据来源
  ECW_REGION_TYPE: "region_trade_type", // 区域类型
  ECW_TRANSPORT_TYPE: "transport_type", // 货运方式
  ECW_CHARGE_TYPE: "warehouse_charge_type", // 仓储收费方式
  ECW_SHELF_TYPE: "shelf_type", // 货架类型
  ECW_PRODUCT_MATERIAL: "product_material", // 商品材质
  ECW_PACKAGING_TYPE: "packaging_type", // 包装要求
  ECW_CONTAINER_LOCATION: "container_location", // 默认货柜位置
  ECW_SPECIAL_REQ_FOR_LINE_PRODUCTS: "special_req_for_line_products", // 特殊需求
  ECW_COUPON_TYPE: "coupon_type", // 优惠券类型
  ECW_COUPON_STATUS: "coupon_status", // 优惠券状态
  ECW_COUPON_COST_TYPE: "coupon_cost_type", // 优惠券费用类型
  ECW_COUPON_OVERDUE_STATUS: "coupon_overdue_status", // 优惠券状态
  ECW_COUPON_PUTON_STATUS: "coupon_puton_status",
  ECW_SUITABLE_USER_TYPE: "suitable_user_type", // 适用用户类型
  ECW_SUITABLE_LINE_TYPE: "suitable_line_type", // 适用线路类型
  ECW_SUITABLE_PROD_TYPE: "suitable_prod_type", // 适用产品类型
  ECW_ORDER_ATTR: "order_attr", // 订单属性
  ECW_YESNO: "yesno", // 是否 1,0
  ECW_COMPANY_TYPE: "company_type", // 供应商类别
  ECW_COOPERATION_TYPE: "cooperation_type", // 合作类型
  ECW_SHIPPING_DECLARATION_TYPE: "shipping_declaration_type", // 出货报关方式（与订单报关方式相同）
  ECW_CUSTOMS_TYPE: "customs_type", //  订单报关方式（非出货报关），优惠券中的单证报关
  ECW_PACKAGE_TYPE: "packageType", // 包装单位
  ECW_DOUBLE_CLEAR: "double_clear", // 是否双清
  ECW_TRADE_TYPE: "trade_type", // 交货放肆
  ECW_OFFER_RESULT: "offer_result", //  报单结果 赢单 输单
  ECW_WAREHOUSING_TYPE: "warehousing_type", //  入仓类型
  ECW_OFFER_STATUS: "offer_status", // 销售阶段（报价单）
  ECW_IS_BRAND: "is_brand", // 有无品牌
  ECW_OFFER_TYPE: "offer_type", // 跟进类型
  ECW_OFFER_METHOD: "offer_method", //  跟进方式
  ECW_RECEIPT_STATE: "receipt_state", // 收款单状态
  ECW_SUING_METHOD: "suing_method", // 出单方式
  ECW_HARVEST_METHOD: "harvest_method", // 收货方式
  ECW_PAY_ADVANCE: "pay_advance", // 是否预付
  ECW_CUSTOM_DRAWEE: "custom_drawee", // 自定义付款人费用类型
  ECW_BEGINTIME_TYPE_ENDTIME: "begintime_type_endtime", // 时间筛选字段（订单）
  APP_ORDER_STATUS: "app_order_status", // 订单状态筛选字段（订单）
  // --------ecw---------
  CUSTOMER_STATUS: "customer_status",
  CUSTOMER_SOURCE: "customer_source",
  CUSTOMER_BALANCE: "customer_balance",
  CUSTOMER_TYPE: "customer_type",
  CUSTOMER_LEVEL: "customer_level",
  CUSTOMER_COMPLAINT_TYPE: "customer_complaint_type",
  CUSTOMER_COMPLAINT_STATUS: "customer_complaint_status",
  ECW_MESSAGE_LEAVE_TYPE: "ecw_message_leave_type",
  ECW_MESSAGE_LEAVE_STATUS: "ecw_message_leave_status",
  PWD_TYPE: "pwd_type",
  ZHONG_PAO_TYPE: "zhong_pao_type",
  TRANSPORT_TYPE: "transport_type",
  BRAND_REG_TYPE: "brand_registry_type",
  BRAND_AUTH_STATUS: "brand_authorization_status",
  BRAND_CUSTOMER_CHARGING_MODEL: "customer_charging_model",
  COUNTRY: "country", // 国家地区
  AREA_CODE: "area_code", // 区号
  SOCIAL: "customer_social_tools", // 社交软件
  IS_DEFAULT: "is_default", // 默认联系人
  CUSTOMER_FOLLOW_TYPE: "customer_follow_type", // 跟进类型
  CUSTOMER_FOLLOW_METHOD: "customer_follow_method", //  跟进方式
  COMMISSION_PRODUCT_APPROVAL: "commission_product_approval", // 佣金备案
  SHIPPING_DECLARATION_TYPE: "shipping_declaration_type", // 出货报关方式（与订单报关方式相同）
  COMMISSION_TYPE: "commission_type", // 佣金类型
  COMMISSION_DARK_TYPE: "commission_dark_type", // 暗涌类型
  COMMISSION_CURRENCY_TYPE: "commission_currency_type", // 佣金货币类型
  // COMMISSION_UNIT: 'commission_unit',//佣金货物单位
  ECW_PORT_TYPE: "port_type", // 港口类型
  CERTIFICATE_TYPE: "certificate_type", // 证件类型
  // customer
  CUSTOMER_CREDIT_RULE_TYPE: "customer_credit_rule_type",
  CUSTOMER_LEVEL_RULE_TYPE: "customer_level_rule_type",
  // order
  ORDER_TYPE: "order_type", // 订单类型
  PRODUCT_RECORD_ATTRIBUTE: "product_record_attribute", // 产品备案属性
  CONTROL_GOODS_STATUS: "control_goods_status", // 控货状态
  DISBURSEMENT_TYPE: "disbursement_type", // 垫付类型
  DRAWEE: "drawee", // 付款人
  ORDER_STATUS: "order_status", // 订单状态
  BEGINTIME_TYPE_ENDTIME: "begintime_type_endtime", // 订单日期筛选类别
  ORDER_ERROR_TYPE: "order_error_type", // 订单异常类型
  ORDER_EXCEPTION_STATUS: "order_exception_status", // 异常订单状态
  PAYMENT_TYPE: "payment_type", // 收款类型

  ECASH_INIT: "ecash_init", // e-cash
  FEE_TYPE: "receivable_fee_type",
  // PAY_TYPE:'payment_type',
  RECEIVE_FLAG: "receive_flag",
  COMDINED_VALUE_ADDED_FEE: "combined_value_added_fee",
  ORDER_SPECIAL_NEEDS: "order_special_needs", // 订单特殊需求
  ORDER_ABNORMAL_STATE: "order_abnormal_state",

  // ========== 出货模块 ==========
  BOX_SHIPMENT_TRAILER_STATUS: "shipment_trailer_status", // 拖车状态
  QUANTITATIVE_RELATION_SYMBOL: "quantitative_relation_symbol", //数量关系符号
  WAY_OF_RECEIVING: "way_of_receiving", //领取方式
  GIFT_STATUS: "gift_status", //礼品状态
  GIFT_ENABLE_STATUS: "gift_enable_status", //礼品启用状态
  PLATFORM_TYPE: "platform_type", //平台入口
  REWARD_REDEEM_STATUS: "reward_redeem_status", //礼品兑换状态
  MEMBER_SCORE_OPERATE_TYPE: "member_user_score_log_operate_type", //会员积分日志操作类型
  SCORE_RULE_TYPE: "score_rule_type", //积分规则指标类型
  YES_OR_NO: "yes_or_no",
  CLIENT_PLATFORM: "client_platform",
  MEMBER_SCORE_SOURCE: "member_score_source", //会员积分来源
  MEMBERSHIP_LEVELS: "membership_levels", //会员等级
  MEMBER_USER_OPERATE_LOG: "member_user_operate_log", //会员等级操作日志
};

/**
 * 获取 dictType 对应的数据字典数组
 *
 * @param dictType 数据类型
 * @returns {*|Array} 数据字典数组
 */
export function getDictDatas(dictType) {
  // if (dictType === 'bpm_task_assign_script') {
  //   console.log(store.getters.dict_datas[dictType]);
  //   debugger
  // }
  // debugger
  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);
    }
  }
  // debugger
  // console.log(results);
  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 {}
