|
|
@ -5,7 +5,7 @@ |
|
|
|
<div class="plus"> |
|
|
|
<div class="plus"> |
|
|
|
<i class="el-icon-circle-plus-outline" @click.stop="addType(0)"></i> |
|
|
|
<i class="el-icon-circle-plus-outline" @click.stop="addType(0)"></i> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<el-tree ref="type" :load="getType" lazy node-key="id" accordion :default-expanded-keys="defaultActive" :current-node-key="categoryId" :props="defaultProps" :highlight-current="true" @current-change="typeClick"> |
|
|
|
<el-tree ref="type" :data="typeList" node-key="id" accordion :default-expanded-keys="defaultActive" :current-node-key="categoryId" :props="defaultProps" :highlight-current="true" @current-change="typeClick"> |
|
|
|
<span class="custom-tree-node" slot-scope="{ node, data }"> |
|
|
|
<span class="custom-tree-node" slot-scope="{ node, data }"> |
|
|
|
<span :title="node.label">{{ node.label }}</span> |
|
|
|
<span :title="node.label">{{ node.label }}</span> |
|
|
|
<span class="actions"> |
|
|
|
<span class="actions"> |
|
|
@ -77,7 +77,7 @@ |
|
|
|
:default-checked-keys="defaultTypeChecked" |
|
|
|
:default-checked-keys="defaultTypeChecked" |
|
|
|
:current-node-key="curId" |
|
|
|
:current-node-key="curId" |
|
|
|
show-checkbox |
|
|
|
show-checkbox |
|
|
|
:props="defaultPropsImport" |
|
|
|
:props="defaultProps" |
|
|
|
highlight-current |
|
|
|
highlight-current |
|
|
|
@node-click="importTypeClick" |
|
|
|
@node-click="importTypeClick" |
|
|
|
@node-expand="importTypeExpand" |
|
|
|
@node-expand="importTypeExpand" |
|
|
@ -156,11 +156,8 @@ |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
|
|
|
|
typeList: [], |
|
|
|
defaultProps: { |
|
|
|
defaultProps: { |
|
|
|
children: 'children', |
|
|
|
|
|
|
|
label: 'categoryName' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
defaultPropsImport: { |
|
|
|
|
|
|
|
children: 'children', |
|
|
|
children: 'children', |
|
|
|
label: 'label' |
|
|
|
label: 'label' |
|
|
|
}, |
|
|
|
}, |
|
|
@ -215,20 +212,37 @@ export default { |
|
|
|
},500) |
|
|
|
},500) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted(){}, |
|
|
|
mounted(){ |
|
|
|
|
|
|
|
this.getType() |
|
|
|
|
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
getType(node, resolve){ |
|
|
|
getType(){ |
|
|
|
this.$post(`${this.api.getLevel}?parentId=${node.level ? node.data.id : 0}`).then(res => { |
|
|
|
this.$post(this.api.getTableByClassification).then(res => { |
|
|
|
const list = res.list |
|
|
|
// 递归赋值,同时添加层级标识 |
|
|
|
this.node = node |
|
|
|
function handleId(data,level = 0){ |
|
|
|
this.resolve = resolve |
|
|
|
data.map(n => { |
|
|
|
resolve(list) |
|
|
|
n.id = String(n.id) |
|
|
|
|
|
|
|
n.label = n.categoryName |
|
|
|
|
|
|
|
n.level = level + 1 |
|
|
|
|
|
|
|
if(n.children.length){ |
|
|
|
|
|
|
|
handleId(n.children,n.level) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
handleId(res) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.typeList = res |
|
|
|
|
|
|
|
if (!this.added) { |
|
|
|
|
|
|
|
if(res[0].children.length){ |
|
|
|
|
|
|
|
this.categoryId = res[0].children[0].id |
|
|
|
|
|
|
|
this.defaultActive = [res[0].children[0].id] |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
this.categoryId = res[0].id |
|
|
|
|
|
|
|
this.defaultActive = [res[0].id] |
|
|
|
|
|
|
|
} |
|
|
|
// 取第一个分类的id |
|
|
|
// 取第一个分类的id |
|
|
|
if (!this.added && list.length) { |
|
|
|
|
|
|
|
this.categoryId = list[0].id |
|
|
|
|
|
|
|
this.defaultActive = [list[0].id] |
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
this.$nextTick(() => { |
|
|
|
this.$refs.type.setCurrentKey(list[0].id) |
|
|
|
this.$refs.type.setCurrentKey(res[0].children[0].id) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
this.added = false |
|
|
|
this.added = false |
|
|
@ -262,20 +276,14 @@ export default { |
|
|
|
this.getData() |
|
|
|
this.getData() |
|
|
|
}, |
|
|
|
}, |
|
|
|
addType(row){ |
|
|
|
addType(row){ |
|
|
|
if (row) { |
|
|
|
if (row) this.defaultActive = [row.data.id] |
|
|
|
this.categoryId = row.data.id |
|
|
|
|
|
|
|
this.defaultActive = [row.data.id] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.typeVisible = true |
|
|
|
this.typeVisible = true |
|
|
|
this.levelId = row ? row.data.id : 0 |
|
|
|
this.levelId = row ? row.data.id : 0 |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
editType(row){ |
|
|
|
editType(row){ |
|
|
|
this.typeVisible = true |
|
|
|
this.typeVisible = true |
|
|
|
this.id = row.data.id |
|
|
|
this.id = row.data.id |
|
|
|
this.categoryName = row.data.categoryName |
|
|
|
this.categoryName = row.data.categoryName |
|
|
|
this.curNode = row |
|
|
|
|
|
|
|
this.categoryId = row.data.id |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
delType(row){ |
|
|
|
delType(row){ |
|
|
|
// 该分类下的数据表已存在于产品管理中,是否确认删除? |
|
|
|
// 该分类下的数据表已存在于产品管理中,是否确认删除? |
|
|
@ -285,7 +293,7 @@ export default { |
|
|
|
this.added = true |
|
|
|
this.added = true |
|
|
|
this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => { |
|
|
|
this.$post(`${this.api.deleteCategory}?categoryId=${row.data.id}`).then(res => { |
|
|
|
this.$message.success('删除成功') |
|
|
|
this.$message.success('删除成功') |
|
|
|
this.$refs.type.remove(row) |
|
|
|
this.getType() |
|
|
|
}).catch(res => {}) |
|
|
|
}).catch(res => {}) |
|
|
|
}).catch(() => {}) |
|
|
|
}).catch(() => {}) |
|
|
|
}, |
|
|
|
}, |
|
|
@ -299,9 +307,7 @@ export default { |
|
|
|
categoryName: this.categoryName |
|
|
|
categoryName: this.categoryName |
|
|
|
}).then(res => { |
|
|
|
}).then(res => { |
|
|
|
this.$message.success('编辑成功') |
|
|
|
this.$message.success('编辑成功') |
|
|
|
this.curNode.data.categoryName = this.categoryName |
|
|
|
this.getType() |
|
|
|
this.$refs.type.updateKeyChildren(this.id, this.curNode) |
|
|
|
|
|
|
|
this.getType(this.node, this.resolve) |
|
|
|
|
|
|
|
this.typeVisible = false |
|
|
|
this.typeVisible = false |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.submited = false |
|
|
|
this.submited = false |
|
|
@ -315,18 +321,7 @@ export default { |
|
|
|
categoryName: this.categoryName |
|
|
|
categoryName: this.categoryName |
|
|
|
}).then(res => { |
|
|
|
}).then(res => { |
|
|
|
this.$message.success('添加成功') |
|
|
|
this.$message.success('添加成功') |
|
|
|
this.getType(this.node, this.resolve) |
|
|
|
this.getType() |
|
|
|
if (this.levelId) { |
|
|
|
|
|
|
|
let node = this.$refs.type.getNode(this.categoryId) |
|
|
|
|
|
|
|
node.loaded = false |
|
|
|
|
|
|
|
node.expand() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// this.categoryId = '' |
|
|
|
|
|
|
|
// this.defaultProps = [] |
|
|
|
|
|
|
|
// this.$refs.type.setCurrentNode(0) |
|
|
|
|
|
|
|
// this.getType(0, this.resolve) |
|
|
|
|
|
|
|
location.reload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.typeVisible = false |
|
|
|
this.typeVisible = false |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.submited = false |
|
|
|
this.submited = false |
|
|
|