|
@@ -9,7 +9,7 @@
|
|
|
<!-- 搜索标题 -->
|
|
|
<el-form :inline="true" class="searchForm" v-model.trim="searchForm">
|
|
|
<el-form-item prop="hasPracticeCourse">
|
|
|
- <el-cascader
|
|
|
+ <el-cascader ref="cascader"
|
|
|
:show-all-levels="false"
|
|
|
:options="treeList"
|
|
|
v-model="searchForm.catalogId"
|
|
@@ -57,6 +57,7 @@
|
|
|
<el-form-item label="分类" prop="catalogId" :label-width="formLabelWidth">
|
|
|
<el-cascader style="width: 100%;"
|
|
|
:show-all-levels="false"
|
|
|
+ ref="formCascader"
|
|
|
:options="treeList"
|
|
|
v-model="form.catalogId"
|
|
|
:props="{ checkStrictly: true }"
|
|
@@ -121,7 +122,8 @@ export default {
|
|
|
page: 1, // 当前页
|
|
|
total: 0, // 总条数
|
|
|
page_size: [10, 20, 40, 50] // 选择限制显示条数
|
|
|
- }
|
|
|
+ },
|
|
|
+ tempTreeList: []
|
|
|
};
|
|
|
},
|
|
|
activated() {
|
|
@@ -154,7 +156,7 @@ export default {
|
|
|
let params = {
|
|
|
title: this.form.title, // 标题
|
|
|
content: this.form.content, // 内容
|
|
|
- catalogId: this.form.catalogId[0], // 分类编号
|
|
|
+ catalogId: this.form.catalogId[this.form.catalogId.length - 1], // 分类编号
|
|
|
}
|
|
|
helpCenterContentModify(params).then(res => {
|
|
|
this.messageTips("添加", res);
|
|
@@ -175,7 +177,6 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
-
|
|
|
messageTips(title, res) {
|
|
|
if (res.code == 200) {
|
|
|
this.$message.success(title + "成功");
|
|
@@ -220,6 +221,7 @@ export default {
|
|
|
tempList = {
|
|
|
value: res.id,
|
|
|
label: res.text,
|
|
|
+ parentId: res.parentId
|
|
|
}
|
|
|
if (res.children && res.children.length > 0) {
|
|
|
tempList.children = this.setTableData(res.children)
|
|
@@ -229,25 +231,56 @@ export default {
|
|
|
return list
|
|
|
},
|
|
|
openTypes(type, row) {
|
|
|
- this.typeStatus = true;
|
|
|
- this.formActionTitle = type;
|
|
|
+ this.typeStatus = true
|
|
|
+ this.formActionTitle = type
|
|
|
if (type == "update") {
|
|
|
// 修改的时候赋值
|
|
|
- console.log(row)
|
|
|
this.form = {
|
|
|
id: row.id,
|
|
|
title: row.title, // 标题
|
|
|
content: row.content, // 内容
|
|
|
- catalogId: [row.catalogId], // 分类编号
|
|
|
+ catalogId: this.getAllIds(row), // 分类编号
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
+ getAllIds(row) {
|
|
|
+ let idAndParent=[];// idAndParent保存 Tree所有节点的id和parentId
|
|
|
+ this.getIdAndParent(this.treeList,idAndParent);
|
|
|
+ let parentIds = []; // 用于保存选中节点的父节点及父节点的父节点
|
|
|
+ this.getId(row.catalogId, parentIds, idAndParent);
|
|
|
+ return parentIds.reverse(); //反转数组
|
|
|
+ },
|
|
|
+ getIdAndParent(tree, idAndParentIds) {// idAndParentIds用来保存所有节点的id,parentId
|
|
|
+ // 对原有的数据结构进行遍历,拿出所有节点的id,parentId到一个一维数组中。
|
|
|
+ tree.forEach(item => {
|
|
|
+ let mid = {
|
|
|
+ id: item.value,
|
|
|
+ parentId: item.parentId,
|
|
|
+ };
|
|
|
+ idAndParentIds.push(mid);
|
|
|
+ if (item.children) {
|
|
|
+ this.getIdAndParent(item.children, idAndParentIds);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getId(id, parentIds, idAndParent) {
|
|
|
+ idAndParent.forEach(item => {
|
|
|
+ if (item.id == id) {
|
|
|
+ parentIds.push(id);
|
|
|
+ if (item.parentId != -1) {
|
|
|
+ this.getId(item.parentId, parentIds, idAndParent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
onFormClose(formName) {
|
|
|
// 关闭弹窗重置验证
|
|
|
this.form = {
|
|
|
- name: null, // 作业模块名称
|
|
|
- subjectIds: []
|
|
|
- };
|
|
|
+ title: null, // 标题
|
|
|
+ content: null, // 内容
|
|
|
+ catalogId: [], // 分类编号
|
|
|
+ }
|
|
|
+ this.$refs.cascader.handleClear()
|
|
|
this.$refs[formName].resetFields();
|
|
|
}
|
|
|
}
|