|
@@ -43,24 +43,83 @@
|
|
|
import { getList, remove, update, add, getAnnouncement, getDealerList, getBrandList, getCategoryList } from "@/api/announcement";
|
|
|
import { mapGetters } from "vuex";
|
|
|
|
|
|
+/**
|
|
|
+ * @typedef {Object} AnnouncementItem
|
|
|
+ * @property {number} id - 公告ID
|
|
|
+ * @property {string} title - 公告标题
|
|
|
+ * @property {string} customerCode - 客户编号
|
|
|
+ * @property {string} publishTime - 发布时间
|
|
|
+ * @property {number} dealerId - 经销商ID
|
|
|
+ * @property {string} dealerName - 经销商名称
|
|
|
+ * @property {number} brandId - 品牌ID
|
|
|
+ * @property {string} brandName - 品牌名称
|
|
|
+ * @property {number} categoryId - 分类ID
|
|
|
+ * @property {string} categoryName - 分类名称
|
|
|
+ * @property {string} roleType - 角色类型
|
|
|
+ * @property {string} content - 公告内容
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {Object} OptionItem
|
|
|
+ * @property {number} id - 选项ID
|
|
|
+ * @property {string} dealerName - 经销商名称
|
|
|
+ * @property {string} brandName - 品牌名称
|
|
|
+ * @property {string} categoryName - 分类名称
|
|
|
+ * @property {number} value - 选项值
|
|
|
+ * @property {string} label - 选项标签
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {Object} PageInfo
|
|
|
+ * @property {number} pageSize - 每页大小
|
|
|
+ * @property {number} currentPage - 当前页码
|
|
|
+ * @property {number} total - 总记录数
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {Object} QueryParams
|
|
|
+ * @property {string} [title] - 公告标题
|
|
|
+ * @property {string} [customerCode] - 客户编号
|
|
|
+ * @property {Array<string>} [publishTime] - 发布时间范围
|
|
|
+ * @property {number} [dealerId] - 经销商ID
|
|
|
+ * @property {number} [brandId] - 品牌ID
|
|
|
+ * @property {number} [categoryId] - 分类ID
|
|
|
+ * @property {string} [roleType] - 角色类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公告管理组件
|
|
|
+ * @component AnnouncementIndex
|
|
|
+ */
|
|
|
export default {
|
|
|
name: 'AnnouncementIndex',
|
|
|
data() {
|
|
|
return {
|
|
|
+ /** @type {AnnouncementItem} 表单数据 */
|
|
|
form: {},
|
|
|
+ /** @type {QueryParams} 查询参数 */
|
|
|
query: {},
|
|
|
+ /** @type {boolean} 加载状态 */
|
|
|
loading: true,
|
|
|
+ /** @type {boolean} 详情对话框显示状态 */
|
|
|
detailVisible: false,
|
|
|
+ /** @type {AnnouncementItem} 当前查看的详情数据 */
|
|
|
currentDetail: {},
|
|
|
+ /** @type {PageInfo} 分页信息 */
|
|
|
page: {
|
|
|
pageSize: 10,
|
|
|
currentPage: 1,
|
|
|
total: 0
|
|
|
},
|
|
|
+ /** @type {Array<AnnouncementItem>} 选中的数据列表 */
|
|
|
selectionList: [],
|
|
|
+ /** @type {Array<OptionItem>} 经销商选项列表 */
|
|
|
dealerOptions: [],
|
|
|
+ /** @type {Array<OptionItem>} 品牌选项列表 */
|
|
|
brandOptions: [],
|
|
|
- categoryOptions: [], // 添加分类选项数组
|
|
|
+ /** @type {Array<OptionItem>} 分类选项列表 */
|
|
|
+ categoryOptions: [],
|
|
|
+ /** @type {Object} 表格配置选项 */
|
|
|
option: {
|
|
|
height: 'auto',
|
|
|
calcHeight: 30,
|
|
@@ -207,11 +266,16 @@ export default {
|
|
|
},
|
|
|
]
|
|
|
},
|
|
|
+ /** @type {Array<AnnouncementItem>} 表格数据 */
|
|
|
data: []
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
...mapGetters(["permission"]),
|
|
|
+ /**
|
|
|
+ * 权限列表
|
|
|
+ * @returns {Object} 权限配置对象
|
|
|
+ */
|
|
|
permissionList() {
|
|
|
return {
|
|
|
addBtn: this.vaildData(this.permission.announcement_add, false),
|
|
@@ -220,6 +284,10 @@ export default {
|
|
|
editBtn: this.vaildData(this.permission.announcement_edit, false)
|
|
|
};
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 选中的ID字符串
|
|
|
+ * @returns {string} 逗号分隔的ID字符串
|
|
|
+ */
|
|
|
ids() {
|
|
|
let ids = [];
|
|
|
this.selectionList.forEach(ele => {
|
|
@@ -234,22 +302,45 @@ export default {
|
|
|
this.loadCategoryOptions(); // 添加分类加载
|
|
|
},
|
|
|
methods: {
|
|
|
- // 加载分类选项
|
|
|
+ /**
|
|
|
+ * 加载分类选项
|
|
|
+ * @async
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async loadCategoryOptions() {
|
|
|
try {
|
|
|
const res = await getCategoryList();
|
|
|
- this.categoryOptions = res.data.data || [];
|
|
|
+ // 根据新接口返回的数据结构进行转换
|
|
|
+ const categoryData = res.data.data || [];
|
|
|
+
|
|
|
+ // 将接口返回的数据转换为页面所需的格式
|
|
|
+ this.categoryOptions = categoryData
|
|
|
+ .filter(item => item.status === 1 && item.isDeleted === 0) // 只显示启用且未删除的分类
|
|
|
+ .map(item => ({
|
|
|
+ id: item.id,
|
|
|
+ name: item.name,
|
|
|
+ categoryName: item.name, // 兼容原有字段名
|
|
|
+ value: item.id,
|
|
|
+ label: item.name,
|
|
|
+ orgId: item.orgId,
|
|
|
+ orgName: item.orgName,
|
|
|
+ isSystem: item.isSystem,
|
|
|
+ sortOrder: item.sortOrder
|
|
|
+ }))
|
|
|
+ .sort((a, b) => a.sortOrder - b.sortOrder); // 按排序字段排序
|
|
|
+
|
|
|
const categoryColumn = this.option.column.find(col => col.prop === 'categoryId');
|
|
|
if (categoryColumn) {
|
|
|
categoryColumn.dicData = this.categoryOptions;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
+ console.error('加载分类选项失败:', error);
|
|
|
// 如果接口不存在,使用模拟数据
|
|
|
this.categoryOptions = [
|
|
|
- { id: 1, categoryName: '系统公告', value: 1, label: '系统公告' },
|
|
|
- { id: 2, categoryName: '产品公告', value: 2, label: '产品公告' },
|
|
|
- { id: 3, categoryName: '活动公告', value: 3, label: '活动公告' },
|
|
|
- { id: 4, categoryName: '维护公告', value: 4, label: '维护公告' }
|
|
|
+ { id: 1, name: '系统公告', categoryName: '系统公告', value: 1, label: '系统公告', isSystem: 1, sortOrder: 0 },
|
|
|
+ { id: 2, name: '产品公告', categoryName: '产品公告', value: 2, label: '产品公告', isSystem: 0, sortOrder: 1 },
|
|
|
+ { id: 3, name: '活动公告', categoryName: '活动公告', value: 3, label: '活动公告', isSystem: 0, sortOrder: 2 },
|
|
|
+ { id: 4, name: '维护公告', categoryName: '维护公告', value: 4, label: '维护公告', isSystem: 0, sortOrder: 3 }
|
|
|
];
|
|
|
const categoryColumn = this.option.column.find(col => col.prop === 'categoryId');
|
|
|
if (categoryColumn) {
|
|
@@ -257,12 +348,20 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- // 查看详情
|
|
|
+ /**
|
|
|
+ * 查看详情
|
|
|
+ * @param {AnnouncementItem} row - 行数据
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
viewDetail(row) {
|
|
|
this.currentDetail = row;
|
|
|
this.detailVisible = true;
|
|
|
},
|
|
|
- // 加载经销商选项
|
|
|
+ /**
|
|
|
+ * 加载经销商选项
|
|
|
+ * @async
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async loadDealerOptions() {
|
|
|
try {
|
|
|
const res = await getDealerList();
|
|
@@ -284,7 +383,11 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- // 加载品牌选项
|
|
|
+ /**
|
|
|
+ * 加载品牌选项
|
|
|
+ * @async
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async loadBrandOptions() {
|
|
|
try {
|
|
|
const res = await getBrandList();
|
|
@@ -306,6 +409,14 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 保存行数据
|
|
|
+ * @async
|
|
|
+ * @param {AnnouncementItem} row - 行数据
|
|
|
+ * @param {Function} done - 完成回调
|
|
|
+ * @param {Function} loading - 加载回调
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async rowSave(row, done, loading) {
|
|
|
try {
|
|
|
await add(row);
|
|
@@ -320,6 +431,15 @@ export default {
|
|
|
loading();
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 更新行数据
|
|
|
+ * @async
|
|
|
+ * @param {AnnouncementItem} row - 行数据
|
|
|
+ * @param {number} index - 行索引
|
|
|
+ * @param {Function} done - 完成回调
|
|
|
+ * @param {Function} loading - 加载回调
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async rowUpdate(row, index, done, loading) {
|
|
|
try {
|
|
|
await update(row);
|
|
@@ -334,6 +454,12 @@ export default {
|
|
|
loading();
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 删除行数据
|
|
|
+ * @async
|
|
|
+ * @param {AnnouncementItem} row - 行数据
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async rowDel(row) {
|
|
|
try {
|
|
|
await this.$confirm("确定将选择数据删除?", {
|
|
@@ -352,23 +478,47 @@ export default {
|
|
|
console.log(error);
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 重置搜索
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
searchReset() {
|
|
|
this.query = {};
|
|
|
this.onLoad(this.page);
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 搜索变化
|
|
|
+ * @param {QueryParams} params - 搜索参数
|
|
|
+ * @param {Function} done - 完成回调
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
searchChange(params, done) {
|
|
|
this.query = params;
|
|
|
this.page.currentPage = 1;
|
|
|
this.onLoad(this.page, params);
|
|
|
done();
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 选择变化
|
|
|
+ * @param {Array<AnnouncementItem>} list - 选中的数据列表
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
selectionChange(list) {
|
|
|
this.selectionList = list;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 清空选择
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
selectionClear() {
|
|
|
this.selectionList = [];
|
|
|
this.$refs.crud.toggleSelection();
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ * @async
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async handleDelete() {
|
|
|
if (this.selectionList.length === 0) {
|
|
|
this.$message.warning("请选择至少一条数据");
|
|
@@ -392,6 +542,13 @@ export default {
|
|
|
console.log(error);
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 打开前回调
|
|
|
+ * @async
|
|
|
+ * @param {Function} done - 完成回调
|
|
|
+ * @param {string} type - 操作类型
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async beforeOpen(done, type) {
|
|
|
if (["edit", "view"].includes(type)) {
|
|
|
try {
|
|
@@ -403,15 +560,36 @@ export default {
|
|
|
}
|
|
|
done();
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 当前页变化
|
|
|
+ * @param {number} currentPage - 当前页码
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
currentChange(currentPage) {
|
|
|
this.page.currentPage = currentPage;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 页大小变化
|
|
|
+ * @param {number} pageSize - 页大小
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
sizeChange(pageSize) {
|
|
|
this.page.pageSize = pageSize;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 刷新变化
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
refreshChange() {
|
|
|
this.onLoad(this.page, this.query);
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 加载数据
|
|
|
+ * @async
|
|
|
+ * @param {PageInfo} page - 分页信息
|
|
|
+ * @param {QueryParams} [params={}] - 查询参数
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
async onLoad(page, params = {}) {
|
|
|
const { publishTime } = this.query;
|
|
|
let values = {
|