소스 검색

fix(announcement): 修复客户黑名单数据处理和角色掩码转换问题

yz 2 일 전
부모
커밋
66793474d0
2개의 변경된 파일22개의 추가작업 그리고 20개의 파일을 삭제
  1. 1 1
      src/api/types/announcement.d.ts
  2. 21 19
      src/views/announcement/mixins/announcementIndex.js

+ 1 - 1
src/api/types/announcement.d.ts

@@ -192,4 +192,4 @@ export type NoticeDetailResponse = Promise<ApiResponse<NoticeRecord>>;
 export type NoticeOperationResponse = Promise<ApiResponse<boolean>>;
 
 export type DealerListResponse = Promise<ApiResponse<Array<DealerOption>>>;
-export type BrandListResponse = Promise<ApiResponse<Array<BrandOption>>>;
+export type BrandListResponse = Promise<ApiResponse<Array<BrandOption>>>;

+ 21 - 19
src/views/announcement/mixins/announcementIndex.js

@@ -5,7 +5,7 @@
  */
 
 /**
- * @typedef {import('@/views/announcement/types').NoticeRecord} NoticeRecord
+ * @typedef {import("@/api/announcement").NoticeRecord} NoticeRecord
  */
 
 import { getList, update, add, getAnnouncement, getCategoryList } from "@/api/announcement";
@@ -454,7 +454,7 @@ export default {
 
             try {
                 const response = await getAnnouncement(this.selectionList[0].id);
-                
+
                 this.currentDetail = response.data?.data || {};
                 this.detailVisible = true;
             } catch (error) {
@@ -493,7 +493,7 @@ export default {
                 let rolesMask;
                 if (Array.isArray(row.visibleRoles)) {
                     // 如果是数组,需要检查是RoleType[]还是RoleOption[]
-                    const roleValues = row.visibleRoles.map(role => 
+                    const roleValues = row.visibleRoles.map(role =>
                         typeof role === 'object' ? role.value : role
                     );
                     rolesMask = this.calculateRolesMask(roleValues);
@@ -515,14 +515,14 @@ export default {
                     orgCode: this.userInfo?.orgCode || row.orgCode,
                     orgName: this.userInfo?.orgName || row.orgName,
                     brandScope: row.brandScope || undefined,
-                    customerBlacklist: filteredCustomerBlacklist.map(customer => ({
+                    customerBlacklist: JSON.stringify(filteredCustomerBlacklist.map(customer => ({
                         ...customer,
                         ID: customer.id,
                         CODE: customer.Customer_CODE,
                         NAME: customer.Customer_NAME
-                    })),
+                    }))),
                     remark: row.remark || '',
-                    visibleRoles: rolesMask,
+                    visibleRoles: rolesMask.toString(),
                     status: row.status !== undefined ? row.status : ANNOUNCEMENT_STATUS.DRAFT,
                 };
 
@@ -583,7 +583,7 @@ export default {
                 let rolesMask;
                 if (Array.isArray(row.visibleRoles)) {
                     // 如果是数组,需要检查是RoleType[]还是RoleOption[]
-                    const roleValues = row.visibleRoles.map(role => 
+                    const roleValues = row.visibleRoles.map(role =>
                         typeof role === 'object' ? role.value : role
                     );
                     rolesMask = this.calculateRolesMask(roleValues);
@@ -598,7 +598,9 @@ export default {
                 }
 
                 // 处理客户黑名单数据
-                
+
+                console.log('aaa', this.currentCustomerBlacklist)
+                console.log('aaa', row.customerBlacklist)
                 const filteredCustomerBlacklist = this.currentCustomerBlacklist.filter((/** @type {CustomerBlacklistOption} */ customer) => {
                     const selectedIds = (row.customerBlacklist || []).map((/** @type {CustomerBlacklistOption} */ item) => item.id);
                     return selectedIds.includes(customer.id);
@@ -609,16 +611,16 @@ export default {
                 const formData = {
                     ...row,
                     brandScope: row.brandScope || undefined,
-                    customerBlacklist: filteredCustomerBlacklist.map(customer => ({
-                        ...customer,
+                    customerBlacklist: JSON.stringify(filteredCustomerBlacklist.map(customer => ({
                         ID: customer.id,
                         CODE: customer.Customer_CODE,
                         NAME: customer.Customer_NAME
-                    })),
+                    }))),
                     remark: row.remark || '',
-                    visibleRoles: rolesMask
+                    visibleRoles: rolesMask.toString()
                 };
 
+                console.log(formData)
                 await update(formData);
                 await this.onLoad(this.page);
                 this.$message({
@@ -715,9 +717,9 @@ export default {
                     }
 
                     const response = await getAnnouncement(this.form.id);
-                    
+
                     const formData = response.data?.data || {};
-                     
+
                     /** @type {{visibleRoles: Array<RoleType>, customerBlackList: Array<import("@/views/announcement/types").CustomerBlacklistItem>, BrandScope: Array<import("@/api/types/announcement").BrandScopeItem>}} */
                     const convertType = {
                         visibleRoles: [],
@@ -736,7 +738,7 @@ export default {
                     } else {
                         convertType.visibleRoles = [];
                     }
-                    
+
                     // 确保客户黑名单是数组格式
                     /** @type {Array<import("@/views/announcement/types").CustomerBlacklistItem>} */
                     const tmpCustomerData  = JSON.parse(formData.customerBlacklist || '[]')
@@ -842,7 +844,7 @@ export default {
          * @throws {Error} 当搜索客户失败时抛出错误
          */
         async remoteSearchCustomers(query) {
-            if (!query || typeof query !== 'string' || query.trim().length < 2) {
+            if (!query || typeof query !== 'string' || query.trim().length < 1) {
                 /** @type {Array<CustomerBlacklistOption>} */
                 this.customerBlacklistOptions = [];
                 return;
@@ -857,7 +859,7 @@ export default {
                 if (response.data && response.data.success && response.data.data) {
                     const customers = response.data.data.records || [];
                     this.currentCustomerBlacklist = customers.map(c => ({
-                        id: c.id ? parseInt(c.id) : 0,
+                        id: c.Customer_ID,
                         Customer_NAME: c.Customer_NAME,
                         Customer_CODE: c.Customer_CODE,
                         Customer_ShortName: c.Customer_ShortName
@@ -865,7 +867,7 @@ export default {
 
 
                     this.customerBlacklistOptions = customers.map(customer => ({
-                        id: customer.id ? parseInt(customer.id) : 0,
+                        id: customer.Customer_ID,
                         Customer_NAME: customer.Customer_NAME,
                         Customer_CODE: customer.Customer_CODE,
                         Customer_ShortName: customer.Customer_ShortName
@@ -920,7 +922,7 @@ export default {
          */
         clearCustomerOptions() {
             this.customerBlacklistOptions = [];
-            
+
             this.currentCustomerBlacklist = [];
         },