<template>
  <q-list>
    <div class="firstMenus">
      <div v-for="(item) in menus" :key="item.MenuId">
        <div class="firstMenusTitle">
          <i :class="`iconfont icon-${item.MenuIcon}`" style="margin-right: 5px;"></i>
          {{ item.MenuName }}
        </div>
        <div v-if="item.SubList" class="secondMenus">
          <div v-for="_item in item.SubList" :key="_item.MenuId" class="secondMenusTitle">
            <div
              class="secondMenusText"
              :class="{ 'menuActive': currentPath == _item.MenuUrl }"
              @click="changeMenu(_item.MenuUrl)"
            >{{ _item.MenuName }}</div>
          </div>
        </div>
      </div>
    </div>
  </q-list>
</template>

<script lang="ts">
import { defineComponent, inject } from 'vue'
import router from '@/router'
export default defineComponent({
  name: 'navs',
  props: {
    menus: {
      type: Array,
      required: true
    }
  },
  setup() {
    let currentPath = inject('currentPath')
    let changeMenu = (url: string) => {
      router.push({
        path: url
      })
    }
    return {
      currentPath,
      changeMenu
    }
  }
})
</script>

<style lang="scss" scoped>
.firstMenus {
  color: #fff;
  .firstMenusTitle {
    font-weight: 700;
    height: 40px;
    line-height: 40px;
    padding: 0 20px;
  }
}
.secondMenusTitle {
  height: 30px;
  line-height: 30px;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 5px;
  box-shadow: 0 30px 53px 0 rgb(0 0 0 / 12%);
  position: relative;
  color: #b2b4c7;
  display: inline-block;
  &:nth-child(odd) {
    padding-left: 40px;
    padding-right: 0;
    min-width: 120px;
  }
  &:nth-child(even) {
    padding-left: 14px;
    padding-right: 0;
    min-width: 80px;
  }
  .secondMenusText {
    cursor: pointer;
    padding: 0 4px;
    display: inline-block;
    line-height: 21px;
    border-radius: 5px;
    box-shadow: 0 30px 53px 0 rgb(0 0 0 / 12%);
    position: relative;
  }
  .menuActive {
    color: #fff;
    background-color: #3470ff;
  }
}
</style>
