<template>
  <Submenu :name="`${parentName}`">
    <template slot="title">
      <!--  <Icon color="#7c3aed" size="20" :type="parentItem.icon || ''" /> -->
      <Icon v-if="parentItem.icon && parentItem.icon.indexOf('iconfont') === -1" :type="parentItem.icon || ''"
        size="20"></Icon>
      <Icon v-else :custom="parentItem.icon" size="20"></Icon>
      <span>{{ showTitle(parentItem) }}</span>
    </template>
    <template v-for="item in children">
      <template v-if="item.children && item.children.length === 1">
        <side-menu-item1 v-if="showChildren(item)" :key="`menu-${item.name}`" :parent-item="item"></side-menu-item1>
        <menu-item v-else :name="getNameOrHref(item, true)" :key="`menu-${item.children[0].name}`">
          <Icon :type="item.children[0].icon || ''" />
          <span>{{ showTitle(item.children[0]) }}</span>
        </menu-item>
      </template>
      <template v-else>
        <side-menu-item1 v-if="showChildren(item)" :key="`menu-${item.name}`" :parent-item="item"></side-menu-item1>
        <menu-item v-else :name="getNameOrHref(item)" :key="`menu-${item.name}`">
          <span>{{ showTitle(item) }}<Badge v-if="item.name === 'thirdPartyAccount' && showRedBadge" dot style="margin: 0 0 5px 25px;" /></span>
        </menu-item>
      </template>
    </template>
  </Submenu>
</template>
<script>
import mixin from './mixin'
import itemMixin from './item.mixin'
import SideMenuItem1 from './SideMenuItem1.vue'
import { mapState } from 'vuex'
export default {
  name: 'SideMenuItem',
  mixins: [mixin, itemMixin],
  components: {
    SideMenuItem1,
  },
  computed: {
    ...mapState({
      noOnlineAccount: (state) => state.wxb.noOnlineAccount //第三方账号是否登录
    })
  },
  data () {
    return {
      showRedBadge: false
    }
  },
  watch: {
    noOnlineAccount (val) {
      this.showRedBadge = val
    }
  }
}
</script>
