Ver Fonte

feat(complaint): 添加投诉管理常量定义和工具函数

yz há 3 semanas atrás
pai
commit
e91834b8dd
3 ficheiros alterados com 492 adições e 80 exclusões
  1. 435 0
      src/constants/complaint.js
  2. 4 1
      src/constants/index.js
  3. 53 79
      src/views/complaint/index.vue

+ 435 - 0
src/constants/complaint.js

@@ -0,0 +1,435 @@
+/**
+ * 投诉管理相关常量定义
+ * @fileoverview 投诉人类型、投诉类型、投诉状态、回复状态等枚举值和工具函数
+ */
+
+/**
+ * 投诉人类型枚举
+ * @readonly
+ * @enum {number}
+ */
+export const COMPLAINANT_TYPE = {
+  /** 终端消费者 */
+  CONSUMER: 1,
+  /** 门店 */
+  STORE: 2,
+  /** 经销商 */
+  DEALER: 3
+}
+
+/**
+ * 投诉类型枚举
+ * @readonly
+ * @enum {string}
+ */
+export const COMPLAINT_TYPE = {
+  /** 质量问题 */
+  QUALITY: '质量',
+  /** 物流问题 */
+  LOGISTICS: '物流',
+  /** 服务问题 */
+  SERVICE: '服务',
+  /** 价格问题 */
+  PRICE: '价格',
+  /** 其他问题 */
+  OTHER: '其他'
+}
+
+/**
+ * 投诉状态枚举
+ * @readonly
+ * @enum {number}
+ */
+export const COMPLAINT_STATUS = {
+  /** 待处理 */
+  PENDING: 0,
+  /** 处理中 */
+  PROCESSING: 1,
+  /** 已回复 */
+  REPLIED: 2,
+  /** 已关闭 */
+  CLOSED: 3,
+  /** 已撤销 */
+  CANCELLED: 4
+}
+
+/**
+ * 回复状态枚举
+ * @readonly
+ * @enum {number}
+ */
+export const REPLY_STATUS = {
+  /** 未回复 */
+  NOT_REPLIED: 0,
+  /** 已回复 */
+  REPLIED: 1
+}
+
+/**
+ * 投诉人类型配置映射
+ * @readonly
+ * @type {Record<number, {label: string, type: string, color: string}>}
+ */
+export const COMPLAINANT_TYPE_CONFIG = {
+  [COMPLAINANT_TYPE.CONSUMER]: {
+    label: '终端消费者',
+    type: 'primary',
+    color: '#409EFF'
+  },
+  [COMPLAINANT_TYPE.STORE]: {
+    label: '门店',
+    type: 'success',
+    color: '#67C23A'
+  },
+  [COMPLAINANT_TYPE.DEALER]: {
+    label: '经销商',
+    type: 'warning',
+    color: '#E6A23C'
+  }
+}
+
+/**
+ * 投诉类型配置映射
+ * @readonly
+ * @type {Record<string, {label: string, type: string, color: string}>}
+ */
+export const COMPLAINT_TYPE_CONFIG = {
+  [COMPLAINT_TYPE.QUALITY]: {
+    label: '质量',
+    type: 'danger',
+    color: '#F56C6C'
+  },
+  [COMPLAINT_TYPE.LOGISTICS]: {
+    label: '物流',
+    type: 'warning',
+    color: '#E6A23C'
+  },
+  [COMPLAINT_TYPE.SERVICE]: {
+    label: '服务',
+    type: 'primary',
+    color: '#409EFF'
+  },
+  [COMPLAINT_TYPE.PRICE]: {
+    label: '价格',
+    type: 'info',
+    color: '#909399'
+  },
+  [COMPLAINT_TYPE.OTHER]: {
+    label: '其他',
+    type: 'info',
+    color: '#909399'
+  }
+}
+
+/**
+ * 投诉状态配置映射
+ * @readonly
+ * @type {Record<number, {label: string, type: string, color: string}>}
+ */
+export const COMPLAINT_STATUS_CONFIG = {
+  [COMPLAINT_STATUS.PENDING]: {
+    label: '待处理',
+    type: 'warning',
+    color: '#E6A23C'
+  },
+  [COMPLAINT_STATUS.PROCESSING]: {
+    label: '处理中',
+    type: 'primary',
+    color: '#409EFF'
+  },
+  [COMPLAINT_STATUS.REPLIED]: {
+    label: '已回复',
+    type: 'success',
+    color: '#67C23A'
+  },
+  [COMPLAINT_STATUS.CLOSED]: {
+    label: '已关闭',
+    type: 'info',
+    color: '#909399'
+  },
+  [COMPLAINT_STATUS.CANCELLED]: {
+    label: '已撤销',
+    type: 'danger',
+    color: '#F56C6C'
+  }
+}
+
+/**
+ * 回复状态配置映射
+ * @readonly
+ * @type {Record<number, {label: string, type: string, color: string}>}
+ */
+export const REPLY_STATUS_CONFIG = {
+  [REPLY_STATUS.NOT_REPLIED]: {
+    label: '未回复',
+    type: 'info',
+    color: '#909399'
+  },
+  [REPLY_STATUS.REPLIED]: {
+    label: '已回复',
+    type: 'success',
+    color: '#67C23A'
+  }
+}
+
+/**
+ * 投诉人类型选项数据
+ * @readonly
+ * @type {Array<{label: string, value: number}>}
+ */
+export const COMPLAINANT_TYPE_OPTIONS = [
+  { label: '终端消费者', value: COMPLAINANT_TYPE.CONSUMER },
+  { label: '门店', value: COMPLAINANT_TYPE.STORE },
+  { label: '经销商', value: COMPLAINANT_TYPE.DEALER }
+]
+
+/**
+ * 投诉类型选项数据
+ * @readonly
+ * @type {Array<{label: string, value: string}>}
+ */
+export const COMPLAINT_TYPE_OPTIONS = [
+  { label: '质量', value: COMPLAINT_TYPE.QUALITY },
+  { label: '物流', value: COMPLAINT_TYPE.LOGISTICS },
+  { label: '服务', value: COMPLAINT_TYPE.SERVICE },
+  { label: '价格', value: COMPLAINT_TYPE.PRICE },
+  { label: '其他', value: COMPLAINT_TYPE.OTHER }
+]
+
+/**
+ * 投诉状态选项数据
+ * @readonly
+ * @type {Array<{label: string, value: number}>}
+ */
+export const COMPLAINT_STATUS_OPTIONS = [
+  { label: '待处理', value: COMPLAINT_STATUS.PENDING },
+  { label: '处理中', value: COMPLAINT_STATUS.PROCESSING },
+  { label: '已回复', value: COMPLAINT_STATUS.REPLIED },
+  { label: '已关闭', value: COMPLAINT_STATUS.CLOSED },
+  { label: '已撤销', value: COMPLAINT_STATUS.CANCELLED }
+]
+
+/**
+ * 回复状态选项数据
+ * @readonly
+ * @type {Array<{label: string, value: number}>}
+ */
+export const REPLY_STATUS_OPTIONS = [
+  { label: '未回复', value: REPLY_STATUS.NOT_REPLIED },
+  { label: '已回复', value: REPLY_STATUS.REPLIED }
+]
+
+/**
+ * 获取投诉人类型标签
+ * @param {number} complainantType - 投诉人类型值
+ * @returns {string} 投诉人类型标签
+ */
+export function getComplainantTypeLabel(complainantType) {
+  const config = COMPLAINANT_TYPE_CONFIG[complainantType]
+  return config ? config.label : '未知类型'
+}
+
+/**
+ * 获取投诉人类型Element UI标签类型
+ * @param {number} complainantType - 投诉人类型值
+ * @returns {string} Element UI标签类型
+ */
+export function getComplainantTypeType(complainantType) {
+  const config = COMPLAINANT_TYPE_CONFIG[complainantType]
+  return config ? config.type : 'info'
+}
+
+/**
+ * 获取投诉人类型颜色
+ * @param {number} complainantType - 投诉人类型值
+ * @returns {string} 十六进制颜色值
+ */
+export function getComplainantTypeColor(complainantType) {
+  const config = COMPLAINANT_TYPE_CONFIG[complainantType]
+  return config ? config.color : '#909399'
+}
+
+/**
+ * 获取投诉类型标签
+ * @param {string} complaintType - 投诉类型值
+ * @returns {string} 投诉类型标签
+ */
+export function getComplaintTypeLabel(complaintType) {
+  const config = COMPLAINT_TYPE_CONFIG[complaintType]
+  return config ? config.label : '未知类型'
+}
+
+/**
+ * 获取投诉类型Element UI标签类型
+ * @param {string} complaintType - 投诉类型值
+ * @returns {string} Element UI标签类型
+ */
+export function getComplaintTypeType(complaintType) {
+  const config = COMPLAINT_TYPE_CONFIG[complaintType]
+  return config ? config.type : 'info'
+}
+
+/**
+ * 获取投诉类型颜色
+ * @param {string} complaintType - 投诉类型值
+ * @returns {string} 十六进制颜色值
+ */
+export function getComplaintTypeColor(complaintType) {
+  const config = COMPLAINT_TYPE_CONFIG[complaintType]
+  return config ? config.color : '#909399'
+}
+
+/**
+ * 获取投诉状态标签
+ * @param {number} status - 投诉状态值
+ * @returns {string} 投诉状态标签
+ */
+export function getComplaintStatusLabel(status) {
+  const config = COMPLAINT_STATUS_CONFIG[status]
+  return config ? config.label : '未知状态'
+}
+
+/**
+ * 获取投诉状态Element UI标签类型
+ * @param {number} status - 投诉状态值
+ * @returns {string} Element UI标签类型
+ */
+export function getComplaintStatusType(status) {
+  const config = COMPLAINT_STATUS_CONFIG[status]
+  return config ? config.type : 'info'
+}
+
+/**
+ * 获取投诉状态颜色
+ * @param {number} status - 投诉状态值
+ * @returns {string} 十六进制颜色值
+ */
+export function getComplaintStatusColor(status) {
+  const config = COMPLAINT_STATUS_CONFIG[status]
+  return config ? config.color : '#909399'
+}
+
+/**
+ * 获取回复状态标签
+ * @param {number} replyStatus - 回复状态值
+ * @returns {string} 回复状态标签
+ */
+export function getReplyStatusLabel(replyStatus) {
+  const config = REPLY_STATUS_CONFIG[replyStatus]
+  return config ? config.label : '未知状态'
+}
+
+/**
+ * 获取回复状态Element UI标签类型
+ * @param {number} replyStatus - 回复状态值
+ * @returns {string} Element UI标签类型
+ */
+export function getReplyStatusType(replyStatus) {
+  const config = REPLY_STATUS_CONFIG[replyStatus]
+  return config ? config.type : 'info'
+}
+
+/**
+ * 获取回复状态颜色
+ * @param {number} replyStatus - 回复状态值
+ * @returns {string} 十六进制颜色值
+ */
+export function getReplyStatusColor(replyStatus) {
+  const config = REPLY_STATUS_CONFIG[replyStatus]
+  return config ? config.color : '#909399'
+}
+
+/**
+ * 验证投诉人类型是否有效
+ * @param {number} complainantType - 投诉人类型值
+ * @returns {boolean} 是否为有效投诉人类型
+ */
+export function isValidComplainantType(complainantType) {
+  return Object.values(COMPLAINANT_TYPE).includes(complainantType)
+}
+
+/**
+ * 验证投诉类型是否有效
+ * @param {string} complaintType - 投诉类型值
+ * @returns {boolean} 是否为有效投诉类型
+ */
+export function isValidComplaintType(complaintType) {
+  return Object.values(COMPLAINT_TYPE).includes(complaintType)
+}
+
+/**
+ * 验证投诉状态是否有效
+ * @param {number} status - 投诉状态值
+ * @returns {boolean} 是否为有效投诉状态
+ */
+export function isValidComplaintStatus(status) {
+  return Object.values(COMPLAINT_STATUS).includes(status)
+}
+
+/**
+ * 验证回复状态是否有效
+ * @param {number} replyStatus - 回复状态值
+ * @returns {boolean} 是否为有效回复状态
+ */
+export function isValidReplyStatus(replyStatus) {
+  return Object.values(REPLY_STATUS).includes(replyStatus)
+}
+
+/**
+ * 获取所有投诉人类型值
+ * @returns {Array<number>} 投诉人类型值数组
+ */
+export function getAllComplainantTypeValues() {
+  return Object.values(COMPLAINANT_TYPE)
+}
+
+/**
+ * 获取所有投诉类型值
+ * @returns {Array<string>} 投诉类型值数组
+ */
+export function getAllComplaintTypeValues() {
+  return Object.values(COMPLAINT_TYPE)
+}
+
+/**
+ * 获取所有投诉状态值
+ * @returns {Array<number>} 投诉状态值数组
+ */
+export function getAllComplaintStatusValues() {
+  return Object.values(COMPLAINT_STATUS)
+}
+
+/**
+ * 获取所有回复状态值
+ * @returns {Array<number>} 回复状态值数组
+ */
+export function getAllReplyStatusValues() {
+  return Object.values(REPLY_STATUS)
+}
+
+/**
+ * 判断投诉状态是否可以编辑
+ * @param {number} status - 投诉状态值
+ * @returns {boolean} 是否可以编辑
+ */
+export function isComplaintEditable(status) {
+  return status !== COMPLAINT_STATUS.CANCELLED && status !== COMPLAINT_STATUS.CLOSED
+}
+
+/**
+ * 判断投诉状态是否可以处理
+ * @param {number} status - 投诉状态值
+ * @returns {boolean} 是否可以处理
+ */
+export function isComplaintProcessable(status) {
+  return status === COMPLAINT_STATUS.PROCESSING
+}
+
+/**
+ * 判断投诉状态是否可以关闭
+ * @param {number} status - 投诉状态值
+ * @returns {boolean} 是否可以关闭
+ */
+export function isComplaintClosable(status) {
+  return status !== COMPLAINT_STATUS.CANCELLED && status !== COMPLAINT_STATUS.CLOSED
+}

