<template>
  <section class="stage-wrapper">
    <section class="left" :style="{ 'width': lfBoxWid }" v-if="activeTab == '2'">
      <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" />
      </div>
    </section>
    <section class="right" :style="{ 'width': activeTab == '2' ? 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="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'" />
        </div>
        <div class="box" style="flex: 1">
          <!-- 消防设置台账 start -->
          <XfzstzTable v-if="activeTab === '1'" @onQuery="onQuery" :dict="{ D_BZ_XFZDBWHZLX, D_BZ_XFZDBWWXDJ }" />
          <!-- 消防设置台账 end -->
          <!-- <template v-else-if="activeTab === '2'">
            <XfzdbwtzTableSheng ref="JzwTableRef" v-if="isProvinces" :ywId="activeTab" :orglevel='orglevel'
              :orgCode="orgCode" />
            <XfzdbwtzTableShi ref="JzwTableRef" v-else-if="isCity" :ywId="activeTab" :orglevel='orglevel'
              :orgCode="orgCode" />
            <XfzdbwtzTableXian ref="JzwTableRef" v-else-if="IsXJZH" :ywId="activeTab" :orglevel='orglevel'
              :orgCode="orgCode" />
          </template> -->
          <!-- 消防重点部位台账 start -->
          <CcsstzTable v-else-if="activeTab === '2'" ref="JzwTableRef" :isOpen="isOpen" :id="tabValue"
            :orgCode="orgCode" :dict="{ D_BZ_XFZDBWHZLX, D_BZ_XFZDBWWXDJ }" />

          <!-- 消防重点部位台账 end -->
        </div>
      </div>
    </section>

  </section>
</template>

<script setup>
import { onMounted, ref, reactive, getCurrentInstance, computed, provide } from "vue";
import Xfzdbwtz from "./components/Xfzdbwtz.vue";
import Xfzstz from "./components/Xfzstz.vue";
// import XfzdbwtzTableSheng from "./components/XfzdbwtzTableSheng.vue";
// import XfzdbwtzTableShi from "./components/XfzdbwtzTableShi.vue";
// import XfzdbwtzTableXian from "./components/XfzdbwtzTableXian.vue";
import CcsstzTable from './components/CcsstzTable.vue'
import XfzstzTable from "./components/XfzstzTable.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { filterqx } from "@/utils/auth.js";
// import { getApi } from "@/api/tobAcco_api.js";
const { proxy } = getCurrentInstance();
const { D_BZ_XFZDBWHZLX, D_BZ_XFZDBWWXDJ } = proxy.$dict(
  "D_BZ_XFZDBWHZLX", "D_BZ_XFZDBWWXDJ");

const tabs = [
  {
    label: "消防重点部位台账",
    ywId: "26",
    value: "2"
  },
  {
    label: "消防设施台账",
    ywId: "25",
    value: "1"
  },

];
// 是否是省账号
const isProvinces = computed(() => {
  return filterqx('isaqbm') == '1' && filterqx('isSgs') == '1'
})
// 是否是市本级账号
const isCity = computed(() => {
  return filterqx('isaqbm') == '1' && filterqx('isgs') == '1'
})
//县级账号
const IsXJZH = computed(() => {
  return filterqx('isaqbm') == '1' && filterqx('isgs') != '1' && filterqx('isSgs') != '1'
})
const activeTab = ref("2");
const isOpen = ref(false);
const query = ref(null);
const orgCode = ref("")
const orglevel = ref('')
const JzwTableRef = ref()
const iconChange = ref(true);
const lfBoxWid = ref("300px");
const rgBoxWid = ref("calc(100% - 300px)");
const count = ref(1)
const tabTitle = computed(() => {
  return tabs.find((v) => v.value == activeTab.value).label;
});
const tabValue = computed(() => {
  return tabs.find((v) => v.value == activeTab.value).ywId;
});

provide("ywId", tabValue);
provide("title", tabTitle);
provide("isOpen", isOpen);
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;
  orglevel.value = val.orglevel;

};
const onToggle = () => {
  isOpen.value = !isOpen.value;
};
const onQuery = (data) => {
  query.value = data;
};
const handleTabs = ({ index }) => {
  if (index == '0') {
    count.value = 1
  }
}
// onMounted(() => {
// });
</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;

  .title {
    height: 60px;
    line-height: 60px;
    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>
