|
@@ -159,6 +159,12 @@ export default {
|
|
|
currentCustomerBlacklist: [],
|
|
|
/** @type {boolean} 客户选项加载状态 */
|
|
|
customerOptionsLoading: false,
|
|
|
+ /** @type {boolean} 公告表单组件显示状态 */
|
|
|
+ announcementFormVisible: false,
|
|
|
+ /** @type {boolean} 是否为编辑模式 */
|
|
|
+ isEditMode: false,
|
|
|
+ /** @type {string|null} 编辑的公告ID */
|
|
|
+ editAnnouncementId: null,
|
|
|
/** @type {TableOption} 表格配置选项 */
|
|
|
option: {
|
|
|
height: 'auto',
|
|
@@ -191,16 +197,17 @@ export default {
|
|
|
},
|
|
|
{
|
|
|
label: "分类",
|
|
|
- prop: "categoryId",
|
|
|
+ prop: "categoryName",
|
|
|
type: "select",
|
|
|
dicData: [],
|
|
|
props: {
|
|
|
label: "name",
|
|
|
- value: "id"
|
|
|
+ value: "name"
|
|
|
},
|
|
|
slot: true,
|
|
|
search: true,
|
|
|
span: 12,
|
|
|
+ searchProp: "categoryId",
|
|
|
rules: [{
|
|
|
required: true,
|
|
|
message: "请选择分类",
|
|
@@ -408,7 +415,7 @@ export default {
|
|
|
.map(item => ({
|
|
|
id: item.id,
|
|
|
name: item.name,
|
|
|
- value: item.id,
|
|
|
+ value: item.name,
|
|
|
label: item.name,
|
|
|
orgId: item.orgId,
|
|
|
orgName: item.orgName,
|
|
@@ -417,7 +424,7 @@ export default {
|
|
|
.sort((a, b) => a.sortOrder - b.sortOrder);
|
|
|
|
|
|
// 更新表格列配置中的字典数据
|
|
|
- const categoryColumn = this.option.column.find((/** @type {TableColumn} */ col) => col.prop === 'categoryId');
|
|
|
+ const categoryColumn = this.option.column.find((/** @type {TableColumn} */ col) => col.prop === 'categoryName');
|
|
|
if (categoryColumn) {
|
|
|
categoryColumn.dicData = this.categoryOptions;
|
|
|
}
|
|
@@ -428,11 +435,11 @@ export default {
|
|
|
// 使用默认分类选项
|
|
|
/** @type {Array<CategoryOption>} */
|
|
|
this.categoryOptions = [
|
|
|
- { id: 1, name: '系统公告', value: 1, label: '系统公告', sortOrder: 0 },
|
|
|
- { id: 2, name: '部门公告', value: 2, label: '部门公告', sortOrder: 1 }
|
|
|
+ { id: 1, name: '系统公告', value: '系统公告', label: '系统公告', sortOrder: 0 },
|
|
|
+ { id: 2, name: '部门公告', value: '部门公告', label: '部门公告', sortOrder: 1 }
|
|
|
];
|
|
|
|
|
|
- const categoryColumn = this.option.column.find((/** @type {TableColumn} */ col) => col.prop === 'categoryId');
|
|
|
+ const categoryColumn = this.option.column.find((/** @type {TableColumn} */ col) => col.prop === 'categoryName');
|
|
|
if (categoryColumn) {
|
|
|
categoryColumn.dicData = this.categoryOptions;
|
|
|
}
|
|
@@ -474,76 +481,9 @@ export default {
|
|
|
* @throws {Error} 当保存失败时抛出错误
|
|
|
*/
|
|
|
async rowSave(row, done, loading) {
|
|
|
- try {
|
|
|
- // 参数验证
|
|
|
- if (!row.title?.trim()) {
|
|
|
- this.$message.error('公告标题不能为空');
|
|
|
- loading();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!row.content?.trim()) {
|
|
|
- this.$message.error('公告内容不能为空');
|
|
|
- loading();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 计算角色掩码值
|
|
|
- /** @type {VisibleRolesMask} */
|
|
|
- let rolesMask;
|
|
|
- if (Array.isArray(row.visibleRoles)) {
|
|
|
- // 如果是数组,需要检查是RoleType[]还是RoleOption[]
|
|
|
- const roleValues = row.visibleRoles.map(role =>
|
|
|
- typeof role === 'object' ? role.value : role
|
|
|
- );
|
|
|
- rolesMask = this.calculateRolesMask(roleValues);
|
|
|
- } else {
|
|
|
- rolesMask = row.visibleRoles ? parseInt(row.visibleRoles) : 0;
|
|
|
- }
|
|
|
-
|
|
|
- // 处理客户黑名单数据
|
|
|
- const filteredCustomerBlacklist = this.currentCustomerBlacklist.filter((/** @type {CustomerBlacklistOption} */ customer) => {
|
|
|
- const selectedIds = (row.customerBlacklist || []).map((/** @type {CustomerBlacklistOption} */ item) => item.id);
|
|
|
- return selectedIds.includes(customer.id);
|
|
|
- });
|
|
|
-
|
|
|
- // 构建表单数据
|
|
|
- /** @type {import('@/api/announcement').NoticeFormData} */
|
|
|
- const formData = {
|
|
|
- ...row,
|
|
|
- orgId: this.userInfo?.orgId || row.orgId,
|
|
|
- orgCode: this.userInfo?.orgCode || row.orgCode,
|
|
|
- orgName: this.userInfo?.orgName || row.orgName,
|
|
|
- brandScope: row.brandScope || undefined,
|
|
|
- customerBlacklist: JSON.stringify(filteredCustomerBlacklist.map(customer => ({
|
|
|
- ...customer,
|
|
|
- ID: customer.id,
|
|
|
- CODE: customer.Customer_CODE,
|
|
|
- NAME: customer.Customer_NAME
|
|
|
- }))),
|
|
|
- remark: row.remark || '',
|
|
|
- visibleRoles: rolesMask.toString(),
|
|
|
- status: row.status !== undefined ? row.status : ANNOUNCEMENT_STATUS.DRAFT,
|
|
|
- };
|
|
|
-
|
|
|
- // 设置分类名称
|
|
|
- const selectedCategory = this.categoryOptions.find((/** @type {CategoryOption} */ cat) => String(cat.id) == row.categoryId);
|
|
|
- if (selectedCategory) {
|
|
|
- formData.categoryName = selectedCategory.name;
|
|
|
- }
|
|
|
-
|
|
|
- await add(formData);
|
|
|
- await this.onLoad(this.page);
|
|
|
- this.$message({
|
|
|
- type: "success",
|
|
|
- message: "新增公告成功!"
|
|
|
- });
|
|
|
- done();
|
|
|
- } catch (error) {
|
|
|
- console.error('保存失败:', error);
|
|
|
- this.$message.error(`保存失败: ${error.message || '未知错误'}`);
|
|
|
- loading();
|
|
|
- }
|
|
|
+ // 新增操作现在由表单组件处理,此方法已废弃
|
|
|
+ console.warn('rowSave方法已废弃,请使用表单组件进行新增操作');
|
|
|
+ done();
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -558,86 +498,9 @@ export default {
|
|
|
* @throws {Error} 当更新失败时抛出错误
|
|
|
*/
|
|
|
async rowUpdate(row, index, done, loading) {
|
|
|
- try {
|
|
|
- // 参数验证
|
|
|
- if (!row.id) {
|
|
|
- this.$message.error('缺少公告ID,无法更新');
|
|
|
- loading();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!row.title?.trim()) {
|
|
|
- this.$message.error('公告标题不能为空');
|
|
|
- loading();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!row.content?.trim()) {
|
|
|
- this.$message.error('公告内容不能为空');
|
|
|
- loading();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 计算角色掩码值
|
|
|
- /** @type {VisibleRolesMask} */
|
|
|
- let rolesMask;
|
|
|
- if (Array.isArray(row.visibleRoles)) {
|
|
|
- // 如果是数组,需要检查是RoleType[]还是RoleOption[]
|
|
|
- const roleValues = row.visibleRoles.map(role =>
|
|
|
- typeof role === 'object' ? role.value : role
|
|
|
- );
|
|
|
- rolesMask = this.calculateRolesMask(roleValues);
|
|
|
- } else {
|
|
|
- rolesMask = row.visibleRoles;
|
|
|
- }
|
|
|
-
|
|
|
- // 设置分类名称
|
|
|
- const selectedCategory = this.categoryOptions.find((/** @type {CategoryOption} */ cat) => String(cat.id) == row.categoryId);
|
|
|
- if (selectedCategory) {
|
|
|
- row.categoryName = selectedCategory.name;
|
|
|
- }
|
|
|
-
|
|
|
- // 处理客户黑名单数据
|
|
|
-
|
|
|
- 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);
|
|
|
- });
|
|
|
- const uniqFilterCustomerBlacklist = filteredCustomerBlacklist.filter((item, index, self) =>
|
|
|
- index === self.findIndex((t) => (
|
|
|
- t.id === item.id
|
|
|
- ))
|
|
|
- );
|
|
|
-
|
|
|
- // 构建更新数据
|
|
|
- /** @type {import('@/api/announcement').NoticeFormData} */
|
|
|
- const formData = {
|
|
|
- ...row,
|
|
|
- brandScope: row.brandScope || undefined,
|
|
|
- customerBlacklist: JSON.stringify(uniqFilterCustomerBlacklist.map(customer => ({
|
|
|
- ID: customer.id,
|
|
|
- CODE: customer.Customer_CODE,
|
|
|
- NAME: customer.Customer_NAME
|
|
|
- }))),
|
|
|
- remark: row.remark || '',
|
|
|
- visibleRoles: rolesMask.toString()
|
|
|
- };
|
|
|
-
|
|
|
- console.log(formData)
|
|
|
- await update(formData);
|
|
|
- await this.onLoad(this.page);
|
|
|
- this.$message({
|
|
|
- type: "success",
|
|
|
- message: "更新公告成功!"
|
|
|
- });
|
|
|
- done();
|
|
|
- } catch (error) {
|
|
|
- console.error('更新失败:', error);
|
|
|
- this.$message.error(`更新失败: ${error.message || '未知错误'}`);
|
|
|
- loading();
|
|
|
- }
|
|
|
+ // 编辑操作现在由表单组件处理,此方法已废弃
|
|
|
+ console.warn('rowUpdate方法已废弃,请使用表单组件进行编辑操作');
|
|
|
+ done();
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -713,7 +576,23 @@ export default {
|
|
|
* @throws {Error} 当获取详情失败时抛出错误
|
|
|
*/
|
|
|
async beforeOpen(done, type) {
|
|
|
- if (["edit", "view"].includes(type)) {
|
|
|
+ // 对于新增和编辑操作,使用表单组件
|
|
|
+ if (type === "add") {
|
|
|
+ this.isEditMode = false;
|
|
|
+ this.editAnnouncementId = null;
|
|
|
+ this.announcementFormVisible = true;
|
|
|
+ done();
|
|
|
+ return;
|
|
|
+ } else if (type === "edit") {
|
|
|
+ this.isEditMode = true;
|
|
|
+ this.editAnnouncementId = this.form?.id || null;
|
|
|
+ this.announcementFormVisible = true;
|
|
|
+ done();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对于查看操作,保持原有逻辑
|
|
|
+ if (type === "view") {
|
|
|
try {
|
|
|
if (!this.form?.id) {
|
|
|
this.$message.error('缺少公告ID,无法获取详情');
|
|
@@ -775,21 +654,6 @@ export default {
|
|
|
console.error('获取详情失败:', error);
|
|
|
this.$message.error('获取详情失败,请稍后重试');
|
|
|
}
|
|
|
- } else if (type === "add") {
|
|
|
- // 新增时设置默认值
|
|
|
- this.form = {
|
|
|
- orgId: this.userInfo?.orgId || '',
|
|
|
- orgCode: this.userInfo?.orgCode || '',
|
|
|
- orgName: this.userInfo?.orgName || '',
|
|
|
- visibleRoles: [ROLE_TYPES.DEALER], // 默认经销商
|
|
|
- brandScope: [],
|
|
|
- customerBlacklist: [],
|
|
|
- remark: '',
|
|
|
- status: ANNOUNCEMENT_STATUS.DRAFT
|
|
|
- };
|
|
|
- // 清空客户选项
|
|
|
- /** @type {Array<CustomerBlacklistOption>} */
|
|
|
- this.customerBlacklistOptions = [];
|
|
|
}
|
|
|
done();
|
|
|
},
|
|
@@ -927,9 +791,26 @@ export default {
|
|
|
*/
|
|
|
clearCustomerOptions() {
|
|
|
this.customerBlacklistOptions = [];
|
|
|
+ },
|
|
|
|
|
|
- this.currentCustomerBlacklist = [];
|
|
|
+ /**
|
|
|
+ * 处理表单组件返回事件
|
|
|
+ */
|
|
|
+ handleFormBack() {
|
|
|
+ this.announcementFormVisible = false;
|
|
|
+ this.isEditMode = false;
|
|
|
+ this.editAnnouncementId = null;
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理表单保存成功事件
|
|
|
+ */
|
|
|
+ handleFormSaveSuccess() {
|
|
|
+ this.announcementFormVisible = false;
|
|
|
+ this.isEditMode = false;
|
|
|
+ this.editAnnouncementId = null;
|
|
|
+ // 刷新列表数据
|
|
|
+ this.onLoad(this.page);
|
|
|
+ }
|
|
|
}
|
|
|
};
|