<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" :style="{ height: 'calc(100% - 70px)' }">
        <MOSTY.DepartmentTree width="100%" placeholder="管理部门ID" clearable filterable :searchType="'03'"
          @getdeptData="getdeptId" />
      </div>
    </section>
    <section class="right" :style="{ width: rgBoxWid }">
      <div class="header">
        <div class="topper">
          <span class="base">
            <el-icon>
              <WarningFilled />
            </el-icon>
            {{ title }}
          </span>
        </div>
        <div class="bottom">
          <el-tabs v-model="activeTab" type="card">
            <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"
            v-if="!['2', '3', '4'].includes(activeTab)">
            <span>{{ isOpen ? "收起" : "展开" }}</span>
            <el-icon>
              <DArrowLeft />
            </el-icon>
          </div> -->
        </div>
      </div>
      <component :is="currentCom" :isOpen="isOpen" :id="ywId" :title="title" :orgCode="orgCode" />
    </section>
  </section>
</template>

<script setup>
import { onMounted, ref, reactive, defineAsyncComponent, markRaw } from "vue"
import * as MOSTY from "@/components/MyComponents/index"
const currentCom = ref(null)
const tabs = [
  {
    label: "事故事件",
    ywId: "43",
    value: "0"
  }
]
const activeTab = ref("0")
const isOpen = ref(false)
const title = ref(tabs.find(item => item.value === activeTab.value).label)
const ywId = ref(tabs.find(item => item.value === activeTab.value).ywId)
const iconChange = ref(true)
const lfBoxWid = ref("300px")
const rgBoxWid = ref("calc(100% - 300px)")
const orgCode = ref("")

const onToggle = () => {
  isOpen.value = !isOpen.value
}
const handleCollapse = () => {
  iconChange.value = !iconChange.value
  if (iconChange.value) {
    lfBoxWid.value = "330px"
    rgBoxWid.value = "calc(100% - 330px)"
  } else {
    lfBoxWid.value = "40px"
    rgBoxWid.value = "calc(100% - 40px)"
  }
}
const getdeptId = val => {
  orgCode.value = val.id
}
onMounted(() => {
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/tab0.vue`)))
})
</script>

<style lang="scss" scoped>
.stage-wrapper {
  display: flex;
  flex-direction: row;
}

.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;

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

    .el-icon {
      cursor: pointer;
    }
  }

  .treeBox {
    overflow: auto;
  }
}

.right {
  padding-right: 10px;
  box-sizing: border-box;
  margin-left: 14px;
  background: #fff;
  width: 83%;
}
</style>
