<template>
  <bc-tree :tree-type="treeType"  :url="url" :params="params" :treeId="treeId"  :show-icon="showIcon"
           :show-line="showLine" :height="height" :reload.sync="treeReload" :icon="icon" :selectedMulti="selectedMulti" :dblClickExpand="dblClickExpand"
           :checkEnable="checkEnable" :chkboxType="chkboxType" :sequence="sequence" :setting="setting"
           :selectedId="selectedId" :selectedType="selectedType" :reSelect.sync="treeReSelect"
           :showDep="showDep" :ztreeName="ztreeName" :ztreeNameShow="ztreeNameShow"
           @onClick="clickNode" @onCheck="checkNode" @onExpand="expandNode">
  </bc-tree>
</template>

<script>
  export default {
    name: "bc-authority-tree",
    props:{
      treeId:{ type: String, default: 'bc-tree' },
      searchId:{ type: String, default: 'keyword' },
      height:{ type: Number, default: 550 },
      reload:{ type: Boolean, default: false },//重新加载
      showLine:{ type: Boolean, default: false }, //设置 zTree 是否显示节点之间的连线。
      showIcon:{ type: Boolean, default: false }, //设置 zTree 是否显示节点的图标。
      icon:{ type: String, default: '' }, //设置 zTree 是否显示节点的图标。
      selectedMulti:{ type: Boolean, default: false }, //设置是否允许同时选中多个节点。
      dblClickExpand:{ type: Boolean, default: true }, //双击节点时，是否自动展开父节点的标识.
      checkEnable:{ type: Boolean, default: false }, //设置 zTree 的节点上是否显示 checkbox / radio
      chkboxType: Object, //勾选 checkbox 对于父子节点的关联关系。[setting.check.enable = true 且 setting.check.chkStyle = "checkbox" 时生效]
      treeType:{ type: String, default: 'common' }, //树类型，区域(area)/单位(company)/通用(common)
      sequence:{ type: Boolean, default: false },
      url:{ type: String, default: '' }, //
      params: {type:Object,default:function() {return null}},
      setting: {type:Object,default:function() {return null}},
      selectedId:{type:String,default:''},//默认选中的节点id,如果传入first,那就是默认选中第一个
      selectedType:{type:Array,default:() => {return []}},//可以选择的节点类型,是数组,允许配置多种类型 属性 type 一般是company dep person
      reSelect: { type: Boolean, default: false },//是否重新去选中默认节点
      showDep:{type: Boolean, default: false},//是否显示机构复选框
      ztreeName:{type: String, default: '组织机构树'},
      ztreeNameShow:{type: Boolean, default: false},//是否展示树文字说明
      isShowTreeModal:{type: Boolean, default: false},//是否弹出树选择框
    },
    data(){
      return{
        treeReSelect:false,
        treeReload:false,
        checkTreeNode:{},
        checkTreeExpandNode:{},
        options: {
          trigger: '.ivu-modal-header',
          body: '.ivu-modal',
          recover: true
        },
      }
    },
    methods:{
      clickNode(event, treeId, treeNode){
        this.$emit('onClick',event, treeId, treeNode);
      },
      checkNode(event, treeId, treeNode){
        this.$emit('onCheck',event, treeId, treeNode);
      },
      expandNode(event, treeId, treeNode){
        this.$emit('onExpand',event, treeId, treeNode);
      },
    },
    created() {
      let map=this.$userUtil.getCurrentObject();
      //下面的判断逻辑有隐患,应该是取bindingCompanys
      //0：业务员、1：人社局、2：组织部 3：主管单位 -1：普通单位
      if(map.userType=='-1' || map.userType=='3'){
        this.params.companyList= map.companys[0].id;
        delete this.params.areaId;
      }else {
        this.params.areaId=map.areaId?map.areaId:"0";
      }
    },
    watch:{
      reload: {
        immediate: true,
        handler: function () {
          if(this.reload){
            this.treeReload = true;
          }
        }
      },
      treeReload: {
        immediate: true,
        handler: function () {
          if(!this.treeReload){
            this.$emit('update:reload', false);
          }
        }
      },
      reSelect: {
        immediate: true,
        handler: function () {
          if(this.reSelect){
            this.treeReSelect = true;
          }
        }
      },
      treeReSelect: {
        immediate: true,
        handler: function () {
          if(!this.treeReSelect){
            this.$emit('update:reSelect', false);
          }
        }
      },
    }
  }
</script>

<style scoped>

</style>
