瀏覽代碼

feat(lead): 添加销售线索管理相关常量和工具函数

yz 3 周之前
父節點
當前提交
4e199b605f
共有 3 個文件被更改,包括 315 次插入25 次删除
  1. 4 1
      src/constants/index.js
  2. 250 0
      src/constants/lead.js
  3. 61 24
      src/views/lead/mixins/leadIndex.js

+ 4 - 1
src/constants/index.js

@@ -12,4 +12,7 @@ export * from './claim'
 export * from './complaint'
 
 // 形象店铺申请相关常量
-export * from './image-store-apply'
+export * from './image-store-apply'
+
+// 销售线索管理相关常量
+export * from './lead'

+ 250 - 0
src/constants/lead.js

@@ -0,0 +1,250 @@
+/**
+ * 销售线索管理相关常量定义
+ * @fileoverview 销售线索优先级、状态等枚举值和工具函数
+ */
+
+/**
+ * 线索优先级枚举
+ * @readonly
+ * @enum {number}
+ */
+export const LEAD_PRIORITY = {
+  /** 低优先级 */
+  LOW: 1,
+  /** 中优先级 */
+  MEDIUM: 2,
+  /** 高优先级 */
+  HIGH: 3
+}
+
+/**
+ * 线索状态枚举
+ * @readonly
+ * @enum {number}
+ */
+export const LEAD_STATUS = {
+  /** 待处理 */
+  PENDING: 0,
+  /** 跟进中 */
+  FOLLOWING: 1,
+  /** 已转化 */
+  CONVERTED: 2,
+  /** 已关闭 */
+  CLOSED: 3
+}
+
+/**
+ * 线索优先级配置映射
+ * @readonly
+ * @type {Record<number, {label: string, type: string, color: string}>}
+ */
+export const LEAD_PRIORITY_CONFIG = {
+  [LEAD_PRIORITY.LOW]: {
+    label: '低',
+    type: 'success',
+    color: '#67C23A'
+  },
+  [LEAD_PRIORITY.MEDIUM]: {
+    label: '中',
+    type: 'warning',
+    color: '#E6A23C'
+  },
+  [LEAD_PRIORITY.HIGH]: {
+    label: '高',
+    type: 'danger',
+    color: '#F56C6C'
+  }
+}
+
+/**
+ * 线索状态配置映射
+ * @readonly
+ * @type {Record<number, {label: string, type: string, color: string}>}
+ */
+export const LEAD_STATUS_CONFIG = {
+  [LEAD_STATUS.PENDING]: {
+    label: '待处理',
+    type: 'info',
+    color: '#909399'
+  },
+  [LEAD_STATUS.FOLLOWING]: {
+    label: '跟进中',
+    type: 'warning',
+    color: '#E6A23C'
+  },
+  [LEAD_STATUS.CONVERTED]: {
+    label: '已转化',
+    type: 'success',
+    color: '#67C23A'
+  },
+  [LEAD_STATUS.CLOSED]: {
+    label: '已关闭',
+    type: 'info',
+    color: '#909399'
+  }
+}
+
+/**
+ * 线索优先级选项数据
+ * @readonly
+ * @type {Array<{label: string, value: number}>}
+ */
+export const LEAD_PRIORITY_OPTIONS = [
+  { label: '低', value: LEAD_PRIORITY.LOW },
+  { label: '中', value: LEAD_PRIORITY.MEDIUM },
+  { label: '高', value: LEAD_PRIORITY.HIGH }
+]
+
+/**
+ * 线索状态选项数据
+ * @readonly
+ * @type {Array<{label: string, value: number}>}
+ */
+export const LEAD_STATUS_OPTIONS = [
+  { label: '待处理', value: LEAD_STATUS.PENDING },
+  { label: '跟进中', value: LEAD_STATUS.FOLLOWING },
+  { label: '已转化', value: LEAD_STATUS.CONVERTED },
+  { label: '已关闭', value: LEAD_STATUS.CLOSED }
+]
+
+/**
+ * 获取线索优先级标签
+ * @param {number} priority - 优先级值
+ * @returns {string} 优先级标签
+ */
+export function getLeadPriorityLabel(priority) {
+  return (LEAD_PRIORITY_CONFIG[priority] && LEAD_PRIORITY_CONFIG[priority].label) || '未知优先级'
+}
+
+/**
+ * 获取线索优先级标签类型
+ * @param {number} priority - 优先级值
+ * @returns {string} Element UI标签类型
+ */
+export function getLeadPriorityType(priority) {
+    return (LEAD_PRIORITY_CONFIG[priority] && LEAD_PRIORITY_CONFIG[priority].type) || 'info'
+}
+
+/**
+ * 获取线索优先级颜色
+ * @param {number} priority - 优先级值
+ * @returns {string} 颜色值
+ */
+export function getLeadPriorityColor(priority) {
+    return (LEAD_PRIORITY_CONFIG[priority] && LEAD_PRIORITY_CONFIG[priority].color) || '#909399'
+}
+
+/**
+ * 获取线索状态标签
+ * @param {number} status - 状态值
+ * @returns {string} 状态标签
+ */
+export function getLeadStatusLabel(status) {
+  return (LEAD_STATUS_CONFIG[status] && LEAD_STATUS_CONFIG[status].label) || '未知状态'
+}
+
+/**
+ * 获取线索状态标签类型
+ * @param {number} status - 状态值
+ * @returns {string} Element UI标签类型
+ */
+export function getLeadStatusType(status) {
+  return (LEAD_STATUS_CONFIG[status] && LEAD_STATUS_CONFIG[status].type) || 'info'
+}
+
+/**
+ * 获取线索状态颜色
+ * @param {number} status - 状态值
+ * @returns {string} 颜色值
+ */
+export function getLeadStatusColor(status) {
+  return (LEAD_STATUS_CONFIG[status] && LEAD_STATUS_CONFIG[status].color) || '#909399'
+}
+
+/**
+ * 验证线索优先级值是否有效
+ * @param {number} priority - 优先级值
+ * @returns {boolean} 是否有效
+ */
+export function isValidLeadPriority(priority) {
+  return Object.values(LEAD_PRIORITY).includes(priority)
+}
+
+/**
+ * 验证线索状态值是否有效
+ * @param {number} status - 状态值
+ * @returns {boolean} 是否有效
+ */
+export function isValidLeadStatus(status) {
+  return Object.values(LEAD_STATUS).includes(status)
+}
+
+/**
+ * 判断是否为高优先级线索
+ * @param {number} priority - 优先级值
+ * @returns {boolean} 是否为高优先级
+ */
+export function isHighPriorityLead(priority) {
+  return priority === LEAD_PRIORITY.HIGH
+}
+
+/**
+ * 判断是否为低优先级线索
+ * @param {number} priority - 优先级值
+ * @returns {boolean} 是否为低优先级
+ */
+export function isLowPriorityLead(priority) {
+  return priority === LEAD_PRIORITY.LOW
+}
+
+/**
+ * 判断线索是否可以编辑
+ * @param {number} status - 状态值
+ * @returns {boolean} 是否可以编辑
+ */
+export function isLeadEditable(status) {
+  return status !== LEAD_STATUS.CLOSED
+}
+
+/**
+ * 判断线索是否可以转化
+ * @param {number} status - 状态值
+ * @returns {boolean} 是否可以转化
+ */
+export function isLeadConvertible(status) {
+  return status === LEAD_STATUS.FOLLOWING
+}
+
+/**
+ * 判断线索是否已完成(转化或关闭)
+ * @param {number} status - 状态值
+ * @returns {boolean} 是否已完成
+ */
+export function isLeadCompleted(status) {
+  return status === LEAD_STATUS.CONVERTED || status === LEAD_STATUS.CLOSED
+}
+
+/**
+ * 判断线索是否处于活跃状态(待处理或跟进中)
+ * @param {number} status - 状态值
+ * @returns {boolean} 是否处于活跃状态
+ */
+export function isLeadActive(status) {
+  return status === LEAD_STATUS.PENDING || status === LEAD_STATUS.FOLLOWING
+}
+
+/**
+ * 获取所有线索优先级值
+ * @returns {Array<number>} 所有优先级值
+ */
+export function getAllLeadPriorityValues() {
+  return Object.values(LEAD_PRIORITY)
+}
+
+/**
+ * 获取所有线索状态值
+ * @returns {Array<number>} 所有状态值
+ */
+export function getAllLeadStatusValues() {
+  return Object.values(LEAD_STATUS)
+}

