<template>
  <section class="stage-wrapper">
    <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" :isOpen="isOpen" :id="tabValue"
        :dict="{ D_BZ_GLLX, D_BZ_YLRQLB, D_BZ_YLGDJB, D_BZ_SF, D_BZ_GYQPLX, D_BZ_DTLX_NEW, D_BZ_QZJXLB, D_BZ_CNJDCLX }" />
    </div>
  </section>
</template>

<script setup>
import { onMounted, ref, reactive, getCurrentInstance, computed, defineAsyncComponent, markRaw, provide } from "vue";
import { useRouter, useRoute } from "vue-router";
const { proxy } = getCurrentInstance();
const { D_BZ_GLLX, D_BZ_YLRQLB, D_BZ_YLGDJB, D_BZ_SF, D_BZ_GYQPLX, D_BZ_DTLX_NEW, D_BZ_QZJXLB, D_BZ_CNJDCLX } = proxy.$dict(
  "D_BZ_GLLX", "D_BZ_YLRQLB", "D_BZ_YLGDJB", "D_BZ_SF", "D_BZ_GYQPLX", "D_BZ_DTLX_NEW", "D_BZ_QZJXLB", 'D_BZ_CNJDCLX');
const route = useRoute();
const router = useRouter();
const tabs = [
  {
    label: "锅炉",
    ywId: "18",
    index: '0'
  },
  {
    label: "压力容器",
    ywId: "19",
    index: '1'
  },
  {
    label: "压力管道",
    ywId: "20",
    index: '2'
  },
  {
    label: "工业气瓶",
    ywId: "21",
    index: '3'
  },
  {
    label: "场（厂）内专用机动车辆",
    ywId: "22",
    index: '4'
  },
  {
    label: "电梯",
    ywId: "21",
    index: '5'
  },
  {
    label: "起重机械",
    ywId: "24",
    index: '6'
  },

];
const activeTab = ref(route.query.tab ? route.query.tab : "0");
const isOpen = ref(false);
const currentCom = ref(null);
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`)));
};

onMounted(() => {
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/Tab0.vue`)));
});
</script>

<style lang="scss" scoped>
.stage-wrapper .el-dialog__body {
  height: 100% !important;
}

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