<template>
  <div id="XTreeOnePro">
    <component-layout-one :siderProps="{width: leftWidth,collapsible: collapsible,collapsedWidth: collapsedWidth,theme: 'light'}">
      <template slot="left">
        <div class="bg-white pd-20" :style="{height: treeHeight}">
          <x-tree-pro
            :config-name="configName"
            :serviceName="serviceName"
            :env="env"
            :countVisible="countVisible"
            @action="action"
            @treeOnChecked="treeOnChecked"
            @itemChecked="itemChecked"
            ref="xtree"
          ></x-tree-pro>
        </div>
      </template>
      <div style="margin-left: 12px">
        <slot></slot>
      </div>
    </component-layout-one>
  </div>
</template>

<script>
  import ComponentLayoutOne from '@vue2-client/layouts/ComponentLayoutOne'
  import XTreePro from '@vue2-client/base-client/components/common/XTree/XTreePro'
  export default {
    name: 'XTreeOnePro',
    components: { ComponentLayoutOne, XTreePro },
    props: {
      // xTree 配置
      configName: {
        type: String,
        default: null
      },
      env: {
        type: String,
        default: 'prod'
      },
      // 配置所属命名空间
      serviceName: {
        type: String,
        default: undefined
      },
      // 左侧宽度
      leftWidth: {
        type: [Number, String],
        default: () => {
          return 200
        }
      },
      // 左侧是否可收起
      collapsible: {
        type: Boolean,
        default: true
      },
      // 左侧收起后宽度
      collapsedWidth: {
        type: Number,
        default: 0
      },
      // 是否显示子级数量
      countVisible: {
        type: Boolean,
        default: false
      },
      treeHeight: {
        type: String,
        default: '85vh'
      }
    },
    data () {
      return {
        // 用于展示筛选出的数据
        searchData: [],
        config: {},
        // 查询值
        searchValue: ''
      }
    },
    created () {
      this.init()
    },
    mounted () {
    },
    methods: {
      /**
       * 详情按钮事件
       * @param record 本条数据
       * @param id 数据标识
       * @param actionType 操作类型
       * @param fun 向上级传递的事件
       */
      action (record, id, actionType, fun = 'action') {
        this.$emit(fun, record, id, actionType)
      },
      treeOnChecked (checkedKeys, deepNodes, deepKeys) {
        this.$emit('treeOnChecked', checkedKeys, deepNodes, deepKeys)
      },
      itemChecked (node) {
        this.$emit('itemChecked', node)
      },
      init () {
      },
      onChange (e) {
        const name = e.target.value
        this.searchValue = name
        this.searchData = []
        for (const row of this.treeData) {
          if (row.title.indexOf(name) > -1) {
            this.searchData.push(row)
          }
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  .pd-20 {
    padding: 20px;
  }
  /deep/ .ant-tree-switcher-icon svg{
    width: 1.5em;
    height: 1.5em;
  }
</style>
