<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <a-row :class="['p-4', `${prefixCls}--box`]" type="flex">
    <a-col :span="12" :class="`${prefixCls}--box-left`">
      <DepartLeftTree ref="leftTree" @select="onTreeSelect" @rootTreeData="onRootTreeData" />
    </a-col>
    <a-col :span="12" :class="`${prefixCls}--box-right`">
      <a-card :bordered="false" :bodyStyle="{ padding: '20px 24px 24px 24px', height: '100%' }">
        <a-tabs v-show="departData != null" defaultActiveKey="base-info" type="card">
          <a-tab-pane tab="基本信息" key="base-info" forceRender style="position: relative">
            <DepartFormTab :data="departData" :rootTreeData="rootTreeData" @success="onSuccess" />
          </a-tab-pane>
          <a-tab-pane tab="部门权限" key="role-info">
            <DepartRuleTab :data="departData" @success="onSuccess" />
          </a-tab-pane>
        </a-tabs>
        <div v-show="departData == null" style="padding-top: 40px">
          <a-empty description="尚未选择部门" />
        </div>
      </a-card>
    </a-col>
  </a-row>
</template>

<script lang="ts" setup name="system-depart">
  import { provide, ref } from 'vue';
  import { useDesign } from '/@/hooks/web/useDesign';
  import DepartLeftTree from './components/DepartLeftTree.vue';
  import DepartFormTab from './components/DepartFormTab.vue';
  import DepartRuleTab from './components/DepartRuleTab.vue';

  const { prefixCls } = useDesign('depart-manage');
  provide('prefixCls', prefixCls);

  // 给子组件定义一个ref变量
  const leftTree = ref();

  // 当前选中的部门信息
  const departData = ref({});
  const rootTreeData = ref<any[]>([]);

  // 左侧树选择后触发
  function onTreeSelect(data) {
    departData.value = data;
  }

  // 左侧树rootTreeData触发
  function onRootTreeData(data) {
    rootTreeData.value = data;
  }

  function onSuccess() {
    leftTree.value.loadRootTreeData();
  }
</script>

<style lang="less">
  @import './index.less';
</style>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-depart-manage';

  .@{prefix-cls}--box {
    // border: 1px solid #44d3ff70 !important;
    // border-radius: 2px !important;
    // box-shadow: 0 0 20px #44b4ff33 inset;
    // background-color: @white;
    box-sizing: border-box;

    &-left {
      background-color: @white;
    }
    &-right {
      background-color: @white;
    }
  }
</style>
