index.vue 2.8 KB
<template>
  <div class="app-add-dialog"
    :tabindex="1"
    @blur="treeBlur"
    >
    <el-input 
        ref="searchTreeInput"
        class="orgina-dialog-input"
        placeholder="请输入"
        @keyup.enter.native="searchClick"
        v-model="inputValue">
        <i slot="suffix" class="el-input__icon el-icon-search" @click="searchClick"></i>
    </el-input>
    <el-tree
        v-show="isAsyc"
        ref="searchLoadTree"
        accordion
        node-key="id"
        :props="parentTreeProps"
        :load="nodeLoad"
        @node-click="nodeClick"
        @check="checkChange"
        lazy
         v-bind="$attrs"
        >
    </el-tree>
    <el-tree
        ref="searchTree"
        v-show="!isAsyc"
        default-expand-all
        node-key="id"
        :props="parentTreeProps"
        :data='parentNoAsycData'
        @node-click="nodeClick"
        @check="checkChange"
         v-bind="$attrs"
        >
    </el-tree>
  </div>
</template>

<script>
export default {
    name:'SearchTree',
  data() {
    return {
        inputValue:'',
        isAsyc:this.parentIsAysc,
    };
  },
  props: {
    parentIsAysc: {
      type: Boolean,
      default: true
    },
    parentNoAsycData: {
      type: Array,
      default: () => {
          return []
      }
     },
    parentTreeProps: {
      type: Object,
      default:() => {
          return {}
      }
    },
    isShow: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    parentIsAysc(val){
      // console.log(val,'***********&&&&&&&&&&&&&&&&&&&^^^^^^^^^^^^^')
      this.isAsyc = val;
      this.isAsyc ? this.inputValue = '' : ''
    },
    isShow(val){
      console.log(val,'****************!!!!!!!!!!!!!!!~~~~~~~~~~~~~~~~~')
      this.isShow ? this.inputValue = '' : ''
    }
  },
  created() {},
  methods: {
    nodeLoad(node, resolve) {
      // this.orginaGetAsycData(node, resolve)
      this.$emit('nodeLoad',node,resolve)
    },
    nodeClick(node, resolve) {
      // console.log(node,'点击当前组织 数据')
      this.$emit('nodeClick',node)
    },
    searchClick(){
      // console.log('组件内 点击到了 搜索 按钮')
      // this.$emit('orginaClickVal','')
      this.inputValue ? this.isAsyc=false : this.isAsyc=true;
      this.$emit('searchClick',this.inputValue)
    },
    checkChange(data){
      // console.log(this.$refs.searchLoadTree.getCheckedKeys(),'组件内  选择changge ')
      this.$emit('checkChange',this.$refs.searchLoadTree.getCheckedKeys())
    },
    treeBlur(){
      console.log('treeBlur')
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" >
.app-add-dialog{
  //tree 样式 start
  .el-tree-node:focus>.el-tree-node__content {
    background-color: #409eff;
    color:#fff;
  }
  //tree 样式 end

  //input 样式
  .orgina-dialog-input{
    margin-bottom: 10px;
  }
}
</style>