OfficeSystem/utils/customerMappings.js
2025-11-21 17:11:08 +08:00

174 lines
5.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 客户相关映射配置
* 统一管理客户状态、意向强度、客户类型、跟进方式等映射关系
*/
/**
* 客户状态映射
* 状态值 -> 状态文本
*/
export const CUSTOMER_STATUS_MAP = {
'1': '潜在',
'2': '高意向',
'3': '成交',
'4': '失效',
'5': '低意向',
};
/**
* 客户状态反向映射(用于筛选)
* 状态文本 -> 状态值数组
*/
export const CUSTOMER_STATUS_FILTER_MAP = {
'potential': ['1'], // 潜在
'highIntent': ['2'], // 高意向
'deal': ['3'], // 成交
'invalid': ['4'], // 失效
'lowIntent': ['5'] // 低意向
};
/**
* 意向强度映射
* 强度值 -> 强度文本
*/
export const INTENT_LEVEL_MAP = {
'1': '高',
'2': '中',
'3': '低'
};
/**
* 客户类型映射如果API返回固定值可以在这里定义
* 注意客户类型通常从API获取这里提供备用映射
*/
export const CUSTOMER_TYPE_MAP = {
// 根据实际业务需求添加
// '1': '个人',
// '2': '企业',
};
/**
* 获取客户状态文本
* @param {string|number} status - 客户状态值
* @param {Array} statusOptions - 客户状态选项数组(可选),格式: [{dictLabel: '', dictValue: ''}] 或 [{label: '', value: ''}]
* @returns {string} 状态文本
*/
export const getCustomerStatusText = (status, statusOptions = []) => {
if (!status) return '未知';
// 如果提供了字典数据,优先从字典数据中查找
if (statusOptions && statusOptions.length > 0) {
const option = statusOptions.find(item =>
String(item.dictValue || item.value) === String(status)
);
if (option) {
return option.dictLabel || option.label || '未知';
}
}
// 否则使用静态映射
return CUSTOMER_STATUS_MAP[String(status)] || '未知';
};
/**
* 获取客户状态样式类
* @param {string|number} status - 客户状态值
* @returns {object} 样式类对象
*/
export const getCustomerStatusClass = (status) => {
const statusStr = String(status);
return {
'status-potential': statusStr === '1', // 潜在
'status-intent': statusStr === '2', // 意向
'status-deal': statusStr === '3', // 成交
'status-invalid': statusStr === '4', // 失效
'status-low-intent': statusStr === '5' // 低意向
};
};
/**
* 获取意向强度文本
* @param {string|number} intentLevel - 意向强度值
* @param {Array} intentLevelOptions - 意向强度选项数组(可选),格式: [{dictLabel: '', dictValue: ''}] 或 [{label: '', value: ''}]
* @returns {string} 强度文本
*/
export const getIntentLevelText = (intentLevel, intentLevelOptions = []) => {
if (!intentLevel) return '--';
// 如果提供了字典数据,优先从字典数据中查找
if (intentLevelOptions && intentLevelOptions.length > 0) {
const option = intentLevelOptions.find(item =>
String(item.dictValue || item.value) === String(intentLevel)
);
if (option) {
return option.dictLabel || option.label || '--';
}
}
// 否则使用静态映射
return INTENT_LEVEL_MAP[String(intentLevel)] || '--';
};
/**
* 获取客户类型文本(从字典数据中查找)
* @param {string|number} type - 客户类型值
* @param {Array} typeOptions - 客户类型选项数组,格式: [{label: '', value: ''}]
* @returns {string} 类型文本
*/
export const getCustomerTypeText = (type, typeOptions = []) => {
if (!type) return '--';
if (!typeOptions || typeOptions.length === 0) {
// 如果提供了静态映射,使用静态映射
return CUSTOMER_TYPE_MAP[String(type)] || '--';
}
// 从字典数据中查找
const option = typeOptions.find(item => String(item.value || item.dictValue) === String(type));
return option ? (option.label || option.dictLabel) : '--';
};
/**
* 根据筛选键获取状态值数组
* @param {string} filterKey - 筛选键potential/highIntent/deal/invalid/lowIntent
* @returns {Array<string>} 状态值数组
*/
export const getStatusListByFilter = (filterKey) => {
return CUSTOMER_STATUS_FILTER_MAP[filterKey] || [];
};
/**
* 获取所有客户状态选项(用于下拉选择等)
* @returns {Array} 状态选项数组
*/
export const getCustomerStatusOptions = () => {
return Object.entries(CUSTOMER_STATUS_MAP).map(([value, label]) => ({
value,
label
}));
};
/**
* 获取所有意向强度选项(用于下拉选择等)
* @returns {Array} 强度选项数组
*/
export const getIntentLevelOptions = () => {
return Object.entries(INTENT_LEVEL_MAP).map(([value, label]) => ({
value,
label
}));
};
/**
* 获取跟进方式文本(从字典数据中查找)
* @param {string|number} followType - 跟进方式值
* @param {Array} followTypeOptions - 跟进方式选项数组,格式: [{dictLabel: '', dictValue: ''}] 或 [{label: '', value: ''}]
* @returns {string} 跟进方式文本
*/
export const getFollowTypeText = (followType, followTypeOptions = []) => {
if (!followType) return '--';
if (!followTypeOptions || followTypeOptions.length === 0) {
return '--';
}
// 从字典数据中查找
const option = followTypeOptions.find(item =>
String(item.dictValue || item.value) === String(followType)
);
return option ? (option.dictLabel || option.label) : '--';
};