Files
shanxia2.0/web-admin/src/utils/crm-opportunity-labels.ts
T
2026-06-01 08:21:21 +08:00

66 lines
2.3 KiB
TypeScript

import type { useDictStore } from '@/store/modules/dict'
/** 商机类型(门户库暂无 crm_opportunity_type 字典时的兜底) */
export const OPPORTUNITY_TYPE_FALLBACK: Record<string, string> = {
new_customer: '新客户开发',
old_customer: '老客户维护',
product_upgrade: '产品升级',
value_added: '增值服务',
other: '其他',
new: '新客户',
renew: '老客户续费',
upgrade: '升级'
}
/** 商机来源(表单历史硬编码值兜底;标准值仍以 crm_clue_source 为准) */
export const OPPORTUNITY_SOURCE_FALLBACK: Record<string, string> = {
phone: '电话营销',
internet: '网络推广',
exhibition: '展会活动',
referral: '客户推荐',
walk_in: '主动上门',
other: '其他'
}
type DictStore = ReturnType<typeof useDictStore>
function findDictItem(dictStore: DictStore, dictType: string, value: string) {
return dictStore.dictMap[dictType]?.find((item) => item.value === value)
}
export function resolveOpportunityDictLabel(
dictStore: DictStore,
dictType: string,
value?: string | null,
fallback?: Record<string, string>
): string {
if (!value) return '—'
const hit = findDictItem(dictStore, dictType, value)
if (hit?.label) return hit.label
if (fallback?.[value]) return fallback[value]
return value
}
export function resolveOpportunityTypeLabel(dictStore: DictStore, type?: string | null) {
return resolveOpportunityDictLabel(dictStore, 'crm_opportunity_type', type, OPPORTUNITY_TYPE_FALLBACK)
}
export function resolveOpportunitySourceLabel(dictStore: DictStore, source?: string | null) {
return resolveOpportunityDictLabel(dictStore, 'crm_clue_source', source, OPPORTUNITY_SOURCE_FALLBACK)
}
export function resolveOpportunityStageLabel(dictStore: DictStore, stage?: string | null, stageName?: string | null) {
if (stageName?.trim()) return stageName
return resolveOpportunityDictLabel(dictStore, 'crm_opportunity_stage', stage)
}
export function resolveOpportunityStatusLabel(dictStore: DictStore, status?: string | null) {
return resolveOpportunityDictLabel(dictStore, 'crm_opportunity_status', status)
}
export function resolveOpportunityTagType(dictStore: DictStore, dictType: string, value?: string | null) {
if (!value) return undefined
const hit = findDictItem(dictStore, dictType, value)
return hit?.tagType || dictStore.getTagType(dictType, value) || 'info'
}