<template>
  <section class="stage-wrapper">
    <section class="left" :style="{ 'width': lfBoxWid }">
      <!-- <section class="left" :style="{ 'width': lfBoxWid }" v-if="activeTab != '0'"> -->
      <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%" placeholder="管理部门ID" clearable filterable :searchType="'03'"
          @getdeptData="getdeptId" :key="keys" />
      </div>
    </section>
    <section class="right" :style="{ 'width': rgBoxWid }">
      <!-- <section class="right" :style="{ 'width': activeTab != '0' ? rgBoxWid : '100%' }"> -->
      <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="onTabClick">
            <el-tab-pane :label="item.label" :name="item.index" 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">
        <component :is="currentCom" :orgCode="orgCode" :title="tabTitle" :isOpen="isOpen"
          :dict="{ D_BZ_SF, D_BZ_WXZYLXNEW, D_BZ_WXZYJB, D_BZ_YXKJLB, D_BZ_XZFS, D_BZ_XSCZYZQ, D_BZ_KNZCDSGLB }" />
      </div>
    </section>
  </section>
</template>

<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import { onMounted, ref, getCurrentInstance, onUnmounted, computed, defineAsyncComponent, markRaw, provide } from "vue";
const { proxy } = getCurrentInstance();
const { D_BZ_SF, D_BZ_WXZYLXNEW, D_BZ_WXZYJB, D_BZ_YXKJLB, D_BZ_XZFS, D_BZ_XSCZYZQ, D_BZ_KNZCDSGLB } = proxy.$dict(
  "D_BZ_SF", "D_BZ_WXZYLXNEW", "D_BZ_WXZYJB", "D_BZ_YXKJLB", "D_BZ_XZFS", "D_BZ_XSCZYZQ", "D_BZ_KNZCDSGLB");
const tabs = [
  {
    label: "危险作业",
    ywId: "36",
    index: '0'
  },
  {
    label: "有限空间作业场所",
    ywId: "37",
    index: '1'
  },
  {
    label: "熏蒸杀虫作业场所",
    ywId: "38",
    index: '2'
  },
];
const iconChange = ref(true);
const lfBoxWid = ref("330px");
const rgBoxWid = ref("calc(100% - 330px)");
const activeTab = ref("0");
const isOpen = ref(false);
const currentCom = ref(null);
const orgCode = ref("")
const keys = ref(0)
const tabTitle = computed(() => {
  return tabs.find(v => v.index == activeTab.value).label
})
const tabValue = computed(() => {
  return tabs.find(v => v.index == activeTab.value).ywId
})
provide('ywId', tabValue)
const onToggle = () => {
  isOpen.value = !isOpen.value;
};
const onTabClick = (tab) => {
  isOpen.value = false;
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/Tab${tab.index}.vue`)));
  keys.value++
  // if (tab.index != '0') {
  //   keys.value++
  // }
};
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;

};
onMounted(() => {
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/Tab0.vue`)));
});
</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>