+ 61 - 24
src/views/lead/mixins/leadIndex.js

@@ -2,6 +2,27 @@ import { getList, add, update, getDetail } from '@/api/order/lead'
 import { getList as getDetailList, add as addDetail, update as updateDetail, remove as removeDetail, getDetail as getDetailDetail } from '@/api/order/lead-detail'
 import { getCustomerList } from '@/api/common/index'
 import { mapGetters } from 'vuex'
+import {
+  LEAD_PRIORITY,
+  LEAD_STATUS,
+  LEAD_PRIORITY_OPTIONS,
+  LEAD_STATUS_OPTIONS,
+  getLeadPriorityLabel,
+  getLeadPriorityType,
+  getLeadPriorityColor,
+  getLeadStatusLabel,
+  getLeadStatusType,
+  getLeadStatusColor,
+  isValidLeadPriority,
+  isValidLeadStatus,
+  isHighPriorityLead,
+  isLowPriorityLead,
+  isLeadEditable,
+  isLeadConvertible,
+  isLeadCompleted,
+  isLeadActive
+} from '@/constants/lead'
+
 
 /**
  * 销售线索记录类型定义
@@ -634,12 +655,7 @@ export default {
          * @returns {string} 状态文本
          */
         getStatusText(status) {
-            const statusMap = {
-                1: '新建',
-                2: '跟进中',
-                3: '已关闭'
-            }
-            return statusMap[status] || '未知状态'
+            return getLeadStatusLabel(status)
         },
 
         /**
@@ -648,12 +664,7 @@ export default {
          * @returns {string} 标签类型
          */
         getStatusType(status) {
-            const typeMap = {
-                1: 'info',
-                2: 'warning',
-                3: 'success'
-            }
-            return typeMap[status] || 'info'
+            return getLeadStatusType(status)
         },
 
         /**
@@ -662,12 +673,7 @@ export default {
          * @returns {string} 优先级文本
          */
         getPriorityText(priority) {
-            const priorityMap = {
-                1: '高',
-                2: '中',
-                3: '低'
-            }
-            return priorityMap[priority] || '未知优先级'
+            return getLeadPriorityLabel(priority)
         },
 
         /**
@@ -676,12 +682,43 @@ export default {
          * @returns {string} 标签类型
          */
         getPriorityType(priority) {
-            const typeMap = {
-                1: 'danger',
-                2: 'warning',
-                3: 'success'
-            }
-            return typeMap[priority] || 'info'
+            return getLeadPriorityType(priority)
+        },
+
+        /**
+         * 判断线索是否可以编辑
+         * @param {number} status - 状态值
+         * @returns {boolean} 是否可以编辑
+         */
+        canEditLead(status) {
+            return isLeadEditable(status)
+        },
+
+        /**
+         * 判断线索是否可以转化
+         * @param {number} status - 状态值
+         * @returns {boolean} 是否可以转化
+         */
+        canConvertLead(status) {
+            return isLeadConvertible(status)
+        },
+
+        /**
+         * 判断是否为高优先级线索
+         * @param {number} priority - 优先级值
+         * @returns {boolean} 是否为高优先级
+         */
+        isHighPriority(priority) {
+            return isHighPriorityLead(priority)
+        },
+
+        /**
+         * 判断线索是否处于活跃状态
+         * @param {number} status - 状态值
+         * @returns {boolean} 是否处于活跃状态
+         */
+        isActiveLead(status) {
+            return isLeadActive(status)
         },
 
         /**