|
@@ -40,7 +40,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getList, remove, update, add, getAnnouncement, getDealerList, getBrandList } from "@/api/announcement";
|
|
|
+import { getList, remove, update, add, getAnnouncement, getDealerList, getBrandList, getCategoryList } from "@/api/announcement";
|
|
|
import { mapGetters } from "vuex";
|
|
|
|
|
|
export default {
|
|
@@ -60,6 +60,7 @@ export default {
|
|
|
selectionList: [],
|
|
|
dealerOptions: [],
|
|
|
brandOptions: [],
|
|
|
+ categoryOptions: [], // 添加分类选项数组
|
|
|
option: {
|
|
|
height: 'auto',
|
|
|
calcHeight: 30,
|
|
@@ -88,18 +89,28 @@ export default {
|
|
|
}]
|
|
|
},
|
|
|
{
|
|
|
+ label: "客户编号",
|
|
|
+ prop: "customerCode",
|
|
|
+ span: 12,
|
|
|
+ search: true,
|
|
|
+ overHidden: true
|
|
|
+ },
|
|
|
+ {
|
|
|
label: "发布时间",
|
|
|
prop: "publishTime",
|
|
|
- type: "datetime",
|
|
|
- format: "yyyy-MM-dd hh:mm:ss",
|
|
|
- valueFormat: "yyyy-MM-dd hh:mm:ss",
|
|
|
+ type: "daterange",
|
|
|
+ format: "yyyy-MM-dd",
|
|
|
+ valueFormat: "yyyy-MM-dd",
|
|
|
+ rangeSeparator: "至",
|
|
|
+ searchRange: true,
|
|
|
+ startPlaceholder: "开始时间",
|
|
|
+ endPlaceholder: "结束时间",
|
|
|
overHidden: true,
|
|
|
search: true,
|
|
|
- rules: [{
|
|
|
- required: true,
|
|
|
- message: "请选择发布时间",
|
|
|
- trigger: "change"
|
|
|
- }]
|
|
|
+ hide: true, // 在表格中隐藏,只用于搜索
|
|
|
+ addDisplay: false, // 新增时不显示
|
|
|
+ editDisplay: false, // 编辑时不显示
|
|
|
+ viewDisplay: false // 查看时不显示
|
|
|
},
|
|
|
{
|
|
|
label: "经销商",
|
|
@@ -140,11 +151,38 @@ export default {
|
|
|
}]
|
|
|
},
|
|
|
{
|
|
|
- label: "详情",
|
|
|
- prop: "detail",
|
|
|
- slot: true,
|
|
|
- hide: true,
|
|
|
- showColumn: false
|
|
|
+ label: "分类",
|
|
|
+ prop: "categoryId",
|
|
|
+ type: "select",
|
|
|
+ dicData: [], // 初始为空,通过loadCategoryOptions方法动态加载
|
|
|
+ props: {
|
|
|
+ label: "categoryName", // 根据后端返回的字段名调整
|
|
|
+ value: "id"
|
|
|
+ },
|
|
|
+ search: true,
|
|
|
+ span: 12,
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ message: "请选择分类",
|
|
|
+ trigger: "change"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "角色",
|
|
|
+ prop: "roleType",
|
|
|
+ type: "select",
|
|
|
+ dicData: [
|
|
|
+ { label: "工厂", value: "factory" },
|
|
|
+ { label: "经销商", value: "dealer" },
|
|
|
+ { label: "零售商", value: "retailer" }
|
|
|
+ ],
|
|
|
+ search: true,
|
|
|
+ span: 12,
|
|
|
+ rules: [{
|
|
|
+ required: true,
|
|
|
+ message: "请选择角色",
|
|
|
+ trigger: "change"
|
|
|
+ }]
|
|
|
},
|
|
|
{
|
|
|
label: "公告内容",
|
|
@@ -167,18 +205,6 @@ export default {
|
|
|
trigger: "blur"
|
|
|
}]
|
|
|
},
|
|
|
- {
|
|
|
- label: "状态",
|
|
|
- prop: "status",
|
|
|
- type: "select",
|
|
|
- dicData: [
|
|
|
- { label: "启用", value: 1 },
|
|
|
- { label: "禁用", value: 0 }
|
|
|
- ],
|
|
|
- search: true,
|
|
|
- span: 12,
|
|
|
- value: 1
|
|
|
- }
|
|
|
]
|
|
|
},
|
|
|
data: []
|
|
@@ -209,22 +235,47 @@ export default {
|
|
|
created() {
|
|
|
this.loadDealerOptions();
|
|
|
this.loadBrandOptions();
|
|
|
+ this.loadCategoryOptions(); // 添加分类加载
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 加载分类选项
|
|
|
+ async loadCategoryOptions() {
|
|
|
+ try {
|
|
|
+ const res = await getCategoryList();
|
|
|
+ this.categoryOptions = res.data.data || [];
|
|
|
+ const categoryColumn = this.option.column.find(col => col.prop === 'categoryId');
|
|
|
+ if (categoryColumn) {
|
|
|
+ categoryColumn.dicData = this.categoryOptions;
|
|
|
+ }
|
|
|
+ } catch (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: '维护公告' }
|
|
|
+ ];
|
|
|
+ const categoryColumn = this.option.column.find(col => col.prop === 'categoryId');
|
|
|
+ if (categoryColumn) {
|
|
|
+ categoryColumn.dicData = this.categoryOptions;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
// 查看详情
|
|
|
viewDetail(row) {
|
|
|
this.currentDetail = row;
|
|
|
this.detailVisible = true;
|
|
|
},
|
|
|
// 加载经销商选项
|
|
|
- loadDealerOptions() {
|
|
|
- getDealerList().then(res => {
|
|
|
+ async loadDealerOptions() {
|
|
|
+ try {
|
|
|
+ const res = await getDealerList();
|
|
|
this.dealerOptions = res.data.data || [];
|
|
|
const dealerColumn = this.option.column.find(col => col.prop === 'dealerId');
|
|
|
if (dealerColumn) {
|
|
|
dealerColumn.dicData = this.dealerOptions;
|
|
|
}
|
|
|
- }).catch(() => {
|
|
|
+ } catch (error) {
|
|
|
// 如果接口不存在,使用模拟数据
|
|
|
this.dealerOptions = [
|
|
|
{ id: 1, dealerName: '经销商A' },
|
|
@@ -235,17 +286,18 @@ export default {
|
|
|
if (dealerColumn) {
|
|
|
dealerColumn.dicData = this.dealerOptions;
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
},
|
|
|
// 加载品牌选项
|
|
|
- loadBrandOptions() {
|
|
|
- getBrandList().then(res => {
|
|
|
+ async loadBrandOptions() {
|
|
|
+ try {
|
|
|
+ const res = await getBrandList();
|
|
|
this.brandOptions = res.data.data || [];
|
|
|
const brandColumn = this.option.column.find(col => col.prop === 'brandId');
|
|
|
if (brandColumn) {
|
|
|
brandColumn.dicData = this.brandOptions;
|
|
|
}
|
|
|
- }).catch(() => {
|
|
|
+ } catch (error) {
|
|
|
// 如果接口不存在,使用模拟数据
|
|
|
this.brandOptions = [
|
|
|
{ id: 1, brandName: '品牌A' },
|
|
@@ -256,50 +308,53 @@ export default {
|
|
|
if (brandColumn) {
|
|
|
brandColumn.dicData = this.brandOptions;
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
},
|
|
|
- rowSave(row, done, loading) {
|
|
|
- add(row).then(() => {
|
|
|
+ async rowSave(row, done, loading) {
|
|
|
+ try {
|
|
|
+ await add(row);
|
|
|
this.onLoad(this.page);
|
|
|
this.$message({
|
|
|
type: "success",
|
|
|
message: "操作成功!"
|
|
|
});
|
|
|
done();
|
|
|
- }, error => {
|
|
|
+ } catch (error) {
|
|
|
console.log(error);
|
|
|
loading();
|
|
|
- });
|
|
|
+ }
|
|
|
},
|
|
|
- rowUpdate(row, index, done, loading) {
|
|
|
- update(row).then(() => {
|
|
|
+ async rowUpdate(row, index, done, loading) {
|
|
|
+ try {
|
|
|
+ await update(row);
|
|
|
this.onLoad(this.page);
|
|
|
this.$message({
|
|
|
type: "success",
|
|
|
message: "操作成功!"
|
|
|
});
|
|
|
done();
|
|
|
- }, error => {
|
|
|
+ } catch (error) {
|
|
|
console.log(error);
|
|
|
loading();
|
|
|
- });
|
|
|
+ }
|
|
|
},
|
|
|
- rowDel(row) {
|
|
|
- this.$confirm("确定将选择数据删除?", {
|
|
|
- confirmButtonText: "确定",
|
|
|
- cancelButtonText: "取消",
|
|
|
- type: "warning"
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- return remove(row.id);
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- this.onLoad(this.page);
|
|
|
- this.$message({
|
|
|
- type: "success",
|
|
|
- message: "操作成功!"
|
|
|
- });
|
|
|
+ async rowDel(row) {
|
|
|
+ try {
|
|
|
+ await this.$confirm("确定将选择数据删除?", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning"
|
|
|
});
|
|
|
+ await remove(row.id);
|
|
|
+ this.onLoad(this.page);
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "操作成功!"
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ // 用户取消删除或删除失败
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
},
|
|
|
searchReset() {
|
|
|
this.query = {};
|
|
@@ -318,33 +373,37 @@ export default {
|
|
|
this.selectionList = [];
|
|
|
this.$refs.crud.toggleSelection();
|
|
|
},
|
|
|
- handleDelete() {
|
|
|
+ async handleDelete() {
|
|
|
if (this.selectionList.length === 0) {
|
|
|
this.$message.warning("请选择至少一条数据");
|
|
|
return;
|
|
|
}
|
|
|
- this.$confirm("确定将选择数据删除?", {
|
|
|
- confirmButtonText: "确定",
|
|
|
- cancelButtonText: "取消",
|
|
|
- type: "warning"
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- return remove(this.ids);
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- this.onLoad(this.page);
|
|
|
- this.$message({
|
|
|
- type: "success",
|
|
|
- message: "操作成功!"
|
|
|
- });
|
|
|
- this.$refs.crud.toggleSelection();
|
|
|
+ try {
|
|
|
+ await this.$confirm("确定将选择数据删除?", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning"
|
|
|
+ });
|
|
|
+ await remove(this.ids);
|
|
|
+ this.onLoad(this.page);
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "操作成功!"
|
|
|
});
|
|
|
+ this.$refs.crud.toggleSelection();
|
|
|
+ } catch (error) {
|
|
|
+ // 用户取消删除或删除失败
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
},
|
|
|
- beforeOpen(done, type) {
|
|
|
+ async beforeOpen(done, type) {
|
|
|
if (["edit", "view"].includes(type)) {
|
|
|
- getAnnouncement(this.form.id).then(res => {
|
|
|
+ try {
|
|
|
+ const res = await getAnnouncement(this.form.id);
|
|
|
this.form = res.data.data;
|
|
|
- });
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
}
|
|
|
done();
|
|
|
},
|
|
@@ -357,7 +416,7 @@ export default {
|
|
|
refreshChange() {
|
|
|
this.onLoad(this.page, this.query);
|
|
|
},
|
|
|
- onLoad(page, params = {}) {
|
|
|
+ async onLoad(page, params = {}) {
|
|
|
const { publishTime } = this.query;
|
|
|
let values = {
|
|
|
...params,
|
|
@@ -372,13 +431,17 @@ export default {
|
|
|
values.publishTime = null;
|
|
|
}
|
|
|
this.loading = true;
|
|
|
- getList(page.currentPage, page.pageSize, values).then(res => {
|
|
|
+ try {
|
|
|
+ const res = await getList(page.currentPage, page.pageSize, values);
|
|
|
const data = res.data.data;
|
|
|
this.page.total = data.total;
|
|
|
this.data = data.records;
|
|
|
this.loading = false;
|
|
|
this.selectionClear();
|
|
|
- });
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|