+ 4 - 1
src/constants/index.js

@@ -6,4 +6,7 @@
 export * from './shipment'
 
 // 理赔管理相关常量
-export * from './claim'
+export * from './claim'
+
+// 投诉管理相关常量
+export * from './complaint'

+ 53 - 79
src/views/complaint/index.vue

@@ -43,24 +43,29 @@
       
       <template slot="status" slot-scope="{row}">
         <el-tag
-          :type="getStatusType(row.status)"
+          :type="getComplaintStatusType(row.status)"
           size="small"
         >
-          {{ getStatusText(row.status) }}
+          {{ getComplaintStatusLabel(row.status) }}
         </el-tag>
       </template>
       
       <template slot="replyStatus" slot-scope="{row}">
         <el-tag
-          :type="row.replyStatus === 1 ? 'success' : 'info'"
+          :type="getReplyStatusType(row.replyStatus)"
           size="small"
         >
-          {{ row.replyStatus === 1 ? '已回复' : '未回复' }}
+          {{ getReplyStatusLabel(row.replyStatus) }}
         </el-tag>
       </template>
       
       <template slot="complainantType" slot-scope="{row}">
-        <span>{{ getComplainantTypeText(row.complainantType) }}</span>
+        <el-tag
+          :type="getComplainantTypeType(row.complainantType)"
+          size="small"
+        >
+          {{ getComplainantTypeLabel(row.complainantType) }}
+        </el-tag>
       </template>
       
       <template slot="menu" slot-scope="{row}">
