<template>
  <div>
    <Row v-if="childrenBus && childrenBus.length>0" :gutter="16">
      <Col v-for="busL1 in childrenBus" :span="4" :key="busL1.busCode" >
        <Card @click.native="toBusForm(busL1)" style="cursor: pointer">
          <Row >
            <Col :span="6">
              <img src="./defalut.png" width="40" height="40"/>
            </Col>
            <Col :span="18">
              <h3 style="margin-top: 5px;">{{busL1.busName}}</h3>
            </Col>
          </Row>
        </Card>
        <commonComponent v-if="nowBusCode === busL1.busCode" openType="draftBox" :value="nowBus" :show.sync="showCommonComponent"></commonComponent>
      </Col>
    </Row>
    <Collapse v-if="childrenGroup && childrenGroup.length>0" v-model="openPanels" style="height: 1200px;">
      <Panel v-for="groupL1 in childrenGroup" :name="groupL1.code" :key="groupL1.code" >
        {{groupL1.name}}
        <template #content>
        <workbench-tree :group="groupL1"></workbench-tree>
        </template>
      </Panel>
    </Collapse>
  </div>
</template>

<script>
  import commonComponent from '../common-component.vue'

  let $this
  export default {
    name: 'workbenchTree',
    components: {
      commonComponent,
    },
    props: {
      group: Object,
    },
    data () {
      return {
        showCommonComponent: false,
        openPanels: [],//展开的列表的集合
        childrenGroup: [],//子分类
        childrenBus: [],//子业务
        nowBus: {},//当前业务
        nowBusCode: '',//当前业务编码
        commonList: [],//固化常用列表
        fieldList: [//用户可以自行选择查询的字段列表及配置

        ]
      }
    },
    methods: {
      initOpenPanels () {
        this.childrenGroup.forEach(child => {
          this.openPanels.push(child.code)
        })
      },
      toBusForm (bus) {
        this.nowBus = bus
        this.nowBus.openType = 'draftBox'
        this.nowBusCode = bus.busCode
        this.showCommonComponent = true
      },
    },
    mounted () {
      $this = this
    },
    watch: {
      group: {
        immediate: true,
        handler: function () {
          //赋值
          if (this.group) {
            this.childrenGroup = this.group.childrenGroup
            this.childrenBus = this.group.childrenBus
            if (this.childrenGroup && this.childrenGroup.length > 0) {
              this.initOpenPanels()
            }
          } else {
            this.childrenGroup = []
            this.childrenBus = []
            this.openPanels = []

          }
        }
      }
    }
  }
</script>

<style>

</style>
