<template>
  <div id="unit" class="flex-row">
    <org-list @add-res="Addres"  @modify-res="Modifyres"
              class="basic-main" style="width:auto;" v-ref:orglist>

    </org-list>
    <div class="binary-right" style="width: 50%;" v-show="isUse">
      <div class="flex">
        <route v-ref:route></route>
      </div>
    </div>
  </div>
</template>

<script>

  import {HttpResetClass} from 'vue-client'


  export default {
    title: '组织管理',
    props: ['data'],
    data () {
      return {
        //当前资源
        isUse: false,
      }
    },
    methods: {
      //添加资源
      Addres (obj) {
        if(this.isUse){
          this.$showMessage('确定要放弃左侧正在编辑内容！！！', ['confirm', 'cancel']).then((res) => {
            if (res === 'confirm') {
              this.isUse=true
              this.$refs.route.init(
                obj.vuetype,
                {
                  data: null,
                  userid:this.$login.f.id,
                  parent:obj.parent
                }
              )
            }
          })
        }else {
          this.isUse=true
          this.$refs.route.init(
            obj.vuetype,
            {
              data: null,
              userid:this.$login.f.id,
              parent:obj.parent
            }
          )
        }
      },
      //修改
      Modifyres (obj) {
        if(this.isUse){
          this.$showMessage('确定要放弃左侧正在编辑内容！！！', ['confirm', 'cancel']).then((res) => {
            if (res === 'confirm') {
              this.isUse=true
              this.$refs.route.init(
                obj.resourcetype,
                {
                  data: obj,
                  userid:this.$login.f.id,
                  parent:null
                }
              )
            }
          })
        }else {
          this.isUse=true
          this.$refs.route.init(
            obj.resourcetype,
            {
              data: obj,
              userid:this.$login.f.id,
              parent:null
            }
          )
        }
      }
    },
    events: {
      //提交
      'success' () {
        this.isUse = false
        this.$refs.orglist.initData(true)
        this.$showAlert('操作成功', 'success', 2000)
      },
      //返回
      'cancel' () {
        this.isUse = false
        this.$refs.orglist.initData()
      },
      //刷新
      'refresh' () {
        this.isUse = false
        this.$refs.orglist.initData(true)
      },
      //点击
      'click' () {
        this.isUse = false
      }
    },
    watch: {

    },
  }

</script>
