|
@@ -0,0 +1,117 @@
|
|
|
|
+<template>
|
|
|
|
+ <el-popover
|
|
|
|
+ :placement="attrs.placement?attrs.placement:'bottom-start'"
|
|
|
|
+ :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 v-model="value" slot="reference" readonly :placeholder="attrs.placeholder?attrs.placeholder:'请选择'" :clearable="attrs.clearable" suffix-icon="el-icon-arrow-down"></el-input>
|
|
|
|
+ </el-popover>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script lang="ts">
|
|
|
|
+/*
|
|
|
|
+ 配置说明
|
|
|
|
+ config:{
|
|
|
|
+ attrs:{
|
|
|
|
+ retConfig:{
|
|
|
|
+ retLabel:'name' //返回的值(示例)
|
|
|
|
+ retValue:'id' //返回的值(示例)
|
|
|
|
+ }
|
|
|
|
+ width:'' //宽度
|
|
|
|
+ placement:'' //方向
|
|
|
|
+ clearable:true/false //是否清空
|
|
|
|
+ placeholder:'' //占位符
|
|
|
|
+ label:'' //标签
|
|
|
|
+ children:'' //下一级
|
|
|
|
+ },
|
|
|
|
+ request:{}
|
|
|
|
+ }
|
|
|
|
+*/
|
|
|
|
+import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
|
|
|
+import VueViews from '@/benyun/compVue/VueViews'
|
|
|
|
+@Component
|
|
|
|
+export default class SelectTree extends VueViews {
|
|
|
|
+ data:Array<any>=[]
|
|
|
|
+
|
|
|
|
+ get defaultProps(){
|
|
|
|
+ let c:any={
|
|
|
|
+ children: 'children',
|
|
|
|
+ label: 'label'
|
|
|
|
+ }
|
|
|
|
+ if(this.attrs.label){
|
|
|
|
+ c.label = this.attrs.label
|
|
|
|
+ }
|
|
|
|
+ if(this.attrs.children){
|
|
|
|
+ c.children = this.attrs.children
|
|
|
|
+ }
|
|
|
|
+ return c;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ created(){
|
|
|
|
+ if(this.propConfig){
|
|
|
|
+ this.setConfig(this.propConfig)
|
|
|
|
+ }
|
|
|
|
+ if(this.propValue){
|
|
|
|
+ this.setValue(this.propConfig)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mounted(){
|
|
|
|
+ this.$nextTick(()=>{
|
|
|
|
+ if(this.requestConfig){
|
|
|
|
+ this.request();
|
|
|
|
+ }else if(this.attrs.data){
|
|
|
|
+ this.setData(this.attrs.data)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setData(data:Array<any>){
|
|
|
|
+ this.data = data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setValue(v:any){
|
|
|
|
+ this.value = v;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getValue(){
|
|
|
|
+ return this.value;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ handleNodeClick(data:any){
|
|
|
|
+ this.value = data[this.defaultProps.label];
|
|
|
|
+ let obj:any = {};
|
|
|
|
+ try{
|
|
|
|
+ if(this.attrs.retConfig){
|
|
|
|
+ for(const key in this.attrs.retConfig){
|
|
|
|
+ obj[key] = data[this.attrs.retConfig[key]]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }catch(e){
|
|
|
|
+ console.log('selectTree:retConfig报错!')
|
|
|
|
+ }
|
|
|
|
+ this.$emit('onChange',obj);
|
|
|
|
+ this.$emit('handleNodeClick',data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //请求url
|
|
|
|
+ request(){
|
|
|
|
+ if(!this.requestConfig || !this.requestConfig.url){
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let parame = (this as any).$lodash.cloneDeep(this.requestConfig);
|
|
|
|
+ parame.success = (res:any) => {
|
|
|
|
+ if(res.data){
|
|
|
|
+ this.setData(res.data);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ parame.fail = (err:any) => {}
|
|
|
|
+ this.requestHandle(parame);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="sass" scoped>
|
|
|
|
+
|
|
|
|
+</style>
|