OfficeSystem/utils/customerMappings.js

173 lines
5.2 KiB
JavaScript
Raw Normal View History

2025-11-11 11:19:52 +08:00
/**
* 客户相关映射配置
2025-11-11 12:00:18 +08:00
* 统一管理客户状态意向强度客户类型跟进方式等映射关系
2025-11-11 11:19:52 +08:00
*/
/**
* 客户状态映射
* 状态值 -> 状态文本
*/
export const CUSTOMER_STATUS_MAP = {
'1': '潜在',
2025-11-21 16:55:45 +08:00
'2': '高意向',
2025-11-11 11:19:52 +08:00
'3': '成交',
2025-11-21 16:55:45 +08:00
'4': '失效',
'5': '低意向',
2025-11-11 11:19:52 +08:00
};
/**
* 客户状态反向映射用于筛选
* 状态文本 -> 状态值数组
*/
export const CUSTOMER_STATUS_FILTER_MAP = {
2025-11-21 16:55:45 +08:00
'potential': ['1'], // 潜在
'highIntent': ['2'], // 高意向
'deal': ['3'], // 成交
'invalid': ['4'], // 失效
'lowIntent': ['5'] // 低意向
2025-11-11 11:19:52 +08:00
};
/**
* 意向强度映射
* 强度值 -> 强度文本
*/
export const INTENT_LEVEL_MAP = {
'1': '高',
'2': '中',
'3': '低'
};
/**
* 客户类型映射如果API返回固定值可以在这里定义
* 注意客户类型通常从API获取这里提供备用映射
*/
export const CUSTOMER_TYPE_MAP = {
// 根据实际业务需求添加
// '1': '个人',
// '2': '企业',
};
/**
* 获取客户状态文本
* @param {string|number} status - 客户状态值
2025-11-11 12:00:18 +08:00
* @param {Array} statusOptions - 客户状态选项数组可选格式: [{dictLabel: '', dictValue: ''}] [{label: '', value: ''}]
2025-11-11 11:19:52 +08:00
* @returns {string} 状态文本
*/
2025-11-11 12:00:18 +08:00
export const getCustomerStatusText = (status, statusOptions = []) => {
2025-11-11 11:19:52 +08:00
if (!status) return '未知';
2025-11-11 12:00:18 +08:00
// 如果提供了字典数据,优先从字典数据中查找
if (statusOptions && statusOptions.length > 0) {
const option = statusOptions.find(item =>
String(item.dictValue || item.value) === String(status)
);
if (option) {
return option.dictLabel || option.label || '未知';
}
}
// 否则使用静态映射
2025-11-11 11:19:52 +08:00
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' // 失效
};
};
/**
* 获取意向强度文本
* @param {string|number} intentLevel - 意向强度值
2025-11-11 12:00:18 +08:00
* @param {Array} intentLevelOptions - 意向强度选项数组可选格式: [{dictLabel: '', dictValue: ''}] [{label: '', value: ''}]
2025-11-11 11:19:52 +08:00
* @returns {string} 强度文本
*/
2025-11-11 12:00:18 +08:00
export const getIntentLevelText = (intentLevel, intentLevelOptions = []) => {
2025-11-11 11:19:52 +08:00
if (!intentLevel) return '--';
2025-11-11 12:00:18 +08:00
// 如果提供了字典数据,优先从字典数据中查找
if (intentLevelOptions && intentLevelOptions.length > 0) {
const option = intentLevelOptions.find(item =>
String(item.dictValue || item.value) === String(intentLevel)
);
if (option) {
return option.dictLabel || option.label || '--';
}
}
// 否则使用静态映射
2025-11-11 11:19:52 +08:00
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) : '--';
};
/**
* 根据筛选键获取状态值数组
2025-11-21 16:55:45 +08:00
* @param {string} filterKey - 筛选键potential/highIntent/deal/invalid/lowIntent
2025-11-11 11:19:52 +08:00
* @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
}));
};
2025-11-11 12:00:18 +08:00
/**
* 获取跟进方式文本从字典数据中查找
* @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) : '--';
};