<template>
  <div class="m-left-block fl lwh-sider" center-sider="">
    <div class="user-block" style="width:150px;cursor:pointer" ng-click="$state.go('states.accountSetting')">
      <img style="width:140px;height:160px"
        class="user-img"
        :onerror="errorImg"
        :src="user.headImg">
      <p class="user-name" style="margin-top: 10px;margin-bottom: -8px">
        {{user.nickname}}
      </p>
    </div>

    <ul class="m-left-list">

      <li class="ng-scope" v-for="(item, index) in menu" :key="index"
          :class="{'current':isActive(item.path)}">

        <a href="javascript:void(0)" style="text-decoration: none" @click="goState(item)"
          class="ng-binding"><span class="p-ico2" :class="item.icon"></span>{{item.name}}</a>

        <div class="sub-list ng-scope" v-if="item.children">
          <a v-for="subItem in item.children" :key="subItem.path"
            @click="goSubState(subItem)" :class="{'current':isActive(subItem.path)}" href="javascript:void(0)"
            class="ng-binding ng-scope">{{subItem.name}}</a>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
  import menu from './menu.js'
  export default {
    props: {
      user: {
        type: Object,
        default: {
          nickanme: ''
        }
      }
    },
    data() {
      return {
        exportLoading: false,
        menu:menu,
        listLoading: false,
        groups: [],
        tableData: [],
        errorImg: 'this.src="' + require('../../../../assets/images/default-photo_hash88f70f5253.jpg') + '"'
      };
    },
    methods: {
      goState( item ){
        if( item.children){
          this.goSubState( item.children[0] );
        }else{
          this.goSubState( item );
        }
      },
      goSubState(item){
        if(item.path == this.$route.path) return;
        this.$router.push(item.path);
      },
      isActive( path ){
        let rpath = this.$route.path;
        return rpath.indexOf( path )> -1;
      }
    }
  }
</script>

<style>
  @import url("./index.css");
</style>
