<template>
  <a-card :class="[$style.treewrapD, $style.ywlxtree]" style="height: 100%">
    <slot></slot>
    <a-input-search placeholder="搜索" @change="onChange" />
    <a-tree
      :key="key"
      ref="auditMaintainCatalogTree"
      v-model="checkedKeys"
      :block-node="false"
      show-icon
      :show-line="showLine"
      :checkable="checkable"
      :check-strictly="checkStrictly"
      :draggable="draggable"
      :tree-data="treeData"
      :replace-fields="replaceFields"
      @select="treeSelect"
      @check="onCheck"
      @expand="onExpand"
    >
      <a-icon slot="folder-open" type="folder-open" />
      <a-icon slot="file-done" type="file-done" />
    </a-tree>
  </a-card>
</template>

<script>
import { Message } from 'ant-design-vue'
export default {
  name: 'AuditClassTree',
  metaInfo: {
    title: 'AuditClassTree',
  },
  props: {
    checkStrictly: {
      type: Boolean,
      default: false,
    },
    // 默认选中节点
    selectedKeys: {
      type: Array,
      default: function() {
        return []
      },
    },
    // 查看模式 manager维护权限 read查看权限
    managerType: {
      type: String,
      default: 'manager',
    },
    // 是否显示复选框
    checkable: {
      type: Boolean,
      default: false,
    },
    // 是否可以拖拽
    draggable: {
      type: Boolean,
      default: false,
    },
    // 是否显示连线
    showLine: {
      type: Boolean,
      default: false,
    },
    // 根节点名称
    topNodeText: {
      type: String,
      default: '根节点',
    },
    // 地址树接口数据源
    treeparams: {
      type: Object,
      default: () => {
        return {}
      },
    },
    // 默认展开节点id
    defaultExpandedKeys: {
      type: Array,
      default: () => {
        return ['0']
      },
    },

    // 是否显示隐藏按钮
    showPrimary: {
      type: Boolean,
      default: true,
    },
    // 地址树是否单选
    single: {
      type: Boolean,
      default: false,
    },
    refreshKey: {
      type: Number,
      default: 0,
    },
    /**
     * 是否展示部门下拉列表
     */
    isSelectDep: {
      type: Boolean,
      default: false,
    },
    cate: {
      type: Boolean,
      default: false,
    },
    isSelect: {
      type: Boolean,
      default: false,
    },
    treeData: {
      type: Array,
      default: () => {
        return []
      },
    },
    replaceFields: {
      type: Object,
      default: () => {
        return { title: 'name', key: 'id' }
      },
    },
  },
  data() {
    return {
      defaultTreeExpandedKeys: ['0'],
      defaultSelectedKeys: ['0'],
      checkedKeys: [], // 选中的节点数据
      dataList: [], // 数组dataList，搜索要用
      spinning: true,
      empty: false,
      icontype: 'left',
      fold: false,
      expandedKeys: ['0'],
      backupsExpandedKeys: [],
      autoExpandParent: false,
      defaultTopNodeText: '审计事项分类',
      defaultTopNodeId: '0',
      key: 0,
      newtree: [],
      depOptions: [], // 部门下拉框列表值
      edit: true, // 当前节点是否可编辑
      depvalue: '', // 选择的组织数据
      orgValue: '',
      orgId: null,

      searchValue: '',
    }
  },
  created() {},
  methods: {
    // 点击树
    treeSelect(selectedKeys, info) {
      this.$emit('treeSelect', selectedKeys, info)
    },
    onChange(e) {
      this.$emit('onChangeSearch', e.target.value)
    },
    onCheck(...args) {
      this.$emit('onCheck', ...args)
    },
    onExpand(e, { expanded, node }) {
      this.$emit('onExpand', {
        e,
        node,
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.spin {
  width: 100%;
  line-height: 30;
}
.ywlxtree {
  :global(.ant-tree-title) {
    display: inline-block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  :global(.ant-input-search) {
    margin: 8px 0;
    overflow: hidden;
  }
  .active {
    color: $primary-color;
  }
  :global(.ant-select) {
    width: 100%;
    overflow: hidden;
  }
}
.treewrap-d {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100% - 35px);
  margin-right: $padding-lg;
  transition: width 0.2s;
  .fold {
    position: absolute;
    top: calc(50% - 30px);
    right: -15px;
    z-index: 2;
    width: 15px;
    height: 75px;
    padding: 0;
    border-radius: 0 10px 10px 0;
  }
  :global(.ant-tree) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  :global(.ant-card-body) {
    background: $white;
  }
}
.collapse {
  width: 0;
  :global(.ant-card-body) {
    background: transparent;
    :global(.ant-empty) {
      display: none;
    }
  }
}
// 单选样式
.single {
  :global .ant-tree-checkbox {
    .ant-tree-checkbox-inner {
      border-radius: 100px;
      &::after {
        position: absolute;
        top: 3px;
        left: 3px;
        display: table;
        width: 8px;
        height: 8px;
        content: ' ';
        background-color: $primary-color;
        border: 0;
        border-radius: 8px;
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
        transform: scale(0);
      }
    }
    &.ant-tree-checkbox-checked {
      &::after {
        position: absolute;
        top: 16.67%;
        left: 0;
        width: 100%;
        height: 66.67%;
        content: '';
        border: 1px solid #1890ff;
        border-radius: 50%;
        animation: antRadioEffect 0.36s ease-in-out;
        animation-fill-mode: both;
      }
      .ant-tree-checkbox-inner {
        background-color: $white;
        &::after {
          opacity: 1;
          transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
          transform: scale(1);
        }
      }
    }
  }
}
</style>
