<template>
  <section class="stage-wrapper">
    <section class="left" :style="{ 'width': lfBoxWid }">
      <div class="title">
        <div style="display: flex; align-items: center">
          <div style="padding-top: 5px; margin-right: 5px">
            <el-icon style="color: var(--el-color-primary) !important">
              <List />
            </el-icon>
          </div>
          <span class="zzjgxx" v-if="iconChange">组织机构信息</span>
        </div>
        <el-icon @click="handleCollapse" v-show="iconChange">
          <DArrowLeft />
        </el-icon>
        <el-icon @click="handleCollapse" v-show="!iconChange">
          <DArrowRight />
        </el-icon>
      </div>
      <div class="treeBox">
        <MOSTY.DepartmentTree width="100%" ref="reloadTree" placeholder="管理部门ID" clearable filterable :searchType="'03'"
          @getdeptData="getdeptId" />
      </div>
    </section>
    <section class="right" :style="{ rgBoxWid }">
      <div class="header">
        <div class="topper">
          <span class="base">
            <el-icon>
              <WarningFilled />
            </el-icon>{{ tabTitle }}</span>
        </div>
        <div class="bottom">
          <el-tabs v-model="activeTab" type="card" @tab-click="handleTabs">
            <el-tab-pane :label="item.label" :name="item.value" v-for="(item, i) in tabs" :key="i" />
          </el-tabs>
          <!-- <div class="toggle" :class="{ active: !isOpen }" @click="onToggle">
            <span>{{ isOpen ? "收起" : "展开" }}</span>
            <el-icon>
              <DArrowLeft />
            </el-icon>
          </div> -->
        </div>
      </div>
      <div class="content">
        <div class="box" style="flex-grow: 0" v-if="isOpen">
          <!-- <Xfzstz v-if="activeTab === '1'" :query="query" />
          <Xfzdbwtz v-else-if="activeTab === '2'" /> -->
          <!-- <Zzjsygl v-if="activeTab === '1'"/> -->
        </div>
        <div class="box" style="flex: 1">
          <!-- 机动车辆 -->
          <Tab0 v-if="activeTab === '0'" ref="JsyTableRef" :isOpen="isOpen" :id="tabValue" :orgCode="orgCode"
            :dict="{ D_BZ_SF, D_BZ_CLYT_ZH, D_BZ_CLYT_ZK, D_BZ_XB, D_BZ_JDCLSYZT, D_TB_DRIVELEVEL, D_BZ_RYLB_NEW }" />

          <!-- 专职驾驶员管理 -->
          <Tab1 v-else-if="activeTab === '1'" ref="JsyTableRef" :isOpen="isOpen" :id="tabValue" :orgCode="orgCode"
            :dict="{ D_BZ_SF, D_BZ_CLYT_ZH, D_BZ_CLYT_ZK, D_BZ_XB, D_BZ_JDCLSYZT, D_TB_DRIVELEVEL, D_BZ_RYLB_NEW }" />
        </div>
      </div>
    </section>

  </section>
</template>

<script setup>
import { ref, computed, getCurrentInstance } from "vue";
import Tab0 from "./tabs/Tab0.vue";
import Tab1 from './tabs/Tab1.vue'
import * as MOSTY from "@/components/MyComponents/index";
const { proxy } = getCurrentInstance();
const { D_BZ_SF, D_BZ_CLYT_ZH, D_BZ_CLYT_ZK, D_BZ_XB, D_BZ_JDCLSYZT, D_TB_DRIVELEVEL, D_BZ_RYLB_NEW } =
  proxy.$dict("D_BZ_SF", "D_BZ_CLYT_ZH", "D_BZ_CLYT_ZK", "D_BZ_XB", 'D_BZ_JDCLSYZT', 'D_TB_DRIVELEVEL', 'D_BZ_RYLB_NEW');
const tabs = [
  {
    label: "机动车辆",
    ywId: "34",
    index: '0'
  },
  {
    label: "专职驾驶员管理",
    ywId: "35",
    index: '1'
  },
];
const activeTab = ref("0");
const isOpen = ref(false);
const orgCode = ref("")
const JsyTableRef = ref()
const reloadTree = ref()
const iconChange = ref(true);
const lfBoxWid = ref("330px");
const rgBoxWid = ref("calc(100% - 330px)");
const count = ref(1)
const tabTitle = computed(() => {
  return tabs.find((v) => v.index == activeTab.value).label;
});
const tabValue = computed(() => {
  return tabs.find((v) => v.index == activeTab.value).ywId;
});
const handleCollapse = () => {
  iconChange.value = !iconChange.value;
  if (iconChange.value) {
    lfBoxWid.value = "330px";
    rgBoxWid.value = "calc(100% - 330px)";
  } else {
    lfBoxWid.value = "42px";
    rgBoxWid.value = "calc(100% - 42px)";
  }
};
const getdeptId = (val) => {
  orgCode.value = val.id;
  // if (count.value > 1) {
  //   setTimeout(() => {
  //     JsyTableRef.value.getPageData()
  //   }, 0)
  // }
  // count.value++
};
const onToggle = () => {
  // isOpen.value = !isOpen.value;
};
const handleTabs = () => {
  count.value = 1
  reloadTree.value.getTreeData()
}
</script>

<style lang="scss" scoped>
.left {
  width: 300px;
  overflow: auto;
  background: #ffffff;
  box-shadow: 0px 2px 10px 0px rgba(107, 107, 107, 0.1);
  border-radius: 0px 0px 0px 0px;
  opacity: 1;
  margin-right: 14px;
  padding-top: 10px;

  .title {
    font-size: 18px;
    color: #0f3916;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .treeBox {
    overflow: auto;
  }
}

.right {
  box-sizing: border-box;
  background: #fff;
  width: 83%;
}

.stage-wrapper {
  display: flex;
  flex-direction: row;
}

.stage-wrapper .header .topper {
  display: flex;
  align-items: center;

  >span {
    display: flex;
    align-items: center;
  }

  .base .el-icon {
    margin-right: 4px;
  }
}

.stage-wrapper .tip .el-icon {
  margin-top: 0;
}

.stage-wrapper .content {
  height: 100%;
  display: flex;
  flex-direction: column;

  .box {
    padding-top: 2px;
  }
}

.stage-wrapper .header .bottom .toggle .el-icon {
  margin-top: 0;
}

.stage-wrapper .header .bottom {
  display: flex;
  justify-content: space-between;
  padding-right: 10px;

  .toggle {
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;

    .el-icon {
      transform: rotate(90deg);
      transition: all 0.25s ease;
    }

    &.active {
      .el-icon {
        transform: rotate(-90deg);
      }
    }
  }
}
</style>
