<template>
  <div class="left_info">
    <Menu ref="updata" accordion width="auto" :open-names="curRoute.activeSubmenu" :active-name="curRoute.activeMenuItem" @on-select="route" @on-open-change="change_img">
      <MenuItem name="index"><span class="menu_icon index"></span>
        首页
      </MenuItem>
      <Submenu name="user" v-show="is_MenuList('用户管理')">
        <template slot="title" >
          <span class="menu_icon user"></span>
          用户管理
        </template>
        <MenuItem name="admin_list" v-show="is_MenuList('员工列表')">员工列表</MenuItem>
        <MenuItem name="admin_role" v-show="is_MenuList('角色权限')">角色权限</MenuItem>
        <MenuItem name="admin_sale" v-show="is_MenuList('商务专员')">商务专员</MenuItem>
        <MenuItem name="admin_guild" v-show="is_MenuList('公会列表')">公会列表</MenuItem>
        <MenuItem name="team_list" v-show="is_MenuList('部门列表')">部门列表</MenuItem>
      </Submenu>
      <Submenu name="game" v-show="is_MenuList('游戏管理')">
        <template slot="title" >
          <span class="menu_icon game"></span>
          游戏管理
        </template>
        <MenuItem name="game_center" v-show="is_MenuList('游戏中心')">游戏中心</MenuItem>
        <MenuItem name="game_mine" v-show="is_MenuList('我的游戏')">我的游戏</MenuItem>
        <MenuItem name="game_promote" v-show="is_MenuList('平台游戏')">平台游戏</MenuItem>
      </Submenu>
      <Submenu name="data" v-show="is_MenuList('数据管理')">
        <template slot="title">
          <span class="menu_icon data"></span>
          数据管理
        </template>
        <MenuItem name="data_sum" v-show="is_MenuList('数据汇总')">数据汇总</MenuItem>
        <MenuItem name="data_recharge" v-show="is_MenuList('充值明细')">充值明细</MenuItem>
        <MenuItem name="data_register" v-show="is_MenuList('注册明细')">注册明细</MenuItem>
        <MenuItem name="data_summary" v-show="is_MenuList('业绩总览')">业绩总览</MenuItem>
        <MenuItem name="data_earning" v-show="is_MenuList('今日业绩')">今日业绩</MenuItem>
        <MenuItem name="data_rank" v-show="is_MenuList('业绩排行')">业绩排行</MenuItem>
      </Submenu>
      <Submenu name="finance" v-show="is_MenuList('财务管理')">
        <template slot="title">
          <span class="menu_icon finance"></span>
          财务管理
        </template>
        <MenuItem name="admin_salary" v-show="is_MenuList('薪资设置')">薪资设置</MenuItem>
        <MenuItem name="staff_pay" v-show="is_MenuList('薪资结算')">薪资结算</MenuItem>
        <MenuItem name="data_pay" v-show="is_MenuList('员工薪资')">员工薪资</MenuItem>
      </Submenu>
      <Submenu name="honor" v-show="is_MenuList('荣誉管理')">
        <template slot="title">
          <span class="menu_icon honor"></span>
          荣誉管理
        </template>
        <MenuItem name="honor_look" v-show="is_MenuList('荣誉明细')">荣誉明细</MenuItem>
        <MenuItem name="honor_set" v-show="is_MenuList('荣誉设置')">荣誉设置</MenuItem>
        <MenuItem name="honor_system" v-show="is_MenuList('荣誉体系说明')">荣誉体系说明</MenuItem>
        <MenuItem name="power_apply" v-show="is_MenuList('特权申请')">特权申请</MenuItem>
        <MenuItem name="power_audit" v-show="is_MenuList('特权审核')">特权审核</MenuItem>
        <MenuItem name="honor_welfare" v-show="is_MenuList('福利设置')">福利设置</MenuItem>
      </Submenu>
      <Submenu name="set" v-show="is_MenuList('系统管理')">
        <template slot="title">
          <span class="menu_icon set"></span>
          系统管理
        </template>
        <MenuItem name="account" v-show="is_MenuList('账户信息')">账户信息</MenuItem>
        <MenuItem name="basic" v-show="is_MenuList('基础设置')">基础设置</MenuItem>
        <!-- <MenuItem name="site_set" v-show="is_MenuList('站点设置')">站点设置</MenuItem> -->
        <MenuItem name="new_notice" v-show="is_MenuList('公告通知(设置)')">公告通知</MenuItem>
        <!-- <MenuItem name="new_notice" v-show="is_MenuList('公告通知(设置)')&&(role==1||role==0)">公告通知</MenuItem> -->
        <MenuItem name="text_set" v-show="is_MenuList('短信设置')">短信设置</MenuItem>
        <!-- <MenuItem name="data_news" v-show="is_MenuList('公告通知')&&(role!==1&&role!==0)">公告通知</MenuItem> -->
        <MenuItem name="update_system" v-show="is_MenuList('系统更新')">系统更新</MenuItem>
      </Submenu>
      <Submenu name="platform" v-show="is_MenuList('平台对接')">
        <template slot="title">
          <span class="menu_icon platform"></span>
          平台对接
        </template>
        <MenuItem name="platform_mine" v-show="is_MenuList('我的平台')">我的平台</MenuItem>
        <MenuItem name="platform_center" v-show="is_MenuList('平台中心')">平台中心</MenuItem>
      </Submenu>
      <!-- <MenuItem name="extension"><span class="menu_icon extension"></span>
        新增功能
      </MenuItem> -->
    </Menu>
  </div>
</template>
<script>
import { mapState, mapGetters } from "vuex";
import { setStore } from "@/utils/utils";
export default {
  name: "left_info",
  data() {
    return {
      is_change_img: [],
      menuList:[],
      lastRouter:''
    };
  },
  computed: {
    ...mapState({
      role: state => state.adminInfo.role_id,
    }),
    ...mapGetters(["curRoute"])
  },
  watch: {
    "curRoute.activeSubmenu"(n, o) {
      if (n) {
        this.$nextTick(() => {
          this.$refs.updata.updateOpened();
          this.is_change_img =n;
        });
      }
    }
  },
  methods: {
    route(n) {
      if(this.curRoute.activeMenuItem.toString()===n.toString()){
        this.$router.go(0);
      }else{
        this.lastRouter=n
        this.$router.push({ path: n });
        if (n.toString() === 'index' || n.toString() === 'extension') {
          this.is_change_img = [n];
        }
      }
    },
    is_MenuList(leftName){
      let j=false
      for(let i of this.menuList){
        if(i.title=='公告通知'||i.title=='公告通知(设置)'){
          j=true
        }
        if(i.title==leftName){
          return true
        }
      }
      this.$store.commit('changeisShowRightNav',j)
    },
    change_img(n) {
      this.is_change_img = n;
    },
    getUserMenu(){
      this.$api.getUserMenu().then(data =>{
        if(data.code==200){
          this.menuList=data.data
          this.is_MenuList('')
        }else{
          this.$Message.info(data.msg)
        }
      })
    },
  },
  created(){
    this.$nextTick(()=>{
      this.getUserMenu()
    })
    this.change_img(this.curRoute.activeSubmenu)
  },
  mounted(){
    
  }
};
</script>
<style>
.menu_img {
  position: relative;
  top: 0px;
  margin-right: 8px;
}
.ivu-menu-submenu .ivu-menu-item{
  padding-left: 62px!important;
  font-size: 14px;
}
#admin_pay .ivu-icon.ivu-icon-ios-arrow-down.ivu-menu-submenu-title-icon{
  display: none
}
</style>

