org-tree.vue
4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<div class="el-tree-select">
<!-- 下拉文本 -->
<!-- TODO -->
<!-- 需求更改2021-3-30:修改时不能修改当前类目 :disabled="parentid!==undefined&&parentid!==''"-->
<el-select :value="valueTitle" :clearable="clearable" @clear="clearHandle">
<!-- <el-popover
v-show="parentid!==''"
ref="popover"
width="435"
> -->
<el-option :value="valueTitle" :label="valueTitle">
<el-tree
id="tree-option"
ref="selectTree"
:accordion="accordion"
:data="options"
:props="props"
:node-key="props.value"
:default-expanded-keys="defaultExpandedKey"
@node-click="handleNodeClick"
>
<span slot-scope="{ node, data }" class="custom-tree-node">
<span :class="{'checkboxText': data.isEnable === false||data.status === false}">
{{ node.label }}
</span>
</span>
</el-tree>
</el-option>
<!-- </el-popover> -->
</el-select>
</div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator'
import { ElForm } from 'element-ui/types/form'
import { Tree as ElTree } from 'element-ui'
@Component({
name: 'TreeSelect'
})
// @group api
export default class extends Vue {
@Prop() private orgData!: {}
@Prop() private props!: {}
@Prop() private options!: []
@Prop() private parentid!:string
@Prop() private parentname!:string
// @Prop() private parentinfo!:{}
@Prop() private editdata!:{}
@Prop() private clearable!:true
@Prop() private accordion!:false
private treeData = [] as any
private valueId= ''
private valueTitle=''
private defaultExpandedKey = [] as any[]
private ref: any = this.$refs
private visible =true
private isShow = false
@Watch('parentid', { immediate: true })
getIds(val: any) {
if (val !== undefined && val !== '') {
this.valueId = val
}
}
@Watch('parentname', { immediate: true })
getname(val: any) {
this.valueTitle = val
if (val !== '') {
this.valueTitle = val
}
}
@Watch('editdata')
getParendName(val: any) {
if (val.id !== undefined || val.id !== '') {
// if (val.parentId === '0') {
// if (this.parentname !== '' && this.parentname !== undefined) {
// this.valueTitle = this.parentname
// } else {
// this.valueTitle = '顶级组织'
// }
// } else {
// this.valueTitle = val.parentName
// this.valueId = val.parentId
// if (this.parentname !== '' && this.parentname !== undefined) {
// this.valueTitle = this.parentname
// this.valueId = this.parentid
// }
// }
this.valueTitle = val.parentName
this.valueId = val.parentId
if (this.parentname !== '' && this.parentname !== undefined) {
this.valueTitle = this.parentname
this.valueId = this.parentid
} else {
if (val.parentId === '0') {
this.valueTitle = '顶级组织'
}
}
} else {
this.valueTitle = ''
this.valueId = ''
}
}
@Watch('options', { immediate: true })
getOption(val:Array<string>) {
// val.splice(val.findIndex((obj:any) => (obj.status === false)), 1)
const obj = {
name: '顶级组织',
id: '0',
parentId: '0',
children: []
} as any
val.unshift(obj)
}
// 生命周期
mounted() {
this.initHandle()
}
// 初始化值
initHandle() {
if (this.valueId) {
this.valueTitle = this.ref.selectTree.getNode(this.valueId).data[(this.props as any).label] // 初始化显示
this.ref.selectTree.setCurrentKey(this.valueId) // 设置默认选中
this.defaultExpandedKey = [this.valueId] // 设置默认展开
}
}
// 切换选项
handleNodeClick(node:any) {
if (node.level === undefined || node.level < 4) {
if (node.id !== '') {
let scrollWrap = document.querySelectorAll('.el-select-dropdown.el-popper')[0];
(scrollWrap as any).style.cssText = 'display:none;'
}
const props = this.props as any
if ((node.isEnable || node.isEnable === undefined) && (node.status || node.status === undefined)) {
this.valueTitle = node[props.label]
this.valueId = node[props.value]
this.$emit('get-value', this.valueId)
this.visible = false
this.defaultExpandedKey = []
}
} else {
this.$message({
message: '最多添加四级菜单!',
type: 'error'
})
}
}
// 清除选中
clearHandle() {
this.valueTitle = ''
this.valueId = ''
this.defaultExpandedKey = []
this.clearSelected()
this.$emit('get-value', null)
}
// 清空选中样式
clearSelected() {
let allNode = document.querySelectorAll('#tree-option .el-tree-node')
allNode.forEach((element) => element.classList.remove('is-current'))
}
}
</script>
<style scoped>
</style>
<style>
</style>