<!--左侧二级菜单树-->
<template>
  <div class="sub-menu-main">
    <template v-for="(item, index) in $store.state.menu.subMenuRouter">
      <template v-if="isExpend">
        <div class="smm-parent">
          <div class="p-item __hover" :class="{current: item.name === $route.name}" @click="item.children?.length > 0 ? item.expend = !item.expend : toSubMenu(item)">
            <SvgIcon class="menu-logo" name="menu-mock" size="18" color="#ffffff" rotate="90"/>
            {{item.meta.title}}
            <SvgIcon class="menu-expend" name="arrow_2" size="12" color="#ffffff" :class="{active: item.expend}" v-if="item.children?.length > 0"/>
          </div>
          <div class="smm-son" v-if="item.children?.length > 0 && item.expend">
            <template v-for="(subItem, subIndex) in item.children">
              <div class="s-item __hover" :class="{current: subItem.name === $route.name}" @click="toSubMenu(subItem)">
                {{subItem.meta.title}}
              </div>
            </template>
          </div>
        </div>
      </template>
      <template v-else>
        <template v-if="item.children?.length > 0">
          <el-popover placement="right" :teleported="false" popper-class="smm-parent-son">
            <template #reference>
              <div class="smm-parent-not-expend __hover"  :class="{current: item.name === $route.name || item.children?.some(v => v.name === $route.name)}"  @click="toSubMenu(item)">
                <SvgIcon class="menu-logo" name="menu-mock" size="18" color="#ffffff"/>
<!--                <SvgIcon class="menu-expend" name="arrow_2" size="12" color="#ffffff" :class="{active: item.expend}" v-if="item.children?.length > 0"/>-->
              </div>
            </template>
            <div class="smm-son">
              <template v-for="(subItem, subIndex) in item.children">
                <div class="s-item __hover" :class="{current: subItem.name === $route.name}" @click="toSubMenu(subItem)">
                  {{subItem.meta.title}}
                </div>
              </template>
            </div>
          </el-popover>
        </template>
        <template v-else>
          <div class="smm-parent-not-expend __hover"  :class="{current: item.name === $route.name || item.children?.some(v => v.name === $route.name)}"  @click="toSubMenu(item)">
            <SvgIcon class="menu-logo" name="menu-mock" size="18" color="#ffffff"/>
<!--            <SvgIcon class="menu-expend" name="arrow_2" size="12" color="#ffffff" :class="{active: item.expend}" v-if="item.children?.length > 0"/>-->
          </div>
        </template>
      </template>
    </template>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  computed,
  onMounted,
  ref,
  reactive,
  watch,
  getCurrentInstance,
  ComponentInternalInstance,
  toRefs,
  nextTick
} from 'vue'
import {useStore} from 'vuex'
import {useRouter, useRoute} from 'vue-router'
import {copy} from "@/utils/util";

export default defineComponent({
  name: '',
  components: {},
  props: {
    isExpend: {}
  },
  setup() {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
    const state = reactive({})
    const toSubMenu = (menu: any) => {
      const deep = (r: any) => {
        if (r.children?.length > 0) {
          deep(r.children[0])
        } else {
          if (menu.name !== route.name) {
            router.push({
              path: r.path
            })
          }
        }
      }
      deep(menu)
    }
    onMounted(() => {
    })
    return {
      ...toRefs(state),
      toSubMenu
    }
  },
})
</script>

<style scoped lang="scss">
  .current {
    background-color: #0062E9;
  }
  .sub-menu-main {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: linear-gradient(0deg, #021D78 0%, #0F44B6 100%);
    padding-top: 13px;
    .smm-parent {
      .p-item {
        display: flex;
        align-items: center;
        height: 44px;
        line-height: 1;
        user-select: none;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
        .menu-logo {
          margin: 0 13px 0 15px;
        }
        .menu-expend {
          margin: 0 12px 0 auto;
          transition: 0.2s;
          &.active {
            transform: rotate(90deg) !important;
          }
        }
      }
      .smm-son {
        .s-item {
          height: 44px;
          padding-left: 46px;
          display: flex;
          align-items: center;
          line-height: 1.2;
          user-select: none;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
    .smm-parent-not-expend {
      height: 44px;
      display: flex;
      align-items: center;
      .menu-logo {
        margin: 0 13px 0 15px;
      }
    }
    :deep(.smm-parent-son) {
      background: #0a369f;
      border: none;
      padding: 0;
      width: auto !important;
      min-width: 0;
      .el-popper__arrow::before {
        background: #0a369f;
        border-color: #0a369f;
      }
      .smm-son {
        .s-item {
          padding: 0 20px;
          height: 44px;
          display: flex;
          align-items: center;
          line-height: 1.2;
          user-select: none;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #FFFFFF;
        }
      }
    }
  }
</style>
