<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: treeHeight }">
        <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>{{ tabTitle }}</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">
            <span>{{ isOpen ? "收起" : "展开" }}</span>
            <el-icon>
              <DArrowLeft />
            </el-icon>
          </div> -->
        </div>
      </div>
      <section class="mt2" v-show="isOpen">
        <JzwTopTotal :info="pageData.info" />
      </section>
      <section class="mt2 model_box pl10 pb10 pr10 content" :style="{ height: _getTable() }">
        <JzwTable ref="JzwTableRef" :ywId="activeTab" :orgCode="orgCode" :orglevel='orglevel'
          @changeSelect="changeSelect" />
      </section>
    </section>
  </section>
</template>

<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import JzwTopTotal from "./component/JzwTopTotal.vue"
import JzwTable from "./component/JzwTable.vue"
import { getItem } from "@/utils/storage";
import { ref, reactive, computed, onMounted } from "vue";

const tabs = [
  {
    label: "建筑物基本情况台账",
    value: "17"
  },
];
const orglevel = ref('')
const lfBoxWid = ref("300px");
const rgBoxWid = ref("calc(100% - 300px)");
const orgCode = ref("")
const item = ref(null)
const treeHeight = ref(""); // 树高度
const iconChange = ref(true);
const activeTab = ref("17");
const isOpen = ref(false);
const JzwTableRef = ref()
const pageData = reactive({
  info: null
})
const tabTitle = computed(() => {
  return tabs.find(v => v.value == activeTab.value).label
})
// onMounted(()=>{
//   orgCode.value = getItem("deptId").ssdwid
// })
//设置表格高度
const _getTable = () => {
  if (isOpen.value) {
    return "calc(100vh - 545px)"
  } else {
    return "calc(100vh - 230px )"
  }
}
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 changeSelect = data => {
  if (data) {
    pageData.info = data
  }
}
const getdeptId = (val) => {
  orgCode.value = val.id;
  orglevel.value = val.orglevel;
  setTimeout(() => {
    JzwTableRef.value.getListData()
  }, 0)

};
// 树高度计算
const treeHeightFn = () => {
  treeHeight.value = window.innerHeight - 187 + "px";
};
const onToggle = () => {
  isOpen.value = !isOpen.value;
}
</script>

<style lang="scss" scoped>
.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>.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);
      }
    }
  }
}

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

  .treeBox {
    overflow: auto;
  }
}

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