@@ -76,7 +81,7 @@
           type="text"
           size="small"
           icon="el-icon-edit"
-          v-if="permission.complaint_edit && row.status !== 4"
+          v-if="permission.complaint_edit && isComplaintEditable(row.status)"
           @click="handleEdit(row)"
         >
           编辑
@@ -85,7 +90,7 @@
           type="text"
           size="small"
           icon="el-icon-check"
-          v-if="permission.complaint_edit && row.status === 1"
+          v-if="permission.complaint_edit && isComplaintProcessable(row.status)"
           @click="handleProcess(row)"
         >
           处理
@@ -94,7 +99,7 @@
           type="text"
           size="small"
           icon="el-icon-close"
-          v-if="permission.complaint_edit && row.status !== 4"
+          v-if="permission.complaint_edit && isComplaintClosable(row.status)"
           @click="handleClose(row)"
         >
           关闭
@@ -269,6 +274,24 @@
 <script>
 import { getList, add, update, remove, getDetail, updateStatus, batchUpdateStatus } from '@/api/complaint'
 import { mapGetters } from 'vuex'
+import {
+  COMPLAINANT_TYPE_OPTIONS,
+  COMPLAINT_TYPE_OPTIONS,
+  COMPLAINT_STATUS_OPTIONS,
+  REPLY_STATUS_OPTIONS,
+  getComplainantTypeLabel,
+  getComplaintTypeLabel,
+  getComplainantTypeType,
+  getComplaintStatusLabel,
+  getComplaintStatusType,
+  getReplyStatusLabel,
+  getReplyStatusType,
+  isComplaintEditable,
+  isComplaintProcessable,
+  isComplaintClosable,
+  isValidComplaintStatus,
+  isValidReplyStatus
+} from '@/constants/complaint'
 
 /**
  * 投诉查询参数类型定义
@@ -365,11 +388,7 @@ export default {
             slot: true,
             search: true,
             type: 'select',
-            dicData: [
-              { label: '消费者', value: 1 },
-              { label: '经销商', value: 2 },
-              { label: '分销商', value: 3 }
-            ]
+            dicData: COMPLAINANT_TYPE_OPTIONS
           },
           {
             label: '客户名称',
@@ -396,13 +415,7 @@ export default {
             minWidth: 100,
             search: true,
             type: 'select',
-            dicData: [
-              { label: '质量', value: '质量' },
-              { label: '物流', value: '物流' },
-              { label: '服务', value: '服务' },
-              { label: '价格', value: '价格' },
-              { label: '其他', value: '其他' }
-            ]
+            dicData: COMPLAINT_TYPE_OPTIONS
           },
           {
             label: '投诉状态',
@@ -411,12 +424,7 @@ export default {
             slot: true,
             search: true,
             type: 'select',
-            dicData: [
-              { label: '待处理', value: 1 },
-              { label: '处理中', value: 2 },
-              { label: '已完成', value: 3 },
-              { label: '已关闭', value: 4 }
-            ]
+            dicData: COMPLAINT_STATUS_OPTIONS
           },
           {
             label: '回复状态',
@@ -425,10 +433,7 @@ export default {
             slot: true,
             search: true,
             type: 'select',
-            dicData: [
-              { label: '未回复', value: 0 },
-              { label: '已回复', value: 1 }
-            ]
+            dicData: REPLY_STATUS_OPTIONS
           },
           {
             label: '提交时间',
@@ -470,55 +475,24 @@ export default {
     }
   },
   methods: {
-    /**
-     * 获取投诉状态文本
-     * @param {number} status - 状态值
-     * @returns {string} 状态文本
-     */
-    getStatusText(status) {
-      const statusMap = {
-        1: '待处理',
-        2: '处理中',
-        3: '已完成',
-        4: '已关闭'
-      }
-      return statusMap[status] || '未知'
-    },
-    
-    /**
-     * 获取投诉状态标签类型
-     * @param {number} status - 状态值
-     * @returns {string} 标签类型
-     */
-    getStatusType(status) {
-      const typeMap = {
-        1: 'warning',
-        2: 'primary',
-        3: 'success',
-        4: 'info'
-      }
-      return typeMap[status] || 'info'
-    },
-    
-    /**
-     * 获取投诉人类型文本
-     * @param {number} type - 类型值
-     * @returns {string} 类型文本
-     */
-    getComplainantTypeText(type) {
-      const typeMap = {
-        1: '消费者',
-        2: '经销商',
-        3: '分销商'
-      }
-      return typeMap[type] || '未知'
-    },
+
+    // 导入工具函数
+    getComplainantTypeLabel,
+    getComplainantTypeType,
+    getComplaintTypeLabel,
+    getComplaintStatusLabel,
+    getComplaintStatusType,
+    getReplyStatusLabel,
+    getReplyStatusType,
+    isComplaintEditable,
+    isComplaintProcessable,
+    isComplaintClosable,
     
     /**
      * 行保存
      * @param {ComplaintForm} row - 表单数据
-     * @param {boolean} done - 完成回调
-     * @param {boolean} loading - 加载状态回调
+     * @param {Function} done - 完成回调
+     * @param {Function} loading - 加载状态回调
      */
     async rowSave(row, done, loading) {
       try {
@@ -543,8 +517,8 @@ export default {
      * 行更新
      * @param {ComplaintForm} row - 表单数据
      * @param {number} index - 行索引
-     * @param {boolean} done - 完成回调
-     * @param {boolean} loading - 加载状态回调
+     * @param {Function} done - 完成回调
+     * @param {Function} loading - 加载状态回调
      */
     async rowUpdate(row, index, done, loading) {
       try {
@@ -559,12 +533,12 @@ export default {
           loading()
         }
       } catch (error) {
-        console.error('修改投诉失败:', error)
+        console.error('更新投诉失败:', error)
         this.$message.error('操作失败')
         loading()
       }
     },
-    
+
     /**
      * 行删除
      * @param {ComplaintRecord} row - 行数据