|
@@ -4,8 +4,8 @@
|
|
|
:width="attrs.width?attrs.width:'300'"
|
|
|
trigger="click"
|
|
|
>
|
|
|
- <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" highlight-current node-key="id"></el-tree>
|
|
|
- <el-input :value="value" slot="reference" :placeholder="attrs.placeholder?attrs.placeholder:'请选择'" :clearable="attrs.clearable" @clear="clear" suffix-icon="el-icon-arrow-down"></el-input>
|
|
|
+ <el-tree :data="data" :props="defaultProps" :default-expand-all="attrs.defaultExpandAll" @node-click="handleNodeClick" highlight-current node-key="id"></el-tree>
|
|
|
+ <el-input :value="titleName" slot="reference" :placeholder="attrs.placeholder?attrs.placeholder:'请选择'" :clearable="attrs.clearable" @clear="clear" suffix-icon="el-icon-arrow-down"></el-input>
|
|
|
</el-popover>
|
|
|
</template>
|
|
|
|
|
@@ -24,6 +24,7 @@
|
|
|
placeholder:'' //占位符
|
|
|
label:'' //标签
|
|
|
children:'' //下一级
|
|
|
+ defaultExpandAll:false/true //是否默认展开所有节点
|
|
|
},
|
|
|
request:{}
|
|
|
}
|
|
@@ -33,7 +34,7 @@ import VueViews from '@/benyun/compVue/VueViews'
|
|
|
@Component
|
|
|
export default class SelectTree extends VueViews {
|
|
|
data:Array<any>=[]
|
|
|
-
|
|
|
+ titleName='';
|
|
|
get defaultProps(){
|
|
|
let c:any={
|
|
|
children: 'children',
|
|
@@ -69,6 +70,7 @@ export default class SelectTree extends VueViews {
|
|
|
clear(){
|
|
|
this.value='';
|
|
|
let obj:any = {};
|
|
|
+ this.titleName = '';
|
|
|
try{
|
|
|
if(this.attrs.retConfig){
|
|
|
for(const key in this.attrs.retConfig){
|
|
@@ -82,10 +84,36 @@ export default class SelectTree extends VueViews {
|
|
|
}
|
|
|
setData(data:Array<any>){
|
|
|
this.data = data;
|
|
|
+ if(this.value){
|
|
|
+ this.getLabel(this.data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getLabel(data:Array<any>){
|
|
|
+ for(const item of data){
|
|
|
+ let t = false;
|
|
|
+ for(const key in this.attrs.retConfig){
|
|
|
+ const code = this.attrs.retConfig[key];
|
|
|
+ if(item[code] == this.value){
|
|
|
+ this.titleName = item[this.defaultProps.label]
|
|
|
+ t = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!t && item[this.defaultProps.children]){
|
|
|
+ this.getLabel(item[this.defaultProps.children]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
setValue(v:any){
|
|
|
this.value = v;
|
|
|
+ if(v && this.data.length > 0){
|
|
|
+ this.getLabel(this.data);
|
|
|
+ }else{
|
|
|
+ this.titleName = '';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
getValue(){
|
|
@@ -93,7 +121,7 @@ export default class SelectTree extends VueViews {
|
|
|
}
|
|
|
|
|
|
handleNodeClick(data:any){
|
|
|
- this.value = data[this.defaultProps.label];
|
|
|
+ this.titleName = data[this.defaultProps.label];
|
|
|
let obj:any = {};
|
|
|
try{
|
|
|
if(this.attrs.retConfig){
|