<template>
  <div id="unit" class="flex-row">
    <box-list v-ref:list :row="row" @select-changed="selected" style="width:auto;"></box-list>
    <div class="flex" style="margin-left: 10px; width: 50%;overflow: auto" v-if="isChange">
      <add-box v-if="isChange" :data="boxmodel" :tabconfig="tabConfig" @sendindex="handleIndex" v-ref:addbox></add-box>
      <box-user-list v-if="userlist&&indexFromChild!==0" :data="boxmodel"
                     :tabconfig="handleSetActiveTab"></box-user-list>
    </div>
  </div>
</template>
<script>
import co from 'co'

export default {
  title: '调压箱管理',
  data () {
    return {
      isChange: false,
      userlist: false,
      row: null,
      boxmodel: null,
      tabConfig: null,
      indexFromChild: null
    }
  },
  methods: {
    handleIndex (index) {
      // 接收子组件传递的值
      this.indexFromChild = index
      console.log('收到index----------->', index)
    },
    selected (obj) {
      this.isChange = true
      this.userlist = true
      this.row = obj.val
      this.boxmodel = obj.val
      this.tabConfig = true
    },
    getChange () {
      this.isChange = true
    }
  },
  events: {
    'search' () {
      this.isChange = false
      this.userlist = false
      this.row = null
      this.boxmodel = {}
      this.$refs.list.$refs.paged.$refs.cri.search()
    },
    'success' (name, row, res) {
      this.isChange = false
      this.userlist = false
      this.row = null
      this.boxmodel = {}

      this.$refs.list.search()
    },
    'error' (name, row, res) {
      this.isChange = false
      this.userlist = false
      this.row = null
      this.boxmodel = {}
    },
    'close' () {
      this.isChange = false
      this.userlist = false
      this.row = null
      this.boxmodel = {}
      this.$refs.list.search()
    },
    'add' () {
      this.isChange = true
      this.userlist = false
      this.row = null
      this.boxmodel = {}
      this.$refs.list.$refs.paged.$refs.grid.selectStore.selected = null
      this.tabConfig = false
      this.tabConfigList = false
      this.$refs.addbox.cancel()
    }
  }
}
</script>
