Browse Source

refactor(api): 重构客户相关API并统一类型定义

yz 1 month ago
parent
commit
3222f7ce00

+ 0 - 19
src/api/common/customer.js

@@ -1,19 +0,0 @@
-import request from '@/router/axios';
-
-/**
- * 获取客户列表
- * @param {import('../types/customer').CustomerQueryParams} params - 查询参数
- * @returns {Promise<import('../types/customer').CustomerListResponse>} 客户列表响应
- */
-export const getCustomerList = async (params) => {
-    return request({
-        url: '/api/blade-factory/api/factory/view-customer',
-        method: 'get',
-        params: {
-            ...params,
-            // 确保分页参数类型正确
-            size: Number(params.size),
-            current: Number(params.current)
-        }
-    });
-};

+ 10 - 170
src/api/common/index.js

@@ -1,104 +1,13 @@
 import request from '@/router/axios';
 
 /**
- * 客户查询参数类型定义
- * @typedef {Object} CustomerQueryParams
- * @property {number} [current=1] - 当前页码
- * @property {number} [size=10] - 每页数量
- * @property {string} [Customer_CODE] - 客户编码
- * @property {string} [Customer_NAME] - 客户名称
- * @property {string} [Customer_ShortName] - 客户简称
- * @property {string} [CustomerCategory_CODE] - 客户分类编码
- * @property {string} [Department_CODE] - 部门编码
- * @property {string} [Saleser_CODE] - 销售员编码
- * @property {number} [status] - 状态 0-禁用 1-启用
- */
-
-/**
- * 客户数据项类型定义
- * @typedef {Object} CustomerItem
- * @property {string} id - 客户ID
- * @property {string} createUser - 创建用户ID
- * @property {string} createDept - 创建部门ID
- * @property {string} createTime - 创建时间
- * @property {string} updateUser - 更新用户ID
- * @property {string} updateTime - 更新时间
- * @property {number} status - 状态
- * @property {number} isDeleted - 是否删除
- * @property {number} ORG_ID - 组织ID
- * @property {string} ORG_CODE - 组织编码
- * @property {string} ORG_NAME - 组织名称
- * @property {number} Customer_ID - 客户ID
- * @property {string} Customer_CODE - 客户编码
- * @property {string} Customer_NAME - 客户名称
- * @property {string} Customer_ShortName - 客户简称
- * @property {number|null} CustomerCategory_ID - 客户分类ID
- * @property {string|null} CustomerCategory_CODE - 客户分类编码
- * @property {string|null} CustomerCategory_NAME - 客户分类名称
- * @property {string} CreatedBy - 创建人
- * @property {string} CreatedOn - 创建时间
- * @property {string} ModifiedBy - 修改人
- * @property {string} ModifiedOn - 修改时间
- * @property {string} StateTaxNo - 税号
- * @property {string} BuyerNoteName - 买方备注名称
- * @property {string} BuyerBankAccount - 买方银行账户
- * @property {string} BuyerBankAccountCode - 买方银行账户编码
- * @property {string} extend9 - 扩展字段9
- * @property {number} TaxSchedule_ID - 税率表ID
- * @property {string} TaxSchedule_CODE - 税率表编码
- * @property {string} TaxSchedule_NAME - 税率表名称
- * @property {string} TaxRate - 税率
- * @property {string|null} DescFlexField_PrivateDescSeg1 - 描述弹性字段1
- * @property {string|null} DescFlexField_PrivateDescSeg2 - 描述弹性字段2
- * @property {string|null} DescFlexField_PrivateDescSeg3 - 描述弹性字段3
- * @property {number|null} Department_ID - 部门ID
- * @property {string} Department_CODE - 部门编码
- * @property {string} Department_NAME - 部门名称
- * @property {number|null} Saleser_ID - 销售员ID
- * @property {string} Saleser_CODE - 销售员编码
- * @property {string} Saleser_NAME - 销售员名称
- * @property {number} TradeCurrency_ID - 交易货币ID
- * @property {string} TradeCurrency_CODE - 交易货币编码
- * @property {string} TradeCurrency_NAME - 交易货币名称
- * @property {number} PriceList_ID - 价格表ID
- * @property {string} PriceList_CODE - 价格表编码
- * @property {string} PriceList_NAME - 价格表名称
- * @property {boolean} IsTaxPrice - 是否含税价格
- * @property {number} ShippmentRule_ID - 发货规则ID
- * @property {string} ShippmentRule_CODE - 发货规则编码
- * @property {string} ShippmentRule_NAME - 发货规则名称
- * @property {number} RecervalTerm_ID - 收款条件ID
- * @property {string} RecervalTerm_CODE - 收款条件编码
- * @property {string} RecervalTerm_NAME - 收款条件名称
- * @property {number} ARConfirmTerm_ID - 应收立账条件ID
- * @property {string} ARConfirmTerm_CODE - 应收立账条件编码
- * @property {string} ARConfirmTerm_NAME - 应收立账条件名称
- */
-
-
-/**
- * API响应数据类型定义
- * @typedef {Object} ApiResponse
- * @property {number} code - 响应码
- * @property {boolean} success - 是否成功
- * @property {string} statusText - 响应消息
- * @property {Object} data - 响应数据
- */
-
-/**
- * 分页响应数据类型定义
- * @typedef {Object} PageResponse
- * @property {CustomerItem[]} records - 数据记录
- * @property {number} total - 总记录数
- * @property {number} size - 每页数量
- * @property {number} current - 当前页码
- * @property {Array} orders - 排序信息
- * @property {boolean} optimizeCountSql - 是否优化count查询
- * @property {boolean} hitCount - 是否命中count缓存
- * @property {string|null} countId - count查询ID
- * @property {number|null} maxLimit - 最大限制
- * @property {boolean} searchCount - 是否查询count
- * @property {number} pages - 总页数
+ * @typedef {import('../types/common').CustomerQueryParams} CustomerQueryParams
+ * @typedef {import('../types/common').CustomerItem} CustomerItem
+ * @typedef {import('../types/common').CustomerListResponse} CustomerListResponse
+ * @typedef {import('../types/common').CustomerDetailResponse} CustomerDetailResponse
+ * @typedef {import('../types/common').ItemQueryParams} ItemQueryParams
+ * @typedef {import('../types/common').ItemRecord} ItemRecord
+ * @typedef {import('../types/common').ItemListResponse} ItemListResponse
  */
 
 /**
@@ -106,7 +15,7 @@ import request from '@/router/axios';
  * @param {number} [current=1] - 当前页码
  * @param {number} [size=10] - 每页数量
  * @param {CustomerQueryParams} [params={}] - 查询参数
- * @returns {Promise<ApiResponse<PageResponse>>} 客户档案列表响应
+ * @returns {Promise<CustomerListResponse>} 客户档案列表响应
  */
 export const getCustomerList = async (current = 1, size = 10, params = {}) => {
   return request({
@@ -123,7 +32,7 @@ export const getCustomerList = async (current = 1, size = 10, params = {}) => {
 /**
  * 获取客户档案详情
  * @param {string} customerId - 客户ID
- * @returns {Promise<AxiosResponse<CustomerItem>>} 客户档案详情响应
+ * @returns {Promise<CustomerDetailResponse>} 客户档案详情响应
  */
 export const getCustomerDetail = async (customerId) => {
   return request({
@@ -132,76 +41,14 @@ export const getCustomerDetail = async (customerId) => {
   });
 };
 
-/**
- * 物料查询参数类型定义
- * @typedef {Object} ItemQueryParams
- * @property {number} [current=1] - 当前页码
- * @property {number} [size=10] - 每页数量
- * @property {string} [itemName] - 物料名称(模糊查询)
- */
-
-/**
- * 物料数据项类型定义
- * @typedef {Object} ItemRecord
- * @property {string} id - 记录ID
- * @property {string} createUser - 创建用户ID
- * @property {string} createDept - 创建部门ID
- * @property {string} createTime - 创建时间
- * @property {string} updateUser - 更新用户ID
- * @property {string} updateTime - 更新时间
- * @property {number} status - 状态 1-正常 0-禁用
- * @property {number} isDeleted - 是否删除 0-未删除 1-已删除
- * @property {number} ORG_ID - 组织ID
- * @property {string} ORG_CODE - 组织编码
- * @property {string} ORG_NAME - 组织名称
- * @property {number} Item_ID - 物料ID
- * @property {string} Item_Code - 物料编码
- * @property {string} Item_Name - 物料名称
- * @property {string} Item_PECS - 物料规格
- * @property {string} Item_Description - 物料描述
- * @property {string} Item_Code1 - 物料编码1
- * @property {string} Item_Code2 - 物料编码2
- * @property {number} MainItemCategory_ID - 主物料分类ID
- * @property {string} MainItemCategory_Code - 主物料分类编码
- * @property {string} MainItemCategory_Name - 主物料分类名称
- * @property {number} InventoryInfo_ID - 库存信息ID
- * @property {string} InventoryInfo_Code - 库存信息编码
- * @property {string} InventoryInfo_Name - 库存信息名称(单位)
- * @property {number|null} Warehouse_ID - 仓库ID
- * @property {string|null} Warehouse_Code - 仓库编码
- * @property {string|null} Warehouse_Name - 仓库名称
- * @property {number|null} Saleser_ID - 销售员ID
- * @property {string|null} Saleser_CODE - 销售员编码
- * @property {string|null} Saleser_NAME - 销售员名称
- * @property {number|null} ShipmentWarehouse_ID - 发货仓库ID
- * @property {string|null} ShipmentWarehouse_Code - 发货仓库编码
- * @property {string|null} ShipmentWarehouse_Name - 发货仓库名称
- * @property {string} createdon - 创建日期
- * @property {string} ModifiedOn - 修改日期
- */
 
-/**
- * 物料分页响应数据类型定义
- * @typedef {Object} ItemPageResponse
- * @property {ItemRecord[]} records - 物料数据记录
- * @property {number} total - 总记录数
- * @property {number} size - 每页数量
- * @property {number} current - 当前页码
- * @property {Array} orders - 排序信息
- * @property {boolean} optimizeCountSql - 是否优化count查询
- * @property {boolean} hitCount - 是否命中count缓存
- * @property {string|null} countId - count查询ID
- * @property {number|null} maxLimit - 最大限制
- * @property {boolean} searchCount - 是否查询count
- * @property {number} pages - 总页数
- */
 
 /**
  * 获取物料列表
  * @param {number} [current=1] - 当前页码
  * @param {number} [size=10] - 每页数量
  * @param {ItemQueryParams} [params={}] - 查询参数
- * @returns {Promise<ApiResponse<ItemPageResponse>>} 物料列表响应
+ * @returns {Promise<ItemListResponse>} 物料列表响应
  * @description 获取物料档案列表,支持按物料名称模糊查询和分页
  * @example
  * // 获取第一页10条数据
@@ -210,13 +57,6 @@ export const getCustomerDetail = async (customerId) => {
  * // 按物料名称查询
  * const result = await getItemList(1, 10, { itemName: '炭黑' });
  */
-/**
- * 获取物料列表
- * @param {number|string} current - 当前页码
- * @param {number|string} size - 每页数量
- * @param {ItemQueryParams} params - 查询参数
- * @returns {Promise<AxiosResponse<ItemPageResponse>>} 物料列表响应
- */
 export const getItemList = async (current = 1, size = 10, params = {}) => {
   return request({
     url: '/api/blade-factory/api/factory/view-item',

+ 153 - 0
src/api/types/common.d.ts

@@ -0,0 +1,153 @@
+import { AxiosResponse } from 'axios';
+
+/**
+ * 基础查询参数接口
+ */
+export interface BaseQueryParams {
+  current?: number;
+  size?: number;
+}
+
+/**
+ * 分页结果接口
+ */
+export interface PageResult<T> {
+  records: T[];
+  total: number;
+  size: number;
+  current: number;
+  pages: number;
+  orders?: any[];
+  optimizeCountSql?: boolean;
+  hitCount?: boolean;
+  countId?: string | null;
+  maxLimit?: number | null;
+  searchCount?: boolean;
+}
+
+/**
+ * API响应数据接口
+ */
+export interface ApiResponseData<T> {
+  code: number;
+  success: boolean;
+  statusText: string;
+  data: T;
+}
+
+/**
+ * 客户查询参数接口
+ */
+export interface CustomerQueryParams extends BaseQueryParams {
+  customerCode?: string;
+  customerName?: string;
+  customerShortName?: string;
+  customerCategoryCode?: string;
+  departmentCode?: string;
+  saleserCode?: string;
+  status?: number;
+}
+
+/**
+ * 客户数据项接口
+ */
+export interface CustomerItem {
+  id: string;
+  createUser: string;
+  createDept: string;
+  createTime: string;
+  updateUser: string;
+  updateTime: string;
+  status: number;
+  isDeleted: number;
+  ORG_ID: number;
+  ORG_CODE: string;
+  ORG_NAME: string;
+  Customer_ID: number;
+  Customer_CODE: string;
+  Customer_NAME: string;
+  Customer_ShortName: string;
+  CustomerCategory_ID: number | null;
+  CustomerCategory_CODE: string | null;
+  CustomerCategory_NAME: string | null;
+  CreatedBy: string;
+  CreatedOn: string;
+  ModifiedBy: string;
+  ModifiedOn: string;
+  StateTaxNo: string;
+  BuyerNoteName: string;
+  BuyerBankAccount: string;
+  BuyerBankAccountCode: string;
+  extend9: string;
+  TaxSchedule_ID: number;
+  TaxSchedule_CODE: string;
+  TaxSchedule_NAME: string;
+  TaxRate: string;
+  DescFlexField_PrivateDescSeg1: string | null;
+  DescFlexField_PrivateDescSeg2: string | null;
+  DescFlexField_PrivateDescSeg3: string | null;
+  Department_ID: number | null;
+  Department_CODE: string;
+  Department_NAME: string;
+  Saleser_ID: number | null;
+  Saleser_CODE: string;
+  Saleser_NAME: string;
+  TradeCurrency_ID: number;
+  TradeCurrency_CODE: string;
+  TradeCurrency_NAME: string;
+  PriceList_ID: number;
+  PriceList_CODE: string;
+  PriceList_NAME: string;
+  IsTaxPrice: boolean;
+  ShippmentRule_ID: number;
+  ShippmentRule_CODE: string;
+  ShippmentRule_NAME: string;
+  RecervalTerm_ID: number;
+  RecervalTerm_CODE: string;
+  RecervalTerm_NAME: string;
+  ARConfirmTerm_ID: number;
+  ARConfirmTerm_CODE: string;
+  ARConfirmTerm_NAME: string;
+}
+
+/**
+ * 物料查询参数接口
+ */
+export interface ItemQueryParams extends BaseQueryParams {
+  itemCode?: string;
+  itemName?: string;
+  specs?: string;
+  category?: string;
+}
+
+/**
+ * 物料数据项接口
+ */
+export interface ItemRecord {
+  id: string;
+  itemCode: string;
+  itemName: string;
+  specs: string;
+  unit: string;
+  category: string;
+  brand: string;
+  model: string;
+  description: string;
+  unitPrice: string;
+  remark: string;
+}
+
+/**
+ * 客户列表响应类型
+ */
+export type CustomerListResponse = AxiosResponse<ApiResponseData<PageResult<CustomerItem>>>;
+
+/**
+ * 客户详情响应类型
+ */
+export type CustomerDetailResponse = AxiosResponse<ApiResponseData<CustomerItem>>;
+
+/**
+ * 物料列表响应类型
+ */
+export type ItemListResponse = AxiosResponse<ApiResponseData<PageResult<ItemRecord>>>;

+ 0 - 53
src/api/types/common.js

@@ -1,53 +0,0 @@
-/**
- * 公共API类型定义
- * @fileoverview 提供通用的API响应和分页类型定义,避免重复定义
- */
-
-/**
- * API响应类型定义
- * @template T
- * @typedef {Object} ApiResponse
- * @property {number} code - 响应码
- * @property {boolean} success - 是否成功
- * @property {T} data - 响应数据
- * @property {string} msg - 响应消息
- */
-
-/**
- * 分页结果类型定义
- * @template T
- * @typedef {Object} PageResult
- * @property {T[]} records - 数据记录
- * @property {number} total - 总记录数
- * @property {number} size - 每页大小
- * @property {number} current - 当前页码
- * @property {Array} orders - 排序信息
- * @property {boolean} optimizeCountSql - 是否优化count查询
- * @property {boolean} hitCount - 是否命中count缓存
- * @property {string|null} countId - count查询ID
- * @property {string|null} maxLimit - 最大限制
- * @property {boolean} searchCount - 是否查询count
- * @property {number} pages - 总页数
- */
-
-/**
- * 基础查询参数类型定义
- * @typedef {Object} BaseQueryParams
- * @property {number} current - 当前页码
- * @property {number} size - 每页大小
- */
-
-/**
- * 基础实体类型定义
- * @typedef {Object} BaseEntity
- * @property {string} id - 主键ID
- * @property {string} createUser - 创建用户ID
- * @property {string} createDept - 创建部门ID
- * @property {string} createTime - 创建时间
- * @property {string} updateUser - 更新用户ID
- * @property {string} updateTime - 更新时间
- * @property {0|1} status - 状态 1-正常 0-禁用
- * @property {0|1} isDeleted - 是否删除 0-未删除 1-已删除
- */
-
-export {}

+ 0 - 60
src/api/types/customer.d.ts

@@ -1,60 +0,0 @@
-import { AxiosResponse } from 'axios';
-
-/**
- * 基础查询参数接口
- */
-export interface BaseQueryParams {
-  current?: number;
-  size?: number;
-}
-
-/**
- * 分页结果接口
- */
-export interface PageResult<T> {
-  records: T[];
-  total: number;
-  size: number;
-  current: number;
-  pages: number;
-}
-
-/**
- * API响应数据接口
- */
-export interface ApiResponseData<T> {
-  code: number;
-  msg: string;
-  success: boolean;
-  data: T;
-}
-
-/**
- * 客户查询参数接口
- */
-export interface CustomerQueryParams extends BaseQueryParams {
-  customerName?: string;
-}
-
-/**
- * 客户记录接口
- */
-export interface CustomerRecord {
-  id: string;
-  ORG_ID: number;
-  Customer_ID: number;
-  Customer_CODE: string;
-  Customer_NAME: string;
-  Customer_ShortName: string;
-  TaxSchedule_NAME: string;
-  TaxRate: number;
-  TradeCurrency_NAME: string;
-  ShippmentRule_NAME: string;
-  RecervalTerm_NAME: string;
-  CreatedOn: string;
-}
-
-/**
- * 客户列表响应接口
- */
-export type CustomerListResponse = AxiosResponse<ApiResponseData<PageResult<CustomerRecord>>>;

+ 4 - 14
src/components/common/customer-select.vue

@@ -28,7 +28,7 @@
 </template>
 
 <script>
-import { getCustomerList } from '@/api/common/customer'
+import { getCustomerList } from '@/api/common/index'
 import { COMMON_EVENTS, CUSTOMER_SELECT_EVENTS } from './events'
 
 /**
@@ -224,13 +224,9 @@ export default {
       try {
         this.loading = true
         
-        const queryParams = {
-          current: 1,
-          size: 20,
+        const response = await getCustomerList(1, 20, {
           customerName: keyword
-        }
-        
-        const response = await getCustomerList(queryParams)
+        })
         
         if (response?.data?.success && response.data.data?.records) {
           this.options = response.data.data.records
@@ -264,13 +260,7 @@ export default {
       try {
         this.loading = true
         
-        const queryParams = {
-          current: 1,
-          size: 200, // 增加查询范围以确保找到目标客户
-          customerName: '' // 空字符串获取所有客户
-        }
-        
-        const response = await getCustomerList(queryParams)
+        const response = await getCustomerList(1, 200, {})
         
         if (response?.data?.success && response.data.data?.records) {
           const allCustomers = response.data.data.records

+ 5 - 17
src/components/order-form/customer-select.vue

@@ -28,7 +28,7 @@
 </template>
 
 <script>
-import { getCustomerList } from '@/api/common/customer'
+import { getCustomerList } from '@/api/common/index'
 import { COMMON_EVENTS, CUSTOMER_SELECT_EVENTS } from './events'
 
 /**
@@ -241,15 +241,10 @@ export default {
       try {
         this.loading = true
         
-        /** @type {CustomerQueryParams} */
-        const queryParams = {
-          current: 1,
-          size: 20,
-          customerName: keyword
-        }
-        
         /** @type {CustomerListResponse} */
-        const response = await getCustomerList(queryParams)
+        const response = await getCustomerList(1, 20, {
+          customerName: keyword
+        })
         
         if (response?.data?.success && response.data.data?.records) {
           this.options = response.data.data.records
@@ -283,15 +278,8 @@ export default {
       try {
         this.loading = true
         
-        /** @type {CustomerQueryParams} */
-        const queryParams = {
-          current: 1,
-          size: 200, // 增加查询范围以确保找到目标客户
-          customerName: '' // 空字符串获取所有客户
-        }
-        
         /** @type {CustomerListResponse} */
-        const response = await getCustomerList(queryParams)
+        const response = await getCustomerList(1, 200, {})
         
         if (response?.data?.success && response.data.data?.records) {
           const allCustomers = response.data.data.records

+ 2 - 4
src/views/announcement/mixins/announcementIndex.js

@@ -1,5 +1,5 @@
 import { getList, update, add, getAnnouncement, getCategoryList } from "@/api/announcement";
-import { getCustomerList } from "@/api/common/customer";
+import { getCustomerList } from "@/api/common/index";
 import { mapGetters } from "vuex";
 import {
     ROLE_OPTIONS,
@@ -782,9 +782,7 @@ export default {
 
             this.customerOptionsLoading = true;
             try {
-                const response = await getCustomerList({
-                    current: 1,
-                    size: 50,
+                const response = await getCustomerList(1, 50, {
                     customerName: query.trim()
                 });