From fa0b67a76dac989fdc5051d94842659f4857136d Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Tue, 11 Nov 2025 12:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=9F=E8=BF=9B=E7=8A=B6=E6=80=81=E6=98=A0?= =?UTF-8?q?=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/customer/follow/add/index.vue | 20 ++++++----- pages/customer/follow/detail/index.vue | 11 +++--- pages/customer/follow/edit/index.vue | 20 ++++++----- utils/customerMappings.js | 46 ++++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/pages/customer/follow/add/index.vue b/pages/customer/follow/add/index.vue index 07c84c8..2c58508 100644 --- a/pages/customer/follow/add/index.vue +++ b/pages/customer/follow/add/index.vue @@ -235,6 +235,11 @@ import { getCustomerFollowTypeDict } from '@/common/api/customer.js'; import FollowupPickers from '@/components/followup-form/FollowupPickers.vue'; +import { + getCustomerStatusText, + getIntentLevelText as getIntentLevelTextFromMapping, + getFollowTypeText as getFollowTypeTextFromMapping +} from '@/utils/customerMappings'; // 表单数据 const formData = ref({ @@ -803,22 +808,19 @@ const formatDateTimeForInput = (date) => { return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; }; -// 获取状态文本 +// 使用统一映射函数获取状态文本 const getStatusText = (value) => { - const item = statusOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getCustomerStatusText(value, statusOptions.value); }; -// 获取意向强度文本 +// 使用统一映射函数获取意向强度文本 const getIntentLevelText = (value) => { - const item = intentLevelOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getIntentLevelTextFromMapping(value, intentLevelOptions.value); }; -// 获取跟进方式文本 +// 使用统一映射函数获取跟进方式文本 const getFollowTypeText = (value) => { - const item = followTypeOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getFollowTypeTextFromMapping(value, followTypeOptions.value); }; // 提交表单 diff --git a/pages/customer/follow/detail/index.vue b/pages/customer/follow/detail/index.vue index af4d0c8..73db2b8 100644 --- a/pages/customer/follow/detail/index.vue +++ b/pages/customer/follow/detail/index.vue @@ -185,7 +185,8 @@ import { getFollowupDetail, getCustomerFollowTypeDict } from '@/common/api/custo import { getCustomerStatusText, getCustomerStatusClass, - getIntentLevelText + getIntentLevelText, + getFollowTypeText as getFollowTypeTextFromMapping } from '@/utils/customerMappings'; // 页面参数 @@ -375,13 +376,9 @@ const getStatusText = getCustomerStatusText; // getCustomerStatusClass 和 getCustomerStatusText 直接使用导入的函数 const getIntentStrengthText = getIntentLevelText; -// 获取跟进方式文本 +// 使用统一映射函数获取跟进方式文本 const getFollowTypeText = (followTypeValue) => { - if (!followTypeValue) return '--'; - - // 从字典数据中查找对应的标签 - const option = followTypeOptions.value.find(item => item.dictValue === String(followTypeValue)); - return option ? option.dictLabel : '--'; + return getFollowTypeTextFromMapping(followTypeValue, followTypeOptions.value); }; // 预览图片 diff --git a/pages/customer/follow/edit/index.vue b/pages/customer/follow/edit/index.vue index a2a92ab..917d4a0 100644 --- a/pages/customer/follow/edit/index.vue +++ b/pages/customer/follow/edit/index.vue @@ -238,6 +238,11 @@ import { getCustomerFollowTypeDict } from '@/common/api/customer.js'; import FollowupPickers from '@/components/followup-form/FollowupPickers.vue'; +import { + getCustomerStatusText, + getIntentLevelText as getIntentLevelTextFromMapping, + getFollowTypeText as getFollowTypeTextFromMapping +} from '@/utils/customerMappings'; // 跟进ID const followId = ref(''); @@ -871,22 +876,19 @@ const formatDateTimeForInput = (date) => { return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; }; -// 获取状态文本 +// 使用统一映射函数获取状态文本 const getStatusText = (value) => { - const item = statusOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getCustomerStatusText(value, statusOptions.value); }; -// 获取意向强度文本 +// 使用统一映射函数获取意向强度文本 const getIntentLevelText = (value) => { - const item = intentLevelOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getIntentLevelTextFromMapping(value, intentLevelOptions.value); }; -// 获取跟进方式文本 +// 使用统一映射函数获取跟进方式文本 const getFollowTypeText = (value) => { - const item = followTypeOptions.value.find(item => item.dictValue === value); - return item ? item.dictLabel : ''; + return getFollowTypeTextFromMapping(value, followTypeOptions.value); }; // 提交表单 diff --git a/utils/customerMappings.js b/utils/customerMappings.js index 407aeac..9f8c890 100644 --- a/utils/customerMappings.js +++ b/utils/customerMappings.js @@ -1,6 +1,6 @@ /** * 客户相关映射配置 - * 统一管理客户状态、意向强度、客户类型等映射关系 + * 统一管理客户状态、意向强度、客户类型、跟进方式等映射关系 */ /** @@ -48,10 +48,21 @@ export const CUSTOMER_TYPE_MAP = { /** * 获取客户状态文本 * @param {string|number} status - 客户状态值 + * @param {Array} statusOptions - 客户状态选项数组(可选),格式: [{dictLabel: '', dictValue: ''}] 或 [{label: '', value: ''}] * @returns {string} 状态文本 */ -export const getCustomerStatusText = (status) => { +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)] || '未知'; }; @@ -73,10 +84,21 @@ export const getCustomerStatusClass = (status) => { /** * 获取意向强度文本 * @param {string|number} intentLevel - 意向强度值 + * @param {Array} intentLevelOptions - 意向强度选项数组(可选),格式: [{dictLabel: '', dictValue: ''}] 或 [{label: '', value: ''}] * @returns {string} 强度文本 */ -export const getIntentLevelText = (intentLevel) => { +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)] || '--'; }; @@ -128,3 +150,21 @@ export const getIntentLevelOptions = () => { })); }; +/** + * 获取跟进方式文本(从字典数据中查找) + * @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) : '--'; +}; +