<template>
  <div id="unit" class="flex-row">
    <dep-list class="basic-main"  @select-changed="selected" v-ref:todolist></dep-list>
    <div class="binary-right" style="width: 68%;" v-if="isChange">
        <div class="flex">
            <dep-compile-list :data="row" :has-child="hasChild"></dep-compile-list>
        </div>
    </div>
  </div>
</template>
<script>
  import {HttpResetClass} from 'vue-client'
  //验证是否有子
  let validatehasChildGen = async function (self, obj) {
    // 获取当前登录人所在组织下的角色，
    self.hasChild = false
    if(self.row.id&&self.row.id.length>0){
      let http = new HttpResetClass()
      let geChildrens = await http.load('POST', '/rs/search',
        {source:`tool.getChildren($${self.row.id}$)`,
          userid:self.$login.f.id},
        {resolveMsg:null, rejectMsg: '获取所在组织下的角色出错！！'})
      if (geChildrens.data.length > 0) {
        self.hasChild = true
      }
    }
  }

  export default {
    title: '部门管理',
    data () {
      return {
        row: null,
        isChange: false,
        // 是否有子
        hasChild: false
      }
    },
    methods: {
      async selected (obj) {
        delete obj.val.num
        this.row = null
        this.row = obj.val
        await validatehasChildGen(this, obj.val)
        this.isChange = true
      }
    },
    events: {
      'add' () {
        this.isChange = false
        this.row = null
        this.isChange = true
        this.hasChild = false
      },
      'search' () {
        this.isChange = false
        this.hasChild = false
      },
      'refresh' () {
        this.row = null
        this.isChange = false
        this.hasChild = false
        this.$refs.todolist.$refs.paged.$refs.cri.search()
      }
    }
  }
</script>
<style>
</style>
