Ver código fonte

feat(公告): 添加品牌范围类型并改进表单数据处理

yz 3 dias atrás
pai
commit
4abc6c122e

+ 6 - 0
src/api/types/announcement.d.ts

@@ -34,6 +34,12 @@ export interface CustomerBlacklistItem {
   Customer_CODE: string;
 }
 
+export type BrandScopeItem = {
+  ID: number;
+  CODE: string;
+  NAME: string;
+}
+
 /**
  * 品牌范围类型
  */

+ 30 - 13
src/views/announcement/mixins/announcementIndex.js

@@ -454,7 +454,7 @@ export default {
 
             try {
                 const response = await getAnnouncement(this.selectionList[0].id);
-                /** @type {NoticeItem} */
+                
                 this.currentDetail = response.data?.data || {};
                 this.detailVisible = true;
             } catch (error) {
@@ -715,32 +715,49 @@ export default {
                     }
 
                     const response = await getAnnouncement(this.form.id);
-                    /** @type {NoticeItem} */
+                    
                     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: [],
+                        customerBlackList: [],
+                        BrandScope: [],
+                    }
 
                     // 将掩码值转换为数值数组格式供表单使用
                     if (typeof formData.visibleRoles === 'number') {
                         const roleObjects = this.parseRolesMask(formData.visibleRoles || 0);
-                        formData.visibleRoles = roleObjects.map(role => role.value);
+                        convertType.visibleRoles = roleObjects.map(role => role.value);
+                    } else if (typeof formData.visibleRoles === 'string') {
+                        const roleValues = formData.visibleRoles ? parseInt(formData.visibleRoles) : 0;
+                        let roleObjects = this.parseRolesMask(roleValues)
+                        convertType.visibleRoles = roleObjects.map(role => role.value);
                     } else {
-                        formData.visibleRoles = [];
+                        convertType.visibleRoles = [];
                     }
                     
                     // 确保客户黑名单是数组格式
-                    formData.customerBlacklist = Array.isArray(formData.customerBlacklist)
-                        ? formData.customerBlacklist
-                        : [];
+                    /** @type {Array<import("@/views/announcement/types").CustomerBlacklistItem>} */
+                    const tmpCustomerData  = JSON.parse(formData.customerBlacklist || '[]')
+                    convertType.customerBlackList = tmpCustomerData.map(item => ({
+                        ...item,
+                    }))
 
                     // 如果有客户黑名单数据,设置到选项中以便显示
-                    if (formData.customerBlacklist.length > 0) {
+                    if (convertType.customerBlackList.length > 0) {
                         /** @type {Array<CustomerBlacklistOption>} */
-                        this.customerBlacklistOptions = [...formData.customerBlacklist];
-                    }
-                    if (formData.customerBlacklist == null) {
-                        formData.customerBlacklist = [];
+                        this.customerBlacklistOptions = convertType.customerBlackList.map(item => ({
+                            id: item.ID,
+                            Customer_NAME: item.NAME,
+                            Customer_CODE: item.CODE,
+                        }))
                     }
 
-                    this.form = { ...formData };
+                    this.form = {
+                        ...formData,
+                        ...convertType,
+                    };
                 } catch (error) {
                     console.error('获取详情失败:', error);
                     this.$message.error('获取详情失败,请稍后重试');