OfficeSystem/utils/customerMappings.js

131 lines
3.3 KiB
JavaScript
Raw Normal View History

2025-11-11 11:19:52 +08:00
/**
* 客户相关映射配置
* 统一管理客户状态意向强度客户类型等映射关系
*/
/**
* 客户状态映射
* 状态值 -> 状态文本
*/
export const CUSTOMER_STATUS_MAP = {
'1': '潜在',
'2': '意向',
'3': '成交',
'4': '失效'
};
/**
* 客户状态反向映射用于筛选
* 状态文本 -> 状态值数组
*/
export const CUSTOMER_STATUS_FILTER_MAP = {
'potential': ['1'], // 潜在
'intent': ['2'], // 意向
'deal': ['3'], // 成交
'invalid': ['4'] // 失效
};
/**
* 意向强度映射
* 强度值 -> 强度文本
*/
export const INTENT_LEVEL_MAP = {
'1': '高',
'2': '中',
'3': '低'
};
/**
* 客户类型映射如果API返回固定值可以在这里定义
* 注意客户类型通常从API获取这里提供备用映射
*/
export const CUSTOMER_TYPE_MAP = {
// 根据实际业务需求添加
// '1': '个人',
// '2': '企业',
};
/**
* 获取客户状态文本
* @param {string|number} status - 客户状态值
* @returns {string} 状态文本
*/
export const getCustomerStatusText = (status) => {
if (!status) return '未知';
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 - 意向强度值
* @returns {string} 强度文本
*/
export const getIntentLevelText = (intentLevel) => {
if (!intentLevel) return '--';
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/intent/deal/invalid
* @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
}));
};