|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<div class="tree-choice">
|
|
|
- <!-- <el-input placeholder="输入名称搜索" v-model="filterText" style="margin-bottom: 10px"></el-input> -->
|
|
|
+ <el-input placeholder="输入名称搜索" v-model="filterText" style="margin-bottom: 10px"></el-input>
|
|
|
<el-tree
|
|
|
:data="dataList"
|
|
|
node-key="id"
|
|
@@ -11,6 +11,7 @@
|
|
|
ref="tree"
|
|
|
@node-click="nodeClick"
|
|
|
show-checkbox
|
|
|
+ :default-checked-keys="defaultChecked"
|
|
|
:props="{ disabled: () => true }"
|
|
|
>
|
|
|
<span class="custom-tree-node" slot-scope="{ data }">
|
|
@@ -22,6 +23,10 @@
|
|
|
|
|
|
<script>
|
|
|
export default {
|
|
|
+ model: {
|
|
|
+ prop: 'modelValue',
|
|
|
+ event: 'dataChange'
|
|
|
+ },
|
|
|
props: {
|
|
|
dataList: Array,
|
|
|
nodeKey: {
|
|
@@ -31,6 +36,10 @@
|
|
|
nodeVal: {
|
|
|
type: String,
|
|
|
default: 'name'
|
|
|
+ },
|
|
|
+ modelValue: {
|
|
|
+ type: Array,
|
|
|
+ required: true
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
@@ -39,6 +48,25 @@
|
|
|
filterText: ''
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ deptIds: {
|
|
|
+ get() {
|
|
|
+ return this.modelValue
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ this.$emit('dataChange', val)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //选中节点
|
|
|
+ defaultChecked() {
|
|
|
+ let ids = this.$store.state.user.dataPermissions
|
|
|
+ if (ids.includes('*')) {
|
|
|
+ return this.getAllIds(this.dataList)
|
|
|
+ } else {
|
|
|
+ return ids
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
watch: {
|
|
|
filterText(val) {
|
|
|
this.$refs.tree.filter(val)
|
|
@@ -51,8 +79,24 @@
|
|
|
return data[this.nodeVal].indexOf(value) !== -1
|
|
|
},
|
|
|
nodeClick(data) {
|
|
|
- console.log(data)
|
|
|
- this.$emit('itemClick', data)
|
|
|
+ let ids
|
|
|
+ if (data.children && data.children.length) {
|
|
|
+ ids = this.getAllIds(data.children)
|
|
|
+ } else {
|
|
|
+ ids = []
|
|
|
+ }
|
|
|
+ ids.push(data.id)
|
|
|
+ this.deptIds = ids.filter((item) => this.defaultChecked.includes(item))
|
|
|
+ },
|
|
|
+ getAllIds(parents) {
|
|
|
+ let arrs = []
|
|
|
+ parents.forEach((item) => {
|
|
|
+ arrs.push(item.id)
|
|
|
+ if (item.children && item.children.length) {
|
|
|
+ arrs = [...arrs, ...this.getAllIds(item.children)]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return arrs
|
|
|
}
|
|
|
}
|
|
|
}
|