<template>
  <div style="text-align: center;overflow-y: auto;height: 393px;">
    <ul :id="treeName" class="ztree" />
  </div>
</template>
<script>
/**
 * 添加编辑Ztree
 */
let treeObj
export default {
  data() {
    return {
      treeName: '' // 区别tree id
    }
  },
  methods: {
    _getZtree(name) {
      this.treeName = name + 'OrginTree'
      const setting = {
        data: {
          simpleData: {
            enable: true,
            idKey: 'id',
            pIdKey: 'pid'
          }
        },
        callback: {
          onClick: this.zTreeOnClick
        }
      }
      this.$store.dispatch('SysOrg/orgTreeList').then(() => {
        $.fn.zTree.init(
          $('#' + this.treeName),
          setting,
          this.$store.state.SysOrg.list
        )
        treeObj = $.fn.zTree.getZTreeObj(this.treeName)
        treeObj.expandAll(true)
      })
    },
    zTreeOnClick(event, treeId, treeNode) {
      this.$emit('on-result-change', treeNode)
    }
  }
}
</script>
