
<template>
  <div class="padding-20">
    <el-tree :data="orgTree":load="loadData" lazy ref="orgTree" :props="orgTreeProps" @node-click="onTreeChange"></el-tree>
  </div>
</template>
<style lang="less">
</style>
<script>
import Three from "../../../tools/getThree.js";
export default {
  name: 'role-manage',
  components: {
  },
  data() {
    return {
      baseData: [],
      currentOrg: {},
      treeProps: {
        label: "title",
        children: "children"
      },
      formSearch: {
        enabled: "",
        roleName: "",
        orgId: ""
      },
      // 组织树
      orgTree: [],
      orgTreeProps: {
        children: 'children',
        label: 'orgName'
      },
      rootOrg: {},
    //   isButtonDisabled: true
    };
  },
  computed: {},

  created: function () {
      this.$emit("SetPageSize", 400);
      this.$emit("SetTitle", this.$t("module.valueSet.selectAffiliation"));
      this.$emit('SetPageActions', [
        {
            text: this.$t("common.confirm"),
            theme: "success",
            icon: "checkmark-round",
            handle: this.getVsOrg,
        },
        {
            text: this.$t("common.clearAll"),
            theme: "warning",
            icon: "trash-a",
            handle: this.clearAll,
        }
        ])    
  },

  mounted: function () {
  },

  methods: {
    // 加载当前组织子节点
    loadData(currentOrg, callback) {
      $store.dispatch("QueryOrg", { "orgId": currentOrg.data.orgId }).then(response => {
        if (response.statusCode == "0") {
          var childrenOrg = response.dataResult.depList;
          if (childrenOrg.length > 0) {
            //记录根节点
            if (currentOrg.level === 0) {
              this.rootOrg = childrenOrg[0];
            }
          }
          callback(childrenOrg);
        } else {
          this.$Message.error(response.msg);
        }
      });
    },
    onTreeChange() {
        let node = this.$refs["orgTree"].getCurrentNode();
        this.currentOrg = {"orgCode": node.orgCode, "orgName": node.orgName, "orgId": node.orgId };
    },
    getVsOrg(){
      if(this.currentOrg.orgCode){
        this.$emit("Close", this.currentOrg)
      }else{
        this.$Message.warning({
          content: this.$t("module.valueSet.selectAffiliation"),
          duration: 3
        });
        return ;
      }
    },
    clearAll(){
      let nothing = null;
      this.$emit("Close", nothing)
    },
    cancel() {
      this.$emit("Close")
    }
  },
  watch: {},
  directives: {}
};
</script